Got rid of static/templates/no_search_result.html

The "Fulltext search unavailable" error page is now generated using the
static/templates/error.html template. Also added two test cases checking
that error page.
This commit is contained in:
Veloman Yunkan 2022-01-30 17:00:21 +04:00 committed by Matthieu Gautier
parent dbcbdff275
commit ae1bf39023
5 changed files with 24 additions and 23 deletions

View File

@ -447,6 +447,11 @@ std::string noSuchBookErrorMsg(const std::string& bookName)
return "No such book: " + bookName;
}
std::string noSearchResultsMsg()
{
return "The fulltext search engine is not available for this content.";
}
} // unnamed namespace
std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& request)
@ -591,12 +596,12 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
} catch(std::runtime_error& e) {
// Searcher->search will throw a runtime error if there is no valid xapian database to do the search.
// (in case of zim file not containing a index)
auto data = get_default_data();
data.set("pattern", encodeDiples(searchInfo.pattern));
auto response = ContentResponse::build(*this, RESOURCE::templates::no_search_result_html, data, "text/html; charset=utf-8");
response->set_code(MHD_HTTP_NOT_FOUND);
response->set_taskbar(searchInfo.bookName, archive.get());
return std::move(response);
return HTTPErrorHtmlResponse(*this, request, MHD_HTTP_NOT_FOUND,
"Fulltext search unavailable",
"Not Found",
m_root + "/skin/search_results.css")
+ noSearchResultsMsg()
+ TaskbarInfo(searchInfo.bookName, archive.get());
}

View File

@ -34,7 +34,6 @@ skin/fonts/Roboto.ttf
skin/block_external.js
skin/search_results.css
templates/search_result.html
templates/no_search_result.html
templates/error.html
templates/index.html
templates/suggestion.json

View File

@ -18,7 +18,7 @@ a:hover {
text-decoration: underline
}
.header {
h1 {
font-size: 120%;
}

View File

@ -1,15 +0,0 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html;charset=UTF-8" http-equiv="content-type" />
<title>Fulltext search unavailable</title>
<link type="text/css" href="{{root}}/skin/search_results.css" rel="Stylesheet" />
</head>
<body>
<div class="header">Not found</div>
<p>
There is no article with the title <b> "{{pattern}}"</b>
and the fulltext search engine is not available for this content.
</p>
</body>
</html>

View File

@ -686,6 +686,18 @@ TEST_F(ServerTest, 404WithBodyTesting)
Cannot find content entry invalid-article
</p>
)" },
{ /* url */ "/ROOT/search?content=poor&pattern=whatever",
expected_page_title=="Fulltext search unavailable" &&
expected_css_url=="/ROOT/skin/search_results.css" &&
book_name=="poor" &&
book_title=="poor" &&
expected_body==R"(
<h1>Not Found</h1>
<p>
The fulltext search engine is not available for this content.
</p>
)" },
};
for ( const auto& t : testData ) {