-
-
Notifications
You must be signed in to change notification settings - Fork 374
/
style-spec.js
161 lines (152 loc) · 4.82 KB
/
style-spec.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
"use strict";
var specStatus = [
{
status: "FPWD",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}W3C-WD",
},
{
status: "WD-NOTE",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}W3C-WD",
},
{
status: "finding",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}base.css",
},
{
status: "unofficial",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}W3C-UD",
},
{
status: "base",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}base.css",
},
{
status: "RSCND",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}W3C-RSCND",
},
{
status: "FPWD-NOTE",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}W3C-WG-NOTE.css",
},
{
status: "FAKE-TEST-TYPE",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}W3C-FAKE-TEST-TYPE",
},
{
status: "CG-FINAL",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}cg-final",
},
{
status: "CG-DRAFT",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}cg-draft",
},
{
status: "BG-FINAL",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}bg-final",
},
{
status: "BG-DRAFT",
expectedURL: "https://www.w3.org/StyleSheets/TR/{version}bg-draft",
},
];
function loadWithStatus(status, expectedURL, mode) {
return new Promise(function(resolve) {
var config = makeBasicConfig();
config.useExperimentalStyles = false;
config.specStatus = status;
config.prevVersion = "FPWD";
config.previousMaturity = "WD";
config.previousPublishDate = "2013-12-17";
var version = "2016/";
switch (mode) {
case "experimental":
config.useExperimentalStyles = true;
version = 2016 + "/";
break;
default:
if (mode) {
config.useExperimentalStyles = mode;
version = mode + "/";
}
}
var testedURL = expectedURL.replace("{version}", version);
var ops = {
config: config,
body: makeDefaultBody(),
};
makeRSDoc(ops, function(doc) {
var query = "link[href^='" + testedURL + "']";
var elem = doc.querySelector(query);
expect(elem).toBeTruthy();
expect(elem.href).toEqual(testedURL);
resolve(doc);
});
});
}
describe("W3C - Style", function() {
afterEach(function(done) {
flushIframes();
done();
});
it("should include 'fixup.js'", function(done) {
var ops = makeStandardOps();
var theTest = function(doc) {
var query = "script[src^='https://www.w3.org/scripts/TR/2016/fixup.js']";
var elem = doc.querySelector(query);
expect(elem.src).toEqual("https://www.w3.org/scripts/TR/2016/fixup.js");
};
makeRSDoc(ops, theTest, "spec/core/simple.html").then(done);
});
it("should have a meta viewport added", function(done) {
var ops = makeStandardOps();
var theTest = function(doc) {
var elem = doc.head.querySelector("meta[name=viewport]");
expect(elem).toBeTruthy();
var expectedStr = "width=device-width, initial-scale=1, shrink-to-fit=no";
expect(elem.content).toEqual(expectedStr);
};
makeRSDoc(ops, theTest, "spec/core/simple.html").then(done);
});
it("should default to base when specStatus is missing", function(done) {
loadWithStatus(
"",
"https://www.w3.org/StyleSheets/TR/{version}base.css"
).then(done);
});
it("should style according to spec status", function(done) {
// We pick random half from the list, as running the whole set is very slow
var promises = pickRandomsFromList(specStatus).map(function(test) {
return loadWithStatus(test.status, test.expectedURL, "2016");
});
Promise.all(promises).then(done);
});
it("should style according to experimental styles", function(done) {
// We pick random half from the list, as running the whole set is very slow
var promises = pickRandomsFromList(specStatus).map(function(test) {
return loadWithStatus(test.status, test.expectedURL, "experimental");
});
Promise.all(promises).then(done);
});
it("should not use 'experimental' URL when useExperimentalStyles is false", function(
done
) {
// We pick random half from the list, as running the whole set is very slow
var promises = pickRandomsFromList(specStatus).map(function(test) {
return loadWithStatus(test.status, test.expectedURL);
});
Promise.all(promises).then(done);
});
it("shouldn't include fixup.js when noToc is set", done => {
var ops = makeStandardOps();
var newProps = {
noToc: true,
};
Object.assign(ops.config, newProps);
var theTest = function(doc) {
var query = "script[src^='https://www.w3.org/scripts/TR/2016/fixup.js']";
var elem = doc.querySelector(query);
expect(elem).toBe(null);
};
makeRSDoc(ops, theTest, "spec/core/simple.html").then(done);
});
});