This repository was archived by the owner on Jun 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathoutline.test.js
More file actions
112 lines (98 loc) · 3.38 KB
/
outline.test.js
File metadata and controls
112 lines (98 loc) · 3.38 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
describe('outline', function() {
var outline;
beforeEach(function() {
var opml = '<?xml version="1.0"?>' +
'<opml version="2.0">' +
'<head>' +
'<ownerEmail>sat@softwire.com</ownerEmail>' +
'</head>' +
'<body>' +
'<outline text="Top" />' +
'<outline text="Footer - tag" _note="This is a footer note to export ~Dont export this" >' +
'<outline text="~Ignore" />' +
'<outline text="Print" />' +
'<outline text="Content" >' +
'<outline text="Something - or other" />' +
'<outline text="TV – Quarterly Reach / Share / Av Time" /></outline>' +
'</outline>' +
'<outline text="~Ignore" />' +
'</body>' +
'</opml>';
outline = new Outline(
$($.parseXML(opml)).find('body'),
'Page Title',
'pageTitle',
'/path/to',
[[
{
displayText: 'Home',
path: 'path/to/home.html',
selected: true
},
{
displayText: 'Section',
path: 'path/to/section.html',
selected: false
}
]]);
});
describe('process', function() {
var generator = {
generate: function(node, siteTitle, title, navigationObject, navLevel) {
return arguments;
}
};
var result;
beforeEach(function() {
result = outline.process('Site Title', generator);
});
it('returns a list of html pages with structured file paths', function() {
expect(result.length).toBe(4);
expect(filePathForPage(0)).toEqual('/path/to/pageTitle.html');
expect(filePathForPage(1)).toEqual('/path/to/pageTitle/top.html');
expect(filePathForPage(2)).toEqual('/path/to/pageTitle/footertag.html');
expect(filePathForPage(3)).toEqual('/path/to/pageTitle/footertag/print.html');
});
it('calls the generator with the correct title for each page', function() {
expect(titleForPage(0)).toEqual('Page Title');
expect(titleForPage(1)).toEqual('Top');
expect(titleForPage(2)).toEqual('Footer - tag');
expect(titleForPage(3)).toEqual('Print');
});
it('calls the generator with the navigation object for the page', function() {
expect(navObjectForPage(0).length).toEqual(2);
expect(navObjectForPage(3)[2][0].path).toEqual('../footertag/print.html');
});
it('sets the selected state of parent pages in the navigation object', function() {
expect(navObjectForPage(3)[0][0].selected).toEqual(true);
expect(navObjectForPage(3)[1][1].selected).toEqual(true);
expect(navObjectForPage(3)[2][0].selected).toEqual(true);
});
it('calls the generator with the navigation level of the page', function() {
expect(navLevelForPage(0)).toEqual(1);
expect(navLevelForPage(1)).toEqual(2);
expect(navLevelForPage(2)).toEqual(2);
expect(navLevelForPage(3)).toEqual(3);
});
var pageFields = {
title: 2,
navObject: 3,
navLevel: 4
};
function filePathForPage(pageNumber) {
return result[pageNumber].filePath;
}
function pageContent(pageNumber, field) {
return result[pageNumber].content[pageFields[field]];
}
function titleForPage(pageNumber) {
return pageContent(pageNumber, 'title');
}
function navObjectForPage(pageNumber) {
return pageContent(pageNumber, 'navObject');
}
function navLevelForPage(pageNumber) {
return pageContent(pageNumber, 'navLevel');
}
});
});