Skip to content

Commit

Permalink
Tests for /nojs
Browse files Browse the repository at this point in the history
Adds 2 tests for /nojs endpoint

Test 1: no_js_default - Without any filters
Test 2: no_js_eng_lang - With lang=eng as filter
  • Loading branch information
juuz0 committed Feb 25, 2023
1 parent 2baf84b commit 8c10936
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 2 deletions.
4 changes: 2 additions & 2 deletions static/templates/no_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
.book__wrapper:hover {
transform: scale(1.0);
}

.book__link__wrapper {
grid-column: 1 / 3;
grid-row: 1 / 3;
Expand All @@ -67,7 +67,7 @@
<select name="lang" id="languageFilter" class='kiwixNav__kiwixFilter filter' form="kiwixSearchForm">
<option value="" selected>{{book-filtering-all-languages}}</option>
{{#languages}}
<option value="{{lang_code}}" {{#selected}} selected {{/selected}}>{{lang_self_name}}</option>
<option value="{{lang_code}}"{{#selected}} selected {{/selected}}>{{lang_self_name}}</option>
{{/languages}}
</select>
</div>
Expand Down
178 changes: 178 additions & 0 deletions test/library_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,184 @@ TEST_F(LibraryServerTest, no_name_mapper_catalog_v2_individual_entry_access)
EXPECT_EQ(r1->status, 404);
}

#define HTML_PREAMBLE \
"<!DOCTYPE html>\n" \
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" \
" <head>\n" \
" <meta charset=\"UTF-8\" />\n" \
" <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\" />\n" \
" <link type=\"root\" href=\"\">\n" \
" <title>Welcome to Kiwix Server</title>\n" \
" <link\n" \
" type=\"text/css\"\n" \
" href=\"/skin/index.css?cacheid=f0ee124c\"\n" \
" rel=\"Stylesheet\"\n" \
" />\n" \
" <link rel=\"apple-touch-icon\" sizes=\"180x180\" href=\"/skin/favicon/apple-touch-icon.png?cacheid=f86f8df3\">\n" \
" <link rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/skin/favicon/favicon-32x32.png?cacheid=79ded625\">\n" \
" <link rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/skin/favicon/favicon-16x16.png?cacheid=a986fedc\">\n" \
" <link rel=\"manifest\" href=\"/skin/favicon/site.webmanifest?cacheid=bc396efb\">\n" \
" <link rel=\"mask-icon\" href=\"/skin/favicon/safari-pinned-tab.svg?cacheid=8d487e95\" color=\"#5bbad5\">\n" \
" <link rel=\"shortcut icon\" href=\"/skin/favicon/favicon.ico?cacheid=92663314\">\n" \
" <meta name=\"msapplication-TileColor\" content=\"#da532c\">\n" \
" <meta name=\"msapplication-config\" content=\"/skin/favicon/browserconfig.xml?cacheid=f29a7c4a\">\n" \
" <meta name=\"theme-color\" content=\"#ffffff\">\n" \
" <style>\n" \
" @font-face {\n" \
" font-family: \"poppins\";\n" \
" src: url(\"/skin/fonts/Poppins.ttf?cacheid=af705837\") format(\"truetype\");\n" \
" }\n\n" \
" @font-face {\n" \
" font-family: \"roboto\";\n" \
" src: url(\"/skin/fonts/Roboto.ttf?cacheid=84d10248\") format(\"truetype\");\n" \
" }\n\n" \
" .book__list {\n" \
" display: flex;\n" \
" flex-direction: row;\n" \
" flex-wrap: wrap;\n" \
" align-items: center;\n" \
" }\n\n" \
" .book__wrapper:hover {\n" \
" transform: scale(1.0);\n" \
" }\n\n" \
" .book__link__wrapper {\n" \
" grid-column: 1 / 3;\n" \
" grid-row: 1 / 3;\n" \
" }\n\n" \
" .book__link {\n" \
" grid-row: 2 / 3;\n" \
" }\n\n" \
" .kiwixHomeBody__results {\n" \
" flex-basis: 100%;\n" \
" }\n\n" \
" a {\n" \
" text-decoration: none;\n" \
" all: unset;\n" \
" }\n" \
" </style>\n" \
" </head>\n" \
" <body>\n" \
" <div class='kiwixNav'>\n"

#define RAY_CHARLES_BOOK_HTML \
" <div class=\"book__wrapper\">\n" \
" <div class=\"book__link__wrapper\">\n" \
" <div class=\"book__icon\" style=background-image:url(/catalog/v2/illustration/charlesray/?size=48)></div>\n" \
" <div class=\"book__header\">\n" \
" <div id=\"book__title\"><a href=\"/content/zimfile&amp;other\">Charles, Ray</a></div>\n" \
" <div class=\"book__download\"><span><a href=\"/nojs/download/zimfile&amp;other\">Download</a></span></div>\n" \
" </div>\n" \
" <a class=\"book__link\" href=\"/content/zimfile&amp;other\" data-hover=\"Preview\">\n" \
" <div class=\"book__description\" title=\"Wikipedia articles about Ray Charles\">Wikipedia articles about Ray Charles</div>\n" \
" </a>\n" \
" </div>\n" \
" <div class=\"book__languageTag\" >fra</div>\n" \
" <div class=\"book__tags\"><div class=\"book__tags--wrapper\">\n" \
" <span class=\"tag__link\" aria-label='unittest' title='unittest'>unittest</span>\n" \
" <span class=\"tag__link\" aria-label='wikipedia' title='wikipedia'>wikipedia</span>\n" \
" </div>\n" \
" </div>\n" \
" </div>\n"
#define CHARLES_RAY_BOOK_HTML \
" <div class=\"book__wrapper\">\n" \
" <div class=\"book__link__wrapper\">\n" \
" <div class=\"book__icon\" style=background-image:url(/catalog/v2/illustration/raycharles/?size=48)></div>\n" \
" <div class=\"book__header\">\n" \
" <div id=\"book__title\"><a href=\"/content/zimfile\">Ray Charles</a></div>\n" \
" <div class=\"book__download\"><span><a href=\"/nojs/download/zimfile\">Download</a></span></div>\n" \
" </div>\n" \
" <a class=\"book__link\" href=\"/content/zimfile\" data-hover=\"Preview\">\n" \
" <div class=\"book__description\" title=\"Wikipedia articles about Ray Charles\">Wikipedia articles about Ray Charles</div>\n" \
" </a>\n" \
" </div>\n" \
" <div class=\"book__languageTag\" >eng</div>\n" \
" <div class=\"book__tags\"><div class=\"book__tags--wrapper\">\n" \
" <span class=\"tag__link\" aria-label='public_tag_without_a_value' title='public_tag_without_a_value'>public_tag_without_a_value</span>\n" \
" <span class=\"tag__link\" aria-label='wikipedia' title='wikipedia'>wikipedia</span>\n" \
" </div>\n" \
" </div>\n" \
" </div>\n"
#define RAY_CHARLES_UNCTZ \
" <div class=\"book__wrapper\">\n" \
" <div class=\"book__link__wrapper\">\n" \
" <div class=\"book__icon\" style=background-image:url(/catalog/v2/illustration/raycharles_uncategorized/?size=48)></div>\n" \
" <div class=\"book__header\">\n" \
" <div id=\"book__title\"><a href=\"/content/zimfile\">Ray (uncategorized) Charles</a></div>\n" \
" <div class=\"book__download\"><span><a href=\"/nojs/download/zimfile\">Download</a></span></div>\n" \
" </div>\n" \
" <a class=\"book__link\" href=\"/content/zimfile\" data-hover=\"Preview\">\n" \
" <div class=\"book__description\" title=\"No category is assigned to this library entry.\">No category is assigned to this library entry.</div>\n" \
" </a>\n" \
" </div>\n" \
" <div class=\"book__languageTag\" >rus</div>\n" \
" <div class=\"book__tags\"><div class=\"book__tags--wrapper\">\n" \
" <span class=\"tag__link\" aria-label='public_tag_with_a_value:value_of_a_public_tag' title='public_tag_with_a_value:value_of_a_public_tag'>public_tag_with_a_value:value_of_a_public_tag</span>\n" \
" <span class=\"tag__link\" aria-label='wikipedia' title='wikipedia'>wikipedia</span>\n" \
" </div>\n" \
" </div>\n" \
" </div>\n"

#define FINAL_HTML_TEXT \
" </div>\n" \
" </div>\n" \
" <div id=\"kiwixfooter\" class=\"kiwixfooter\">Powered by&nbsp;<a href=\"https://kiwix.org\">Kiwix</a></div>\n" \
" </body>\n" \
"</html>\n"


#define FILTERS_HTML(SELECTED_ENG) \
" <div class=\"kiwixNav__filters\">\n" \
" <div class=\"kiwixNav__select\">\n" \
" <select name=\"lang\" id=\"languageFilter\" class='kiwixNav__kiwixFilter filter' form=\"kiwixSearchForm\">\n" \
" <option value=\"\" selected>All languages</option>\n" \
" <option value=\"eng\"" SELECTED_ENG ">English</option>\n" \
" <option value=\"fra\">français</option>\n" \
" <option value=\"rus\">русский</option>\n" \
" </select>\n" \
" </div>\n" \
" <div class=\"kiwixNav__select\">\n" \
" <select name=\"category\" id=\"categoryFilter\" class='kiwixNav__kiwixFilter filter' form=\"kiwixSearchForm\">\n" \
" <option value=\"\">All categories</option>\n" \
" <option value=\"jazz\" >Jazz</option>\n" \
" <option value=\"wikipedia\" >Wikipedia</option>\n" \
" </select>\n" \
" </div>\n" \
" </div>\n" \
" <form id='kiwixSearchForm' class='kiwixNav__SearchForm' action=\"/nojs\">\n" \
" <input type=\"text\" name=\"q\" placeholder=\"Search\" id=\"searchFilter\" class='kiwixSearch filter' value=\"\">\n" \
" <input type=\"submit\" class=\"kiwixButton kiwixButtonHover\" value=\"Search\"/>\n" \
" </form>\n" \
" </div>\n"

#define HOME_BODY_TEXT(X) \
" <div class=\"kiwixHomeBody\">\n" \
" <div class=\"book__list\">\n" \
" <h3 class=\"kiwixHomeBody__results\">" X " book(s)</h3>\n"

TEST_F(LibraryServerTest, no_js_default)
{
const auto r = zfs1_->GET("/ROOT%23%3F/nojs");
EXPECT_EQ(r->status, 200);
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
HTML_PREAMBLE
FILTERS_HTML("")
HOME_BODY_TEXT("3")
RAY_CHARLES_BOOK_HTML
CHARLES_RAY_BOOK_HTML
RAY_CHARLES_UNCTZ
FINAL_HTML_TEXT);
}

TEST_F(LibraryServerTest, no_js_eng_lang)
{
const auto r = zfs1_->GET("/ROOT%23%3F/nojs?lang=eng");
EXPECT_EQ(r->status, 200);
EXPECT_EQ(maskVariableOPDSFeedData(r->body),
HTML_PREAMBLE
FILTERS_HTML(" selected ")
HOME_BODY_TEXT("1")
CHARLES_RAY_BOOK_HTML
FINAL_HTML_TEXT);
}

#undef EXPECT_SEARCH_RESULTS

0 comments on commit 8c10936

Please sign in to comment.