From c091922246ae52bfb32460e9c7ccd71734c8459b Mon Sep 17 00:00:00 2001 From: Mossroy Date: Sun, 28 May 2017 11:39:44 +0200 Subject: [PATCH] Remove the concept of Title (remaining from Evopedia archive structure). As suggested in #218 --- browser-tests/nightwatch_runner.js | 12 +- tests/tests.js | 178 +++++++++++----------- www/css/app.css | 2 +- www/index.html | 18 +-- www/js/app.js | 234 ++++++++++++++--------------- www/js/lib/util.js | 22 +-- www/js/lib/zimArchive.js | 102 ++++++------- www/js/lib/zimDirEntry.js | 2 + 8 files changed, 278 insertions(+), 292 deletions(-) diff --git a/browser-tests/nightwatch_runner.js b/browser-tests/nightwatch_runner.js index f9273b369..ead9590be 100644 --- a/browser-tests/nightwatch_runner.js +++ b/browser-tests/nightwatch_runner.js @@ -16,14 +16,14 @@ module.exports = { .execute(function() { window.setRemoteArchive('https://kiwix.github.io/kiwix-html5/tests/wikipedia_en_ray_charles_2015-06.zim'); }) - .waitForElementVisible('#formTitleSearch', 20000) - .waitForElementVisible('#searchTitles', 20000) + .waitForElementVisible('#formArticleSearch', 20000) + .waitForElementVisible('#searchArticles', 20000) .setValue('#prefix', "Ray") - .click('#searchTitles') - .waitForElementVisible('#titleList', 20000) + .click('#searchArticles') + .waitForElementVisible('#articleList', 20000) .useXpath() - .waitForElementVisible("//div[@id='titleList']/a[text()='Ray Charles']", 20000) - .click("//div[@id='titleList']/a[text()='Ray Charles']") + .waitForElementVisible("//div[@id='articleList']/a[text()='Ray Charles']", 20000) + .click("//div[@id='articleList']/a[text()='Ray Charles']") .useCss() .frame('articleContent') .waitForElementPresent('#mweQ', 2000000) diff --git a/tests/tests.js b/tests/tests.js index 603651662..2c388c5f0 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -110,10 +110,10 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], assert.equal(util.ucEveryFirstLetter(testString3), "Le Couvre-Chef Est Sur Le Porte-Manteaux", "The first letter of every word should be upper-case"); assert.equal(util.ucFirstLetter(testString4), "Épée", "The first letter should be upper-case (with accent)"); }); - QUnit.test("check remove duplicates of an array of title objects", function(assert) { + QUnit.test("check remove duplicates of an array of dirEntry objects", function(assert) { var array = [{title:"a"}, {title:"b"}, {title:"c"}, {title:"a"}, {title:"c"}, {title:"d"}]; var expectedArray = [{title:"a"}, {title:"b"}, {title:"c"}, {title:"d"}]; - assert.deepEqual(util.removeDuplicateTitlesInArray(array), expectedArray, "Duplicates should be removed from the array"); + assert.deepEqual(util.removeDuplicateTitlesInDirEntryArray(array), expectedArray, "Duplicates should be removed from the array"); }); QUnit.module("ZIM initialisation"); @@ -121,13 +121,13 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], assert.ok(localZimArchive.isReady() === true, "ZIM archive should be set as ready"); }); - QUnit.module("zim_title_search_and_read"); + QUnit.module("zim_direntry_search_and_read"); QUnit.test("check DirEntry.fromStringId 'A Fool for You'", function(assert) { var done = assert.async(); var aFoolForYouDirEntry = zimDirEntry.DirEntry.fromStringId(localZimArchive._file, "5856|7|A|0|2|A_Fool_for_You.html|A Fool for You|false|undefined"); assert.expect(2); - var callbackFunction = function(title, htmlArticle) { + var callbackFunction = function(dirEntry, htmlArticle) { assert.ok(htmlArticle && htmlArticle.length > 0, "Article not empty"); // Remove new lines htmlArticle = htmlArticle.replace(/[\r\n]/g, " "); @@ -136,51 +136,51 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], }; localZimArchive.readArticle(aFoolForYouDirEntry, callbackFunction); }); - QUnit.test("check findTitlesWithPrefix 'A'", function(assert) { + QUnit.test("check findDirEntriesWithPrefix 'A'", function(assert) { var done = assert.async(); assert.expect(2); - var callbackFunction = function(titleList) { - assert.ok(titleList && titleList.length === 5, "Article list with 5 results"); - var firstTitle = titleList[0]; - assert.equal(firstTitle.title , 'A Fool for You', 'First result should be "A Fool for You"'); + var callbackFunction = function(dirEntryList) { + assert.ok(dirEntryList && dirEntryList.length === 5, "Article list with 5 results"); + var firstDirEntry = dirEntryList[0]; + assert.equal(firstDirEntry.title , 'A Fool for You', 'First result should be "A Fool for You"'); done(); }; - localZimArchive.findTitlesWithPrefix('A', 5, callbackFunction); + localZimArchive.findDirEntriesWithPrefix('A', 5, callbackFunction); }); - QUnit.test("check findTitlesWithPrefix 'a'", function(assert) { + QUnit.test("check findDirEntriesWithPrefix 'a'", function(assert) { var done = assert.async(); assert.expect(2); - var callbackFunction = function(titleList) { - assert.ok(titleList && titleList.length === 5, "Article list with 5 results"); - var firstTitle = titleList[0]; - assert.equal(firstTitle.title , 'A Fool for You', 'First result should be "A Fool for You"'); + var callbackFunction = function(dirEntryList) { + assert.ok(dirEntryList && dirEntryList.length === 5, "Article list with 5 results"); + var firstDirEntry = dirEntryList[0]; + assert.equal(firstDirEntry.title , 'A Fool for You', 'First result should be "A Fool for You"'); done(); }; - localZimArchive.findTitlesWithPrefix('a', 5, callbackFunction); + localZimArchive.findDirEntriesWithPrefix('a', 5, callbackFunction); }); - QUnit.test("check findTitlesWithPrefix 'blues brothers'", function(assert) { + QUnit.test("check findDirEntriesWithPrefix 'blues brothers'", function(assert) { var done = assert.async(); assert.expect(2); - var callbackFunction = function(titleList) { - assert.ok(titleList && titleList.length === 3, "Article list with 3 result"); - var firstTitle = titleList[0]; - assert.equal(firstTitle.title , 'Blues Brothers (film)', 'First result should be "Blues Brothers (film)"'); + var callbackFunction = function(dirEntryList) { + assert.ok(dirEntryList && dirEntryList.length === 3, "Article list with 3 result"); + var firstDirEntry = dirEntryList[0]; + assert.equal(firstDirEntry.title , 'Blues Brothers (film)', 'First result should be "Blues Brothers (film)"'); done(); }; - localZimArchive.findTitlesWithPrefix('blues brothers', 5, callbackFunction); + localZimArchive.findDirEntriesWithPrefix('blues brothers', 5, callbackFunction); }); QUnit.test("article '(The Night Time Is) The Right Time' correctly redirects to 'Night Time Is the Right Time'", function(assert) { var done = assert.async(); assert.expect(6); - localZimArchive.getTitleByName("A/(The_Night_Time_Is)_The_Right_Time.html").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.ok(title.isRedirect(), "Title is a redirect."); - assert.equal(title.name(), "(The Night Time Is) The Right Time", "Correct redirect title name."); - localZimArchive.resolveRedirect(title, function(title) { - assert.ok(title !== null, "Title found"); - assert.ok(!title.isRedirect(), "Title is not a redirect."); - assert.equal(title.name(), "Night Time Is the Right Time", "Correct redirected title name."); + localZimArchive.getDirEntryByTitleName("A/(The_Night_Time_Is)_The_Right_Time.html").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.ok(dirEntry.isRedirect(), "DirEntry is a redirect."); + assert.equal(dirEntry.name(), "(The Night Time Is) The Right Time", "Correct redirect title name."); + localZimArchive.resolveRedirect(dirEntry, function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + assert.ok(!dirEntry.isRedirect(), "DirEntry is not a redirect."); + assert.equal(dirEntry.name(), "Night Time Is the Right Time", "Correct redirected title name."); done(); }); } else { @@ -191,15 +191,15 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("article 'Raelettes' correctly redirects to 'The Raelettes'", function(assert) { var done = assert.async(); assert.expect(6); - localZimArchive.getTitleByName("A/Raelettes.html").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.ok(title.isRedirect(), "Title is a redirect."); - assert.equal(title.name(), "Raelettes", "Correct redirect title name."); - localZimArchive.resolveRedirect(title, function(title) { - assert.ok(title !== null, "Title found"); - assert.ok(!title.isRedirect(), "Title is not a redirect."); - assert.equal(title.name(), "The Raelettes", "Correct redirected title name."); + localZimArchive.getDirEntryByTitleName("A/Raelettes.html").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.ok(dirEntry.isRedirect(), "DirEntry is a redirect."); + assert.equal(dirEntry.name(), "Raelettes", "Correct redirect title name."); + localZimArchive.resolveRedirect(dirEntry, function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + assert.ok(!dirEntry.isRedirect(), "DirEntry is not a redirect."); + assert.equal(dirEntry.name(), "The Raelettes", "Correct redirected title name."); done(); }); } else { @@ -210,15 +210,15 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("article 'Bein Green' correctly redirects to 'Bein' Green", function(assert) { var done = assert.async(); assert.expect(6); - localZimArchive.getTitleByName("A/Bein_Green.html").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.ok(title.isRedirect(), "Title is a redirect."); - assert.equal(title.name(), "Bein Green", "Correct redirect title name."); - localZimArchive.resolveRedirect(title, function(title) { - assert.ok(title !== null, "Title found"); - assert.ok(!title.isRedirect(), "Title is not a redirect."); - assert.equal(title.name(), "Bein' Green", "Correct redirected title name."); + localZimArchive.getDirEntryByTitleName("A/Bein_Green.html").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.ok(dirEntry.isRedirect(), "DirEntry is a redirect."); + assert.equal(dirEntry.name(), "Bein Green", "Correct redirect title name."); + localZimArchive.resolveRedirect(dirEntry, function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + assert.ok(!dirEntry.isRedirect(), "DirEntry is not a redirect."); + assert.equal(dirEntry.name(), "Bein' Green", "Correct redirected title name."); done(); }); } else { @@ -229,15 +229,15 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("article 'America, the Beautiful' correctly redirects to 'America the Beautiful'", function(assert) { var done = assert.async(); assert.expect(6); - localZimArchive.getTitleByName("A/America,_the_Beautiful.html").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.ok(title.isRedirect(), "Title is a redirect."); - assert.equal(title.name(), "America, the Beautiful", "Correct redirect title name."); - localZimArchive.resolveRedirect(title, function(title) { - assert.ok(title !== null, "Title found"); - assert.ok(!title.isRedirect(), "Title is not a redirect."); - assert.equal(title.name(), "America the Beautiful", "Correct redirected title name."); + localZimArchive.getDirEntryByTitleName("A/America,_the_Beautiful.html").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.ok(dirEntry.isRedirect(), "DirEntry is a redirect."); + assert.equal(dirEntry.name(), "America, the Beautiful", "Correct redirect title name."); + localZimArchive.resolveRedirect(dirEntry, function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + assert.ok(!dirEntry.isRedirect(), "DirEntry is not a redirect."); + assert.equal(dirEntry.name(), "America the Beautiful", "Correct redirected title name."); done(); }); } else { @@ -248,11 +248,11 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("Image 'm/RayCharles_AManAndHisSoul.jpg' can be loaded", function(assert) { var done = assert.async(); assert.expect(4); - localZimArchive.getTitleByName("I/m/RayCharles_AManAndHisSoul.jpg").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.equal(title.namespace +"/"+ title.url, "I/m/RayCharles_AManAndHisSoul.jpg", "URL is correct."); - localZimArchive.readBinaryFile(title, function(title, data) { + localZimArchive.getDirEntryByTitleName("I/m/RayCharles_AManAndHisSoul.jpg").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.equal(dirEntry.namespace +"/"+ dirEntry.url, "I/m/RayCharles_AManAndHisSoul.jpg", "URL is correct."); + localZimArchive.readBinaryFile(dirEntry, function(title, data) { assert.equal(data.length, 4951, "Data length is correct."); var beginning = new Uint8Array([255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1]); @@ -268,11 +268,11 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], var done = assert.async(); assert.expect(4); - localZimArchive.getTitleByName("-/s/style.css").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.equal(title.namespace +"/"+ title.url, "-/s/style.css", "URL is correct."); - localZimArchive.readBinaryFile(title, function(title, data) { + localZimArchive.getDirEntryByTitleName("-/s/style.css").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.equal(dirEntry.namespace +"/"+ dirEntry.url, "-/s/style.css", "URL is correct."); + localZimArchive.readBinaryFile(dirEntry, function(dirEntry, data) { assert.equal(data.length, 104495, "Data length is correct."); data = utf8.parse(data); var beginning = "\n/* start http://en.wikipedia.org/w/load.php?debug=false&lang=en&modules=site&only=styles&skin=vector"; @@ -287,11 +287,11 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("Javascript '-/j/local.js' can be loaded", function(assert) { var done = assert.async(); assert.expect(4); - localZimArchive.getTitleByName("-/j/local.js").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.equal(title.namespace +"/"+ title.url, "-/j/local.js", "URL is correct."); - localZimArchive.readBinaryFile(title, function(title, data) { + localZimArchive.getDirEntryByTitleName("-/j/local.js").then(function(dirEntry) { + assert.ok(dirEntry !== null, "DirEntry found"); + if (dirEntry !== null) { + assert.equal(dirEntry.namespace +"/"+ dirEntry.url, "-/j/local.js", "URL is correct."); + localZimArchive.readBinaryFile(dirEntry, function(dirEntry, data) { assert.equal(data.length, 41, "Data length is correct."); data = utf8.parse(data); var beginning = "console.log( \"mw.loader"; @@ -307,11 +307,11 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], QUnit.test("Split article 'A/Ray_Charles.html' can be loaded", function(assert) { var done = assert.async(); assert.expect(6); - localZimArchive.getTitleByName("A/Ray_Charles.html").then(function(title) { - assert.ok(title !== null, "Title found"); - if (title !== null) { - assert.equal(title.namespace +"/"+ title.url, "A/Ray_Charles.html", "URL is correct."); - localZimArchive.readArticle(title, function(titleName, data) { + localZimArchive.getDirEntryByTitleName("A/Ray_Charles.html").then(function(dirEntry) { + assert.ok(dirEntry !== null, "Title found"); + if (dirEntry !== null) { + assert.equal(dirEntry.namespace +"/"+ dirEntry.url, "A/Ray_Charles.html", "URL is correct."); + localZimArchive.readArticle(dirEntry, function(titleName, data) { assert.equal(titleName, "Ray Charles", "Title is correct."); assert.equal(data.length, 157186, "Data length is correct."); assert.equal(data.indexOf("the only true genius in show business"), 5535, "Specific substring at beginning found."); @@ -324,28 +324,28 @@ define(['jquery', 'zimArchive', 'zimDirEntry', 'util', 'utf8'], }); }); - QUnit.module("zim_random_and_main_title"); - QUnit.test("check that a random title is found", function(assert) { + QUnit.module("zim_random_and_main_article"); + QUnit.test("check that a random article is found", function(assert) { var done = assert.async(); assert.expect(2); - var callbackRandomTitleFound = function(title) { - assert.ok(title !== null, "One title should be found"); - assert.ok(title.name() !== null, "The random title should have a name" ); + var callbackRandomArticleFound = function(dirEntry) { + assert.ok(dirEntry !== null, "One DirEntry should be found"); + assert.ok(dirEntry.name() !== null, "The random DirEntry should have a name" ); done(); }; - localZimArchive.getRandomTitle(callbackRandomTitleFound); + localZimArchive.getRandomDirEntry(callbackRandomArticleFound); }); - QUnit.test("check that the main title is found", function(assert) { + QUnit.test("check that the main article is found", function(assert) { var done = assert.async(); assert.expect(2); - var callbackMainPageTitleFound = function(title) { - assert.ok(title !== null, "Main title should be found"); - assert.equal(title.name(), "Summary", "The main title should be called Summary" ); + var callbackMainPageArticleFound = function(dirEntry) { + assert.ok(dirEntry !== null, "Main DirEntry should be found"); + assert.equal(dirEntry.name(), "Summary", "The main DirEntry should be called Summary" ); done(); }; - localZimArchive.getMainPageTitle(callbackMainPageTitleFound); + localZimArchive.getMainPageDirEntry(callbackMainPageArticleFound); }); }; }); diff --git a/www/css/app.css b/www/css/app.css index d4e14efd4..28ed033bc 100644 --- a/www/css/app.css +++ b/www/css/app.css @@ -59,7 +59,7 @@ padding-left: 1px !important; } -#searchingForTitles .floating { +#searchingForArticles .floating { position: relative; z-index: 10; top: 20px; diff --git a/www/index.html b/www/index.html index 144e36ec0..5387e2341 100644 --- a/www/index.html +++ b/www/index.html @@ -66,13 +66,13 @@
-
+
- + @@ -82,7 +82,7 @@
-
-
- - - -
+
+ +