forked from dteviot/WebToEpub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtestMuggleNetParser.js
71 lines (59 loc) · 2.56 KB
/
UtestMuggleNetParser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"use strict";
module("MuggleNetParser");
function loadMuggleNetMultiPageDoc() {
return util.syncLoadSampleDoc(
"../testdata/MuggleNet.html",
"http://fanfiction.mugglenet.com/viewstory.php?sid=123456&chapter=2"
);
}
function loadMuggleNetSinglePageDoc() {
return util.syncLoadSampleDoc(
"../testdata/MuggleNetSinglePage.html",
"http://fanfiction.mugglenet.com/viewstory.php?sid=123457&chapter=1"
);
}
QUnit.test("getChapterUrls", function (assert) {
let done = assert.async();
let parser = new MuggleNetParser();
parser.getChapterUrls(loadMuggleNetMultiPageDoc()).then(function (chapterUrls) {
assert.equal(chapterUrls.length, 5);
assert.equal(chapterUrls[0].sourceUrl, "http://fanfiction.mugglenet.com/viewstory.php?sid=123456&chapter=1");
assert.equal(chapterUrls[1].sourceUrl, "http://fanfiction.mugglenet.com/viewstory.php?sid=123456&chapter=2");
assert.equal(chapterUrls[4].title, "5. Using Chrome's \"Inspect Element\" to examine the DOM");
done();
});
});
QUnit.test("findMultiPageContent", function (assert) {
let parser = new MuggleNetParser();
let content = parser.findContent(loadMuggleNetMultiPageDoc());
let regex = /^If you're like me, you will have*/;
assert.ok(regex.test(content.innerText));
});
QUnit.test("getEpubMetaInfo", function (assert) {
let parser = new MuggleNetParser();
let metaInfo = parser.getEpubMetaInfo(loadMuggleNetMultiPageDoc());
equal(metaInfo.title, "Web to Epub");
equal(metaInfo.author, "David & Teviotdale");
equal(metaInfo.language, "en");
equal(metaInfo.fileName, "Web_to_Epub");
});
QUnit.test("parserFactory", function (assert) {
let parser = parserFactory.fetch("http://fanfiction.mugglenet.com/viewstory.php?sid=123457&chapter=1");
assert.ok(parser instanceof MuggleNetParser);
});
QUnit.test("getSingleChapterUrls", function (assert) {
let done = assert.async();
let parser = new MuggleNetParser();
parser.getChapterUrls(loadMuggleNetSinglePageDoc()).then(function (chapterUrls) {
assert.equal(chapterUrls.length, 1);
assert.equal(chapterUrls[0].sourceUrl, "http://fanfiction.mugglenet.com/viewstory.php?sid=123457&chapter=1");
assert.equal(chapterUrls[0].title, "Web to Epub");
done();
});
});
QUnit.test("findSinglePageContent", function (assert) {
let parser = new MuggleNetParser();
let content = parser.findContent(loadMuggleNetSinglePageDoc());
let regex = /^If you're like me, you will have*/;
assert.ok(regex.test(content.innerText));
});