In https://tex.stackexchange.com/a/52747/232319 they describe how to include numbered chapters (with number and title) in LOF only if the chapters contain at least one figure.
The key idea is to patch the \chapter command with etoolbox.
The equivalent was more recently described in https://tex.stackexchange.com/a/255684/232319 with xpatch.
Numerous issues concern this task in tex.stackexchange.com.
However, how to include unnumbered chapter (\chapter* commands)?
i.e. How to complete the following etoolbox patch commands to add a content line to LOF when the chapter is not numbered?
\documentclass{book}
\usepackage{etoolbox} % or xpatch
\makeatletter
% initial definitions of the chapter info (name and number)
\def\thischaptertitle{}\def\thischapternumber{}
\newtoggle{noFigs}
\apptocmd{@chapter}%
{\gdef\thischaptertitle{#1}\gdef\thischapternumber{\thechapter}%
\global\toggletrue{noFigs}}{}{}
% the figure environment does the job: the first time it is used after a \chapter command,
% it writes the information of the chapter to the LoF
\AtBeginDocument{%
\AtBeginEnvironment{figure}{%
\iftoggle{noFigs}{
\addtocontents{lof}{\protect\contentsline {chapter}%
{\protect\numberline {\thischapternumber} {\thischaptertitle}}{}{} }
\global\togglefalse{noFigs}
}{}
}%
}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\mainmatter
\chapter{Introduction with no Figures}
\chapter{Test Chapter with Figures}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\chapter{Test Chapter with no Figures}
\chapter{Another Test Chapter with Figures}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\begin{figure}
\caption{caption text}
\end{figure}
\chapter*{Test Unnumbered Chapter with Figures}
\addcontentsline{toc}{chapter}{Test Unnumbered Chapter with Figures}
\begin{figure}
\caption{Unnumbered chapter fig1}
\end{figure}
\begin{figure}
\caption{Unnumbered chapter fig2}
\end{figure}
\end{document}
Note that (as expected), the last numbered chapter contains the figure of the next unnumbered chapter in the LOF while it is not the case in the body. You can even test with a last numbered chapter with no figure, it will still have the figure in LOF of the next unnumbered chapter.