Fix tests: Use promise and actually check the image.

This commit is contained in:
peter-x 2016-01-05 18:59:54 +01:00
parent 72e4da5e02
commit f16b44f1d3

View File

@ -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,22 +517,20 @@ 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.");
equal(title.url, "m/RayCharles_AManAndHisSoul.jpg", "URL is correct.");
localZimArchive.readBinaryFile(title, function(title, data) {
ok(data.length === 58666, "Data length is correct.");
ok(data[361] === 121, "Data is correct at some point.");
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();
});
});
});
});
};
});