From f16b44f1d39b69b070b9bf63a76f598b4157c975 Mon Sep 17 00:00:00 2001 From: peter-x Date: Tue, 5 Jan 2016 18:59:54 +0100 Subject: [PATCH] Fix tests: Use promise and actually check the image. --- tests/tests.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/tests/tests.js b/tests/tests.js index 5c582348..dbfa2d90 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -172,7 +172,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom equal(title._name, "Diego_Velázquez", "Name of the title is correct"); start(); }; - localEvopediaArchive.getTitleByName("Diego_Velázquez", callbackFunction); + localEvopediaArchive.getTitleByName("Diego_Velázquez").then(callbackFunction); }); asyncTest("check getTitleByName with quote : Hundred Years' War", function() { expect(2); @@ -181,7 +181,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom equal(title._name, "Hundred_Years'_War", "Name of the title is correct"); start(); }; - localEvopediaArchive.getTitleByName("Hundred_Years'_War", callbackFunction); + localEvopediaArchive.getTitleByName("Hundred_Years'_War").then(callbackFunction); }); test("check parseTitleFromId", function() { @@ -219,7 +219,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom equal(title._name, "AIDS", "Name of the title is correct"); localEvopediaArchive.readArticle(title, callbackArticleRead); }; - localEvopediaArchive.getTitleByName("AIDS", callbackTitleFound); + localEvopediaArchive.getTitleByName("AIDS").then(callbackTitleFound); }); asyncTest("check getTitleByName with a title name that does not exist in the archive", function() { @@ -228,7 +228,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom ok(title === null, "No title found because it does not exist in the archive"); start(); }; - localEvopediaArchive.getTitleByName("abcdef", callbackTitleFound); + localEvopediaArchive.getTitleByName("abcdef").then(callbackTitleFound); }); asyncTest("check loading a math image", function() { @@ -505,7 +505,7 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom }); asyncTest("article '(The Night Time Is) The Right Time' correctly redirects to 'Night Time Is the Right Time'", function() { expect(6); - localZimArchive.getTitleByName("(The_Night_Time_Is)_The_Right_Time.html", function(title) { + localZimArchive.getTitleByName("(The_Night_Time_Is)_The_Right_Time.html").then(function(title) { ok(title !== null, "Title found"); ok(title.isRedirect(), "Title is a redirect."); equal(title.name(), "(The Night Time Is) The Right Time", "Correct redirect title name."); @@ -517,20 +517,18 @@ define(['jquery', 'title', 'archive', 'zimArchive', 'zimDirEntry', 'util', 'geom }); }); }); - asyncTest("Image 'I/m/RayCharles_AManAndHisSoul.jpg' can be loaded", function() { - expect(6); - localZimArchive.getTitleByName("(The_Night_Time_Is)_The_Right_Time.html", function(title) { + asyncTest("Image 'm/RayCharles_AManAndHisSoul.jpg' can be loaded", function() { + expect(4); + localZimArchive.getTitleByName("m/RayCharles_AManAndHisSoul.jpg").then(function(title) { console.log(title); ok(title !== null, "Title found"); - ok(title.isRedirect(), "Title is a redirect."); - localZimArchive.resolveRedirect(title, function(title) { - ok(title !== null, "Title found"); - ok(!title.isRedirect(), "Title is not a redirect."); - localZimArchive.readBinaryFile(title, function(title, data) { - ok(data.length === 58666, "Data length is correct."); - ok(data[361] === 121, "Data is correct at some point."); - start(); - }); + equal(title.url, "m/RayCharles_AManAndHisSoul.jpg", "URL is correct."); + localZimArchive.readBinaryFile(title, function(title, data) { + 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]); + equal(data.slice(0, beginning.length).toSource(), beginning.toSource(), "Data beginning is correct."); + start(); }); }); });