-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathgithub-spec.js
More file actions
279 lines (271 loc) · 10.3 KB
/
github-spec.js
File metadata and controls
279 lines (271 loc) · 10.3 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
"use strict";
import {
flushIframes,
makeBasicConfig,
makeDefaultBody,
makeRSDoc,
} from "../SpecHelper.js";
describe("Core - Github", () => {
afterAll(flushIframes);
const stringOpt = {
config: Object.assign(makeBasicConfig(), {
github: "https://github.com/speced/respec/",
excludeGithubLinks: false,
}),
body: makeDefaultBody(),
};
const objOpt = {
config: Object.assign(makeBasicConfig(), {
github: {
repoURL: "https://github.com/speced/respec/",
branch: "develop",
},
excludeGithubLinks: false,
}),
body: makeDefaultBody(),
};
// these are set by makeBasicConfig(), but we are going to override them
delete stringOpt.config.edDraftURI;
delete stringOpt.config.shortName;
delete objOpt.config.edDraftURI;
delete objOpt.config.shortName;
describe("respecConfig options", () => {
function generateMembersTest(doc) {
const { respecConfig: conf } = doc.defaultView;
expect(conf.hasOwnProperty("githubAPI")).toBe(true);
expect(conf.githubAPI).toBe("https://respec.org/github");
expect(conf.hasOwnProperty("issueBase")).toBe(true);
expect(conf.issueBase).toBe("https://github.com/speced/respec/issues/");
expect(conf.hasOwnProperty("edDraftURI")).toBe(true);
expect(conf.edDraftURI).toBe("https://speced.github.io/respec/");
expect(conf.hasOwnProperty("shortName")).toBe(true);
expect(conf.shortName).toBe("respec");
}
function doesntOverrideTest(doc) {
const { respecConfig: conf } = doc.defaultView;
expect(conf.issueBase).toBe("https://test.com/issueBase");
expect(conf.edDraftURI).toBe("https://test.com/edDraftURI");
expect(conf.shortName).toBe("dontOverrideThis");
}
it("generates githubAPI, issueBase, edDraftURI, shortName members from string", async () => {
const doc = await makeRSDoc(stringOpt);
generateMembersTest(doc);
});
it("generates githubAPI, issueBase, edDraftURI, shortName members from object", async () => {
const doc = await makeRSDoc(objOpt);
generateMembersTest(doc);
});
const dontOverrideTheseOps = {
githubAPI: "https://test.com/githubAPI",
issueBase: "https://test.com/issueBase",
edDraftURI: "https://test.com/edDraftURI",
shortName: "dontOverrideThis",
};
it("doesn't override issueBase, edDraftURI, shortName members if present (from string)", async () => {
const opts = {
config: Object.assign(makeBasicConfig(), dontOverrideTheseOps, {
github: "https://github.com/speced/respec/",
}),
};
const doc = await makeRSDoc(opts);
doesntOverrideTest(doc);
});
it("doesn't override issueBase, edDraftURI, shortName members if present (from object)", async () => {
const opts = {
config: Object.assign(makeBasicConfig(), dontOverrideTheseOps, {
github: { repoURL: "https://github.com/speced/respec/" },
}),
};
const doc = await makeRSDoc(opts);
doesntOverrideTest(doc);
});
it("does not generate edDraftURI when explicitly set to null", async () => {
const opts = {
config: Object.assign(makeBasicConfig(), {
github: "speced/respec",
edDraftURI: null,
}),
body: makeDefaultBody(),
};
const doc = await makeRSDoc(opts);
const { respecConfig: conf } = doc.defaultView;
expect(conf.edDraftURI).toBeNull();
});
it("does not generate edDraftURI when explicitly set to empty string", async () => {
const opts = {
config: Object.assign(makeBasicConfig(), {
github: "speced/respec",
edDraftURI: "",
}),
body: makeDefaultBody(),
};
const doc = await makeRSDoc(opts);
const { respecConfig: conf } = doc.defaultView;
expect(conf.edDraftURI).toBe("");
});
it("supports custom newIssuesURL", async () => {
const opts = {
config: Object.assign(makeBasicConfig(), {
github: {
repoURL: "https://github.com/speced/respec/",
newIssuesURL: "https://github.com/speced/respec/issues/new",
},
excludeGithubLinks: false,
}),
body: makeDefaultBody(),
};
delete opts.config.edDraftURI;
const doc = await makeRSDoc(opts);
const { respecConfig: conf } = doc.defaultView;
expect(conf.github.newIssuesURL).toBe(
"https://github.com/speced/respec/issues/new"
);
// Also verify the rendered feedback link in the DOM uses the custom URL
const fileABug = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "File an issue"
);
expect(fileABug).toBeTruthy();
expect(fileABug.querySelector("a").href).toBe(
"https://github.com/speced/respec/issues/new"
);
});
it("normalizes github object with custom pullsURL and commitHistoryURL", async () => {
const opts = {
config: Object.assign(makeBasicConfig(), {
github: {
repoURL: "https://github.com/w3c/core-aam/",
pullsURL: "https://github.com/w3c/aria/pulls/",
commitHistoryURL: "https://github.com/w3c/aria/commits/",
},
}),
body: makeDefaultBody(),
};
delete opts.config.edDraftURI;
delete opts.config.shortName;
const doc = await makeRSDoc(opts);
const { respecConfig: conf } = doc.defaultView;
// Check that the github object is normalized correctly
expect(conf.github.pullsURL).toBe("https://github.com/w3c/aria/pulls/");
expect(conf.github.commitHistoryURL).toBe(
"https://github.com/w3c/aria/commits/"
);
expect(conf.github.issuesURL).toBe(
"https://github.com/w3c/core-aam/issues/"
);
expect(conf.github.repoURL).toBe("https://github.com/w3c/core-aam/");
});
});
describe("the definition list items (localized)", () => {
const l10n = {
htmlAttrs: {
lang: "nl",
},
};
function definitionListTest(doc) {
const participate = Array.from(doc.querySelectorAll("dt")).find(
node => node.textContent === "Doe mee:"
);
expect(participate).toBeTruthy();
const allIssues = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "All issues"
);
expect(allIssues).toBeTruthy();
expect(allIssues.querySelector("a").href).toBe(
"https://github.com/speced/respec/issues/"
);
const fileABug = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "Dien een melding in"
);
expect(fileABug).toBeTruthy();
expect(fileABug.querySelector("a").href).toBe(
"https://github.com/speced/respec/issues/new/choose"
);
const commitHistory = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "Revisiehistorie"
);
expect(commitHistory).toBeTruthy();
const ghLink = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "GitHub speced/respec"
);
const pullRequests = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "Pull requests"
);
expect(pullRequests).toBeTruthy();
expect(pullRequests.querySelector("a").href).toBe(
"https://github.com/speced/respec/pulls/"
);
expect(ghLink).toBeTruthy();
expect(ghLink.querySelector("a").href).toBe(
"https://github.com/speced/respec/"
);
// This differs between the string and the object tests, so we return it
return commitHistory;
}
it("generates a participate set of links (from string)", async () => {
const doc = await makeRSDoc({ ...l10n, ...stringOpt });
const commitHistory = definitionListTest(doc);
expect(commitHistory.querySelector("a").href).toBe(
"https://github.com/speced/respec/commits/"
);
});
it("generates a participate set of links (from object)", async () => {
const doc = await makeRSDoc({ ...l10n, ...objOpt });
const commitHistory = definitionListTest(doc);
expect(commitHistory.querySelector("a").href).toBe(
"https://github.com/speced/respec/commits/develop"
);
});
it("supports custom pullsURL and commitHistoryURL for monorepo scenarios", async () => {
const customOpt = {
config: Object.assign(makeBasicConfig(), {
github: {
repoURL: "https://github.com/w3c/core-aam/",
pullsURL:
"https://github.com/w3c/aria/pulls?q=+label%3A%22spec%3Acore-aam%22is%3Apr+is%3Aopen+",
commitHistoryURL:
"https://github.com/w3c/aria/commits/main/core-aam",
},
excludeGithubLinks: false,
}),
body: makeDefaultBody(),
htmlAttrs: {
lang: "nl",
},
};
delete customOpt.config.edDraftURI;
delete customOpt.config.shortName;
const doc = await makeRSDoc(customOpt);
// Check that the custom pull request URL with parameters is used
const pullRequests = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "Pull requests"
);
expect(pullRequests).toBeTruthy();
expect(pullRequests.querySelector("a").href).toBe(
"https://github.com/w3c/aria/pulls?q=+label%3A%22spec%3Acore-aam%22is%3Apr+is%3Aopen+"
);
// Check that the custom commit history URL is used
const commitHistory = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "Revisiehistorie"
);
expect(commitHistory).toBeTruthy();
expect(commitHistory.querySelector("a").href).toBe(
"https://github.com/w3c/aria/commits/main/core-aam"
);
// Issue base should still use repoURL
const fileABug = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "Dien een melding in"
);
expect(fileABug).toBeTruthy();
const allIssues = Array.from(doc.querySelectorAll("dd")).find(
elem => elem.textContent.trim() === "All issues"
);
expect(allIssues).toBeTruthy();
expect(allIssues.querySelector("a").href).toBe(
"https://github.com/w3c/core-aam/issues/"
);
expect(fileABug.querySelector("a").href).toBe(
"https://github.com/w3c/core-aam/issues/new/choose"
);
});
});
});