@salesforcedevs/sfdocs-e2e 1.0.11 → 1.0.12-e2e-topic-version-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,432 @@
1
+ import { it } from 'mocha';
2
+ import TopicVersionPage from '../pageobjects/topic-version.page';
3
+
4
+ // Fixtures live in the `docs-content-type-example` project, kept in sync between this monorepo's
5
+ // local `packages/example-repository` and the remote `salesforcedocs/example-repository`'s
6
+ // `mh/topic-level-version` branch.
7
+ const BASE = '/docs/docs-content-type-example';
8
+
9
+ let page: TopicVersionPage;
10
+
11
+ describe('Topic-level versioning > versioned markdown topic', () => {
12
+ // fixture: OAuth — latest v2 'WI'26' / older v1 'SU'26'.
13
+ beforeEach(async () => {
14
+ page = new TopicVersionPage(`${BASE}/oauth.html`);
15
+ page.open();
16
+ await page.waitForMarkdownTopicLoad();
17
+ });
18
+
19
+ it('should render the picker and default to the latest version', async () => {
20
+ const picker = await page.getSidebarPicker('OAuth');
21
+ expect(picker).not.toBeNull();
22
+ expect(await page.getSelectedVersionLabel(picker!)).toEqual("WI'26");
23
+ expect(await page.isLatestDotShown(picker!)).toBeTruthy();
24
+ });
25
+
26
+ it('should list all versions in declared order when the picker is opened', async () => {
27
+ const picker = await page.getSidebarPicker('OAuth');
28
+ await page.openPicker(picker!);
29
+
30
+ const options = await page.getVersionOptions();
31
+ expect(options.length).toEqual(2);
32
+ expect(await page.getOptionLabel(options[0])).toEqual("WI'26");
33
+ expect(await page.getOptionLabel(options[1])).toEqual("SU'26");
34
+ });
35
+
36
+ it('should switch the page content and URL when a non-latest version is selected', async () => {
37
+ const picker = await page.getSidebarPicker('OAuth');
38
+ await page.selectVersionByLabel(picker!, "SU'26");
39
+ await page.waitForMarkdownTopicLoad();
40
+
41
+ expect(await (await $('>>>h1')).getText()).toEqual('OAuth 1.0');
42
+ await browser.waitUntil(
43
+ async () => (await browser.getUrl()).includes(`${BASE}/v1/oauth.html`),
44
+ { timeoutMsg: 'expected URL to contain /v1/oauth.html' },
45
+ );
46
+ });
47
+
48
+ it('should return to the canonical URL when the latest version is reselected', async () => {
49
+ page = new TopicVersionPage(`${BASE}/v1/oauth.html`);
50
+ page.open();
51
+ await page.waitForMarkdownTopicLoad();
52
+
53
+ const picker = await page.getSidebarPicker('OAuth');
54
+ await page.selectVersionByLabel(picker!, "WI'26");
55
+ await page.waitForMarkdownTopicLoad();
56
+
57
+ const url = await browser.getUrl();
58
+ expect(url.endsWith(`${BASE}/oauth.html`)).toBeTruthy();
59
+ expect(url).not.toContain('/v2/');
60
+ expect(await (await $('>>>h1')).getText()).toEqual('OAuth 2.0');
61
+ });
62
+
63
+ // TODO: unconfirmed whether markdown topics render this banner at all yet (only Redoc spec
64
+ // pages are confirmed to). Enable once verified.
65
+ it.skip('should show the "Newer Version Available" banner when the version is not latest', async () => {
66
+ page = new TopicVersionPage(`${BASE}/v1/oauth.html`);
67
+ page.open();
68
+ await page.waitForMarkdownTopicLoad();
69
+
70
+ const banner = await page.getMarkdownVersionBanner();
71
+ expect(banner).not.toBeNull();
72
+ });
73
+
74
+ it('should not show the "Newer Version Available" banner when the version is latest', async () => {
75
+ const banner = await page.getMarkdownVersionBanner();
76
+ expect(banner).toBeNull();
77
+ });
78
+ });
79
+
80
+ describe('Topic-level versioning > versioned parent with versioned child subtree', () => {
81
+ // fixture: Client SDKs — latest v2 'WI'26' / older v1 'SU'26'.
82
+ beforeEach(async () => {
83
+ page = new TopicVersionPage(`${BASE}/android.html`);
84
+ page.open();
85
+ await page.waitForMarkdownTopicLoad();
86
+ });
87
+
88
+ it('should render the picker on the parent and default to the latest version', async () => {
89
+ const picker = await page.getSidebarPicker('Client SDKs');
90
+ expect(picker).not.toBeNull();
91
+ expect(await page.getSelectedVersionLabel(picker!)).toEqual("WI'26");
92
+ });
93
+
94
+ it('should switch the whole child subtree when the parent version changes', async () => {
95
+ const picker = await page.getSidebarPicker('Client SDKs');
96
+ await page.selectVersionByLabel(picker!, "SU'26");
97
+ await page.waitForMarkdownTopicLoad();
98
+
99
+ await browser.waitUntil(
100
+ async () => (await browser.getUrl()).includes(`${BASE}/v1/android.html`),
101
+ { timeoutMsg: 'expected URL to contain /v1/android.html' },
102
+ );
103
+ expect(await (await $('>>>h1')).getText()).toEqual('Android SDK v1');
104
+
105
+ // Sibling child (iOS SDK) should also have moved to the v1 URL, not just this one.
106
+ const iosItem = await page.getSidebarTreeItem('iOS SDK');
107
+ const iosTile = await page.getTreeItemTile(iosItem);
108
+ const iosAnchor = await iosTile.shadow$('a');
109
+ expect(await iosAnchor.getAttribute('href')).toContain('/v1/ios.html');
110
+ });
111
+
112
+ // TODO: known gap — navigating directly to a different child version URL doesn't sync the
113
+ // parent's picker or sibling hrefs back to that version; both stay stuck on the version the
114
+ // page first loaded with. Enable once that reverse sync ships.
115
+ it.skip('should update the picker and sibling hrefs when navigating directly to a different child version', async () => {
116
+ page = new TopicVersionPage(`${BASE}/v1/android.html`);
117
+ page.open();
118
+ await page.waitForMarkdownTopicLoad();
119
+
120
+ page = new TopicVersionPage(`${BASE}/android.html`);
121
+ page.open();
122
+ await page.waitForMarkdownTopicLoad();
123
+
124
+ const picker = await page.getSidebarPicker('Client SDKs');
125
+ expect(await page.getSelectedVersionLabel(picker!)).toEqual("WI'26");
126
+
127
+ const iosItem = await page.getSidebarTreeItem('iOS SDK');
128
+ const iosTile = await page.getTreeItemTile(iosItem);
129
+ const iosAnchor = await iosTile.shadow$('a');
130
+ const href = await iosAnchor.getAttribute('href');
131
+ expect(href).toContain('/ios.html');
132
+ expect(href).not.toContain('/v1/');
133
+ });
134
+ });
135
+
136
+ describe('Topic-level versioning > versioned parent with own content, subtopics and a spec subtopic', () => {
137
+ // fixture: Errors and Rate Limits — latest v2 'SP'26' / older v1 'WI'25'.
138
+ beforeEach(async () => {
139
+ page = new TopicVersionPage(`${BASE}/errors-and-rate-limits.html`);
140
+ page.open();
141
+ await page.waitForMarkdownTopicLoad();
142
+ });
143
+
144
+ it('should render the picker and default to the latest version', async () => {
145
+ const picker = await page.getSidebarPicker('Errors and Rate Limits');
146
+ expect(picker).not.toBeNull();
147
+ expect(await page.getSelectedVersionLabel(picker!)).toEqual("SP'26");
148
+ });
149
+
150
+ it("should switch the parent's own page content when the version changes", async () => {
151
+ const picker = await page.getSidebarPicker('Errors and Rate Limits');
152
+ await page.selectVersionByLabel(picker!, "WI'25");
153
+ await page.waitForMarkdownTopicLoad();
154
+
155
+ expect(await (await $('>>>h1')).getText()).toEqual('Errors and Rate Limits (v1)');
156
+ await browser.waitUntil(
157
+ async () => (await browser.getUrl()).includes(`${BASE}/v1/errors-and-rate-limits.html`),
158
+ { timeoutMsg: 'expected URL to contain /v1/errors-and-rate-limits.html' },
159
+ );
160
+ });
161
+
162
+ it('should switch the markdown subtopics when the version changes', async () => {
163
+ const picker = await page.getSidebarPicker('Errors and Rate Limits');
164
+ await page.selectVersionByLabel(picker!, "WI'25");
165
+ await page.waitForMarkdownTopicLoad();
166
+
167
+ const child = await page.getSidebarTreeItem('Common Error Codes');
168
+ await child.click();
169
+ await page.waitForMarkdownTopicLoad();
170
+
171
+ expect(await (await $('>>>h1')).getText()).toEqual('Common Error Codes (v1)');
172
+ await browser.waitUntil(
173
+ async () => (await browser.getUrl()).includes(`${BASE}/v1/extra-child-a.html`),
174
+ { timeoutMsg: 'expected URL to contain /v1/extra-child-a.html' },
175
+ );
176
+ });
177
+
178
+ it('should switch the spec (Redoc) subtopic to the matching version when the version changes', async () => {
179
+ // Key cross-type cascade: parent v1 ⇒ the nested spec subtopic is v1 too.
180
+ const picker = await page.getSidebarPicker('Errors and Rate Limits');
181
+ await page.selectVersionByLabel(picker!, "WI'25");
182
+ await page.waitForMarkdownTopicLoad();
183
+
184
+ const child = await page.getSidebarTreeItem('Another Spec API');
185
+ await child.click();
186
+ await page.waitForRedocTopicLoad();
187
+
188
+ await browser.waitUntil(
189
+ async () => (await browser.getUrl()).includes(`${BASE}/v1/new-sample-api`),
190
+ { timeoutMsg: 'expected URL to contain /v1/new-sample-api' },
191
+ );
192
+ // v1's spec lacks the `GET /errors/{code}` operation that only v2 has — its absence
193
+ // confirms the v1 spec asset loaded, since both versions share the same spec title.
194
+ const getErrorCodeOperation = await $('a[href*="operation/getErrorCode"]');
195
+ expect(await getErrorCodeOperation.isExisting()).toBeFalsy();
196
+ });
197
+
198
+ // TODO: enable once redoc→parent version-sync ships — the elements already exist, only the
199
+ // sync behavior is unimplemented.
200
+ it.skip('should sync the parent topic version when the version is changed on the nested Redoc page', async () => {
201
+ const child = await page.getSidebarTreeItem('Another Spec API');
202
+ await child.click();
203
+ await page.waitForRedocTopicLoad();
204
+
205
+ const redocPicker = await page.getRedocPicker();
206
+ await page.selectVersionByLabel(redocPicker!, "WI'25");
207
+ await page.waitForRedocTopicLoad();
208
+
209
+ page = new TopicVersionPage(`${BASE}/errors-and-rate-limits.html`);
210
+ page.open();
211
+ await page.waitForMarkdownTopicLoad();
212
+
213
+ const parentPicker = await page.getSidebarPicker('Errors and Rate Limits');
214
+ expect(await page.getSelectedVersionLabel(parentPicker!)).toEqual("WI'25");
215
+ });
216
+ });
217
+
218
+ describe('Topic-level versioning > standalone Redoc reference', () => {
219
+ // fixture: Widgets API Reference — a spec (forward-arrow) topic, so it never gets a sidebar
220
+ // picker; the picker lives on the Redoc page's own project header instead.
221
+ beforeEach(async () => {
222
+ page = new TopicVersionPage(`${BASE}/widgets-api-reference`);
223
+ page.open();
224
+ await page.waitForRedocTopicLoad();
225
+ });
226
+
227
+ it('should render the Redoc version picker and default to the latest version', async () => {
228
+ const picker = await page.getRedocPicker();
229
+ expect(picker).not.toBeNull();
230
+ expect(await page.getSelectedVersionLabel(picker!)).toEqual("SU'26");
231
+ });
232
+
233
+ it('should switch the rendered spec when a different version is selected', async () => {
234
+ const picker = await page.getRedocPicker();
235
+ await page.selectVersionByLabel(picker!, "SP'26");
236
+ await page.waitForRedocTopicLoad();
237
+
238
+ await browser.waitUntil(
239
+ async () => (await browser.getUrl()).includes(`${BASE}/v1/widgets-api-reference`),
240
+ { timeoutMsg: 'expected URL to contain /v1/widgets-api-reference' },
241
+ );
242
+ const apiInfo = await $('>>>div.api-info');
243
+ expect(await apiInfo.getText()).toContain('1.0.0');
244
+ });
245
+
246
+ it('should show the "Newer Version Available" banner when the version is not latest', async () => {
247
+ page = new TopicVersionPage(`${BASE}/v1/widgets-api-reference`);
248
+ page.open();
249
+ await page.waitForRedocTopicLoad();
250
+
251
+ const banner = await page.getRedocVersionBanner();
252
+ expect(banner).not.toBeNull();
253
+ expect(await page.getBannerTitle(banner!)).toEqual('Newer Version Available');
254
+ expect(await page.getBannerLinkHref(banner!)).toContain(`${BASE}/widgets-api-reference`);
255
+ });
256
+
257
+ it('should not show the "Newer Version Available" banner when the version is latest', async () => {
258
+ const banner = await page.getRedocVersionBanner();
259
+ expect(banner).toBeNull();
260
+ });
261
+ });
262
+
263
+ describe('Topic-level versioning > URL resolution (markdown)', () => {
264
+ it('should serve the latest version at the canonical URL', async () => {
265
+ page = new TopicVersionPage(`${BASE}/oauth.html`);
266
+ page.open();
267
+ await page.waitForMarkdownTopicLoad();
268
+ expect(await (await $('>>>h1')).getText()).toEqual('OAuth 2.0');
269
+ });
270
+
271
+ it('should serve the latest version at its versioned alias URL', async () => {
272
+ page = new TopicVersionPage(`${BASE}/v2/oauth.html`);
273
+ page.open();
274
+ await page.waitForMarkdownTopicLoad();
275
+ expect(await (await $('>>>h1')).getText()).toEqual('OAuth 2.0');
276
+ });
277
+
278
+ it('should serve an older version at its versioned URL', async () => {
279
+ page = new TopicVersionPage(`${BASE}/v1/oauth.html`);
280
+ page.open();
281
+ await page.waitForMarkdownTopicLoad();
282
+ expect(await (await $('>>>h1')).getText()).toEqual('OAuth 1.0');
283
+ });
284
+
285
+ it('should initialize the picker from the URL version', async () => {
286
+ page = new TopicVersionPage(`${BASE}/v1/oauth.html`);
287
+ page.open();
288
+ await page.waitForMarkdownTopicLoad();
289
+
290
+ const picker = await page.getSidebarPicker('OAuth');
291
+ expect(await page.getSelectedVersionLabel(picker!)).toEqual("SU'26");
292
+ });
293
+ });
294
+
295
+ describe('Topic-level versioning > URL resolution (spec)', () => {
296
+ it('should serve the latest spec at the canonical URL', async () => {
297
+ page = new TopicVersionPage(`${BASE}/widgets-api-reference`);
298
+ page.open();
299
+ await page.waitForRedocTopicLoad();
300
+ expect(await (await $('>>>div.api-info')).getText()).toContain('2.0.0');
301
+ });
302
+
303
+ it('should serve the latest spec at its versioned alias URL', async () => {
304
+ page = new TopicVersionPage(`${BASE}/v2/widgets-api-reference`);
305
+ page.open();
306
+ await page.waitForRedocTopicLoad();
307
+ expect(await (await $('>>>div.api-info')).getText()).toContain('2.0.0');
308
+ });
309
+
310
+ it('should serve an older spec at its versioned URL', async () => {
311
+ page = new TopicVersionPage(`${BASE}/v1/widgets-api-reference`);
312
+ page.open();
313
+ await page.waitForRedocTopicLoad();
314
+ expect(await (await $('>>>div.api-info')).getText()).toContain('1.0.0');
315
+ });
316
+ });
317
+
318
+ describe('Topic-level versioning > single-version picker (read-only)', () => {
319
+ // A topic with exactly one authored version still renders a picker, but read-only (no
320
+ // dropdown) and never with the "Newer Version Available" banner, since a single version is
321
+ // always the latest by definition.
322
+ // fixture: Widgets API (Beta) — single version 'Beta'.
323
+ it('should render a read-only picker with no dropdown when a Redoc spec has a single version', async () => {
324
+ page = new TopicVersionPage(`${BASE}/widgets-api-beta`);
325
+ page.open();
326
+ await page.waitForRedocTopicLoad();
327
+ const picker = await page.getRedocPicker();
328
+ expect(await page.isReadOnly(picker!)).toBeTruthy();
329
+ expect(await page.getRedocVersionBanner()).toBeNull();
330
+ });
331
+
332
+ // fixture: Link Between Topics — already single version ('WI'26'). TODO: enable once
333
+ // markdown topics render a read-only picker for single-version entries (the markdown
334
+ // counterpart to the Redoc case above).
335
+ it.skip('should render a read-only picker with no dropdown when a markdown topic has a single version', async () => {
336
+ page = new TopicVersionPage(`${BASE}/internal-linking.html`);
337
+ page.open();
338
+ await page.waitForMarkdownTopicLoad();
339
+ const picker = await page.getSidebarPicker('Link Between Topics');
340
+ expect(await page.isReadOnly(picker!)).toBeTruthy();
341
+ expect(await page.getMarkdownVersionBanner()).toBeNull();
342
+ });
343
+ });
344
+
345
+ describe('Topic-level versioning > topics without a version picker', () => {
346
+ it('should not render a sidebar picker when the markdown topic is evergreen', async () => {
347
+ page = new TopicVersionPage(`${BASE}/get-started.html`);
348
+ page.open();
349
+ await page.waitForMarkdownTopicLoad();
350
+
351
+ const picker = await page.getSidebarPicker('Get Started');
352
+ expect(picker).toBeNull();
353
+ expect(await browser.getUrl()).not.toMatch(/\/v\d+\//);
354
+ expect(await page.getMarkdownVersionBanner()).toBeNull();
355
+ });
356
+
357
+ // fixture: Widgets Status API — plain spec:, no versions: at all.
358
+ it('should not render a picker when the Redoc spec is evergreen', async () => {
359
+ page = new TopicVersionPage(`${BASE}/widgets-status-api`);
360
+ page.open();
361
+ await page.waitForRedocTopicLoad();
362
+ expect(await page.getRedocPicker()).toBeNull();
363
+ expect(await page.getRedocVersionBanner()).toBeNull();
364
+ });
365
+
366
+ it('should show the picker only on versioned rows when the sidebar is mixed', async () => {
367
+ page = new TopicVersionPage(`${BASE}/get-started.html`);
368
+ page.open();
369
+ await page.waitForMarkdownTopicLoad();
370
+ await page.waitForSidebar();
371
+
372
+ expect(await page.getSidebarPicker('OAuth')).not.toBeNull();
373
+ expect(await page.getSidebarPicker('Errors and Rate Limits')).not.toBeNull();
374
+ expect(await page.getSidebarPicker('Client SDKs')).not.toBeNull();
375
+ expect(await page.getSidebarPicker('Get Started')).toBeNull();
376
+ expect(await page.getSidebarPicker('Widget Concepts')).toBeNull();
377
+ });
378
+
379
+ it('should not leak a version segment when navigating to an evergreen topic', async () => {
380
+ page = new TopicVersionPage(`${BASE}/v1/oauth.html`);
381
+ page.open();
382
+ await page.waitForMarkdownTopicLoad();
383
+
384
+ const getStarted = await page.getSidebarTreeItem('Get Started');
385
+ await getStarted.click();
386
+ await page.waitForMarkdownTopicLoad();
387
+
388
+ expect(await browser.getUrl()).toContain(`${BASE}/get-started.html`);
389
+ expect(await browser.getUrl()).not.toContain('/v1/');
390
+ });
391
+ });
392
+
393
+ describe('Topic-level versioning > persistence on reload', () => {
394
+ it('should keep the selected version and its content after a refresh', async () => {
395
+ page = new TopicVersionPage(`${BASE}/oauth.html`);
396
+ page.open();
397
+ await page.waitForMarkdownTopicLoad();
398
+
399
+ const picker = await page.getSidebarPicker('OAuth');
400
+ await page.selectVersionByLabel(picker!, "SU'26");
401
+ await page.waitForMarkdownTopicLoad();
402
+
403
+ await browser.refresh();
404
+ await page.waitForMarkdownTopicLoad();
405
+
406
+ const pickerAfterReload = await page.getSidebarPicker('OAuth');
407
+ expect(await page.getSelectedVersionLabel(pickerAfterReload!)).toEqual("SU'26");
408
+ expect(await (await $('>>>h1')).getText()).toEqual('OAuth 1.0');
409
+ expect(await browser.getUrl()).toContain(`${BASE}/v1/oauth.html`);
410
+
411
+ const selections = await page.readSessionVersionSelections();
412
+ expect(selections).not.toBeNull();
413
+ });
414
+ });
415
+
416
+ describe('Topic-level versioning > invalid version in URL', () => {
417
+ it('should return a 404 when the markdown URL has an invalid version', async () => {
418
+ browser.url(`${BASE}/v999/oauth.html`);
419
+
420
+ const errorComponent = await $('dx-error');
421
+ await errorComponent.waitForDisplayed();
422
+ expect(await browser.getTitle()).toEqual('404 Error | Salesforce Developers');
423
+ });
424
+
425
+ it('should return a 404 when the spec URL has an invalid version', async () => {
426
+ browser.url(`${BASE}/v999/widgets-api-reference`);
427
+
428
+ const errorComponent = await $('dx-error');
429
+ await errorComponent.waitForDisplayed();
430
+ expect(await browser.getTitle()).toEqual('404 Error | Salesforce Developers');
431
+ });
432
+ });