@salesforcedevs/sfdocs-e2e 1.0.12-fix-ver-picker-1 → 1.0.12

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/sfdocs-e2e",
3
- "version": "1.0.12-fix-ver-picker-1",
3
+ "version": "1.0.12",
4
4
  "description": "E2E test suite for SFDocs static portal pages (SSG)",
5
5
  "license": "ISC",
6
6
  "bin": {
@@ -0,0 +1,101 @@
1
+ class ContentActionToolbar {
2
+ HOST_SELECTOR = 'doc-content-action-toolbar';
3
+ INLINE_BUTTON_SELECTOR = 'dx-button.toolbar-button';
4
+ MENU_TRIGGER_SELECTOR = 'dx-button.menu-trigger';
5
+ MENU_SELECTOR = 'dx-dropdown.toolbar-menu';
6
+ MENU_GROUP_SELECTOR = 'div.menu_option';
7
+ MENU_HEADING_SELECTOR = 'span.menu_heading';
8
+ MENU_OPTION_SELECTOR = 'dx-dropdown-option';
9
+ OPTION_LABEL_SELECTOR = 'div.option_label';
10
+ COPIED_TOOLTIP_SELECTOR = '[role="tooltip"].is-visible';
11
+
12
+ async get(): Promise<WebdriverIO.Element> {
13
+ const toolbar = await $(`>>>${this.HOST_SELECTOR}`);
14
+ await toolbar.waitForDisplayed();
15
+ return toolbar;
16
+ }
17
+
18
+ async isPresent(): Promise<boolean> {
19
+ return (await $(`>>>${this.HOST_SELECTOR}`)).isExisting();
20
+ }
21
+
22
+ async getInlineButtonLabels(toolbar: WebdriverIO.Element): Promise<string[]> {
23
+ const inlineButtons = await toolbar.shadow$$(this.INLINE_BUTTON_SELECTOR);
24
+ return Promise.all(inlineButtons.map(async (button) => (await button.getText()).trim()));
25
+ }
26
+
27
+ async openMoreActionsMenu(toolbar: WebdriverIO.Element): Promise<void> {
28
+ const trigger = await toolbar.shadow$(this.MENU_TRIGGER_SELECTOR);
29
+ await trigger.waitForClickable();
30
+ await trigger.click();
31
+ }
32
+
33
+ async getMenuOptionLabelsByGroup(
34
+ toolbar: WebdriverIO.Element,
35
+ ): Promise<Record<string, string[]>> {
36
+ const dropdown = await toolbar.shadow$(this.MENU_SELECTOR);
37
+ const groupContainers = await dropdown.shadow$$(this.MENU_GROUP_SELECTOR);
38
+
39
+ const labelsByGroup: Record<string, string[]> = {};
40
+ for (const group of groupContainers) {
41
+ const heading = (await (await group.$(this.MENU_HEADING_SELECTOR)).getText()).trim();
42
+ const options = await group.$$(this.MENU_OPTION_SELECTOR);
43
+ labelsByGroup[heading] = await Promise.all(
44
+ options.map(async (option) =>
45
+ (await (await option.shadow$(this.OPTION_LABEL_SELECTOR)).getText()).trim(),
46
+ ),
47
+ );
48
+ }
49
+ return labelsByGroup;
50
+ }
51
+
52
+ async clickMenuOption(toolbar: WebdriverIO.Element, label: string): Promise<void> {
53
+ const dropdown = await toolbar.shadow$(this.MENU_SELECTOR);
54
+ const options = await dropdown.shadow$$(this.MENU_OPTION_SELECTOR);
55
+ for (const option of options) {
56
+ const optionLabel = (
57
+ await (await option.shadow$(this.OPTION_LABEL_SELECTOR)).getText()
58
+ ).trim();
59
+ if (optionLabel === label) {
60
+ await option.click();
61
+ return;
62
+ }
63
+ }
64
+ throw new Error(`Menu option "${label}" not found`);
65
+ }
66
+
67
+ async getUrlFromNewTab(action: () => Promise<void>): Promise<string> {
68
+ const originalHandle = await browser.getWindowHandle();
69
+ const handlesBefore = await browser.getWindowHandles();
70
+
71
+ await action();
72
+
73
+ await browser.waitUntil(
74
+ async (): Promise<boolean> =>
75
+ (await browser.getWindowHandles()).length > handlesBefore.length,
76
+ {
77
+ timeout: 10000,
78
+ timeoutMsg: 'Expected a new browser tab to open',
79
+ },
80
+ );
81
+
82
+ const handlesAfter = await browser.getWindowHandles();
83
+ const newHandle = handlesAfter.find((handle) => !handlesBefore.includes(handle));
84
+ if (!newHandle) {
85
+ throw new Error('New browser tab opened but its handle could not be resolved');
86
+ }
87
+ await browser.switchToWindow(newHandle);
88
+ const url = await browser.getUrl();
89
+
90
+ await browser.closeWindow();
91
+ await browser.switchToWindow(originalHandle);
92
+ return url;
93
+ }
94
+
95
+ async getVisibleCopiedTooltipLabel(): Promise<string> {
96
+ const tooltip = await $(`>>>${this.COPIED_TOOLTIP_SELECTOR}`);
97
+ return (await tooltip.getAttribute('aria-label'))?.trim() ?? '';
98
+ }
99
+ }
100
+
101
+ export default new ContentActionToolbar();
@@ -33,13 +33,11 @@ class DocsPage extends Page {
33
33
  }
34
34
 
35
35
  private async getTreeTile(treeItem: WebdriverIO.Element): Promise<WebdriverIO.Element> {
36
- await treeItem.waitForExist();
37
36
  return treeItem.shadow$('a > dx-tree-tile');
38
37
  }
39
38
 
40
39
  private async getTreeItemLabel(treeItem: WebdriverIO.Element): Promise<string> {
41
40
  const treeTile = await this.getTreeTile(treeItem);
42
- await treeTile.waitForExist();
43
41
  const label = await treeTile.shadow$('span.tile-label');
44
42
  return (await label.getText()).trim();
45
43
  }
@@ -76,16 +74,12 @@ class DocsPage extends Page {
76
74
 
77
75
  async getTileForwardArrow(label: string): Promise<WebdriverIO.Element> {
78
76
  const treeItem = await this.getSidebarTile(label);
79
- const treeTile = await this.getTreeTile(treeItem);
80
- await treeTile.waitForExist();
81
- return treeTile.shadow$('.tile-forward-arrow');
77
+ return (await this.getTreeTile(treeItem)).shadow$('.tile-forward-arrow');
82
78
  }
83
79
 
84
80
  async getTileExternalLinkIcon(label: string): Promise<WebdriverIO.Element> {
85
81
  const treeItem = await this.getSidebarTile(label);
86
- const treeTile = await this.getTreeTile(treeItem);
87
- await treeTile.waitForExist();
88
- return treeTile.shadow$('.tile-external-link-icon');
82
+ return (await this.getTreeTile(treeItem)).shadow$('.tile-external-link-icon');
89
83
  }
90
84
 
91
85
  async getRedocBackLink(): Promise<WebdriverIO.Element> {
@@ -28,7 +28,6 @@ export class ReferencePage extends Page {
28
28
  const versionPicker = await this.getVersionPickerBtn();
29
29
  await versionPicker.click();
30
30
  const versionOptions = await $$('>>>doc-version-picker dx-dropdown-option');
31
- await versionOptions[1].waitForClickable();
32
31
  await versionOptions[1].click();
33
32
  }
34
33
 
@@ -1,6 +1,7 @@
1
1
  import DocsPage from '../pageobjects/docs.page';
2
2
  import GuidePage from '../pageobjects/guide.page';
3
3
  import { ReferencePage } from '../pageobjects/reference.page';
4
+ import contentActionToolbar from '../pageobjects/content-action-toolbar';
4
5
 
5
6
  const DOCS_MARKDOWN_PATH = '/docs/docs-content-type-example/get-started.html';
6
7
 
@@ -10,63 +11,154 @@ const EN_US_MARKDOWN_REFERENCE_PATH =
10
11
  const NON_MARKDOWN_REFERENCE_PATH = '/docs/test-metamind-oas-api/references/1mkfx9?meta=Summary';
11
12
  const NON_EN_US_MARKDOWN_REFERENCE_PATH =
12
13
  '/docs/commerce/ja-jp/flex-references-loc/references/manual-ref/commerce-cloud-api-overview.html';
13
-
14
- async function expectToolbarButtons(toolbar: WebdriverIO.Element): Promise<void> {
15
- const toolbarButtons = await toolbar.shadow$$('dx-button.toolbar-button');
16
- expect(toolbarButtons.length).toBe(3);
17
-
18
- const labels = await Promise.all(
19
- toolbarButtons.map(async (button) => (await button.getText()).trim()),
20
- );
21
- expect(labels).toEqual(
22
- expect.arrayContaining(['Copy as Markdown', 'View as Markdown', 'Copy URL to Markdown']),
23
- );
24
- }
14
+ const INLINE_MARKDOWN_LABELS = ['Copy as Markdown', 'View as Markdown', 'View llms.txt'];
15
+ const MENU_GROUPS = {
16
+ 'This Page': [
17
+ 'Copy as Markdown',
18
+ 'View as Markdown',
19
+ 'Copy URL to Markdown',
20
+ 'Open in ChatGPT',
21
+ 'Open in Claude',
22
+ 'Open in Perplexity',
23
+ ],
24
+ 'All Documentation': ['View llms.txt', 'Copy URL to llms.txt'],
25
+ };
26
+ const AI_ASSISTANTS = [
27
+ { label: 'Open in ChatGPT', host: 'chatgpt.com' },
28
+ { label: 'Open in Claude', host: 'claude.ai' },
29
+ { label: 'Open in Perplexity', host: 'www.perplexity.ai' },
30
+ ];
31
+ const LLMS_TXT_PATH = '/docs/llms.txt';
32
+ const COPIED_TOOLTIP_LABEL = 'Copied!';
25
33
 
26
34
  describe('Content action toolbar scenarios', () => {
27
- it('Markdown guide should have the toolbar', async () => {
35
+ it('should show the inline markdown actions when opening a markdown guide', async () => {
28
36
  const page = new GuidePage(EN_US_GUIDE_PATH);
29
37
  page.open();
30
38
  await page.waitPageLoad();
31
39
 
32
- const toolbar = await $('>>>doc-content-action-toolbar');
33
- await toolbar.waitForDisplayed();
34
- await expectToolbarButtons(toolbar);
40
+ const toolbar = await contentActionToolbar.get();
41
+ expect(await contentActionToolbar.getInlineButtonLabels(toolbar)).toEqual(
42
+ expect.arrayContaining(INLINE_MARKDOWN_LABELS),
43
+ );
35
44
  });
36
45
 
37
- it('Markdown reference should have the toolbar', async () => {
46
+ it('should show the inline markdown actions when opening a markdown reference', async () => {
38
47
  const referencePage = new ReferencePage(EN_US_MARKDOWN_REFERENCE_PATH);
39
48
  referencePage.open();
40
49
  await referencePage.waitForMarkdownBasedReferencePageLoad();
41
50
 
42
- const toolbar = await $('>>>doc-content-action-toolbar');
43
- await toolbar.waitForDisplayed();
44
- await expectToolbarButtons(toolbar);
51
+ const toolbar = await contentActionToolbar.get();
52
+ expect(await contentActionToolbar.getInlineButtonLabels(toolbar)).toEqual(
53
+ expect.arrayContaining(INLINE_MARKDOWN_LABELS),
54
+ );
45
55
  });
46
56
 
47
- it('Markdown docs page should have the toolbar', async () => {
57
+ it('should show the inline markdown actions when opening a markdown docs page', async () => {
48
58
  const page = new DocsPage(DOCS_MARKDOWN_PATH);
49
59
  page.open();
50
60
  await page.waitPageLoad();
51
61
 
52
- const toolbar = await $('>>>doc-content-action-toolbar');
53
- await toolbar.waitForDisplayed();
54
- await expectToolbarButtons(toolbar);
62
+ const toolbar = await contentActionToolbar.get();
63
+ expect(await contentActionToolbar.getInlineButtonLabels(toolbar)).toEqual(
64
+ expect.arrayContaining(INLINE_MARKDOWN_LABELS),
65
+ );
66
+ });
67
+
68
+ it('should expose the full grouped action set through the More actions menu on a markdown page', async () => {
69
+ const page = new GuidePage(EN_US_GUIDE_PATH);
70
+ page.open();
71
+ await page.waitPageLoad();
72
+
73
+ const toolbar = await contentActionToolbar.get();
74
+ await contentActionToolbar.openMoreActionsMenu(toolbar);
75
+
76
+ const labelsByGroup = await contentActionToolbar.getMenuOptionLabelsByGroup(toolbar);
77
+ expect(Object.keys(labelsByGroup)).toEqual(
78
+ expect.arrayContaining(Object.keys(MENU_GROUPS)),
79
+ );
80
+ for (const [group, expectedLabels] of Object.entries(MENU_GROUPS)) {
81
+ expect(labelsByGroup[group]).toEqual(expect.arrayContaining(expectedLabels));
82
+ }
55
83
  });
56
84
 
57
- it("Non-markdown reference shouldn't have toolbar", async () => {
85
+ AI_ASSISTANTS.forEach(({ label, host }) => {
86
+ it(`should open ${host} with the page context when selecting ${label}`, async () => {
87
+ const page = new GuidePage(EN_US_GUIDE_PATH);
88
+ page.open();
89
+ await page.waitPageLoad();
90
+
91
+ const toolbar = await contentActionToolbar.get();
92
+ await contentActionToolbar.openMoreActionsMenu(toolbar);
93
+
94
+ const url = await contentActionToolbar.getUrlFromNewTab(() =>
95
+ contentActionToolbar.clickMenuOption(toolbar, label),
96
+ );
97
+ expect(url).toContain(host);
98
+ });
99
+ });
100
+
101
+ it('should open the markdown version of the page in a new tab when selecting View as Markdown', async () => {
102
+ const page = new GuidePage(EN_US_GUIDE_PATH);
103
+ page.open();
104
+ await page.waitPageLoad();
105
+
106
+ const toolbar = await contentActionToolbar.get();
107
+ await contentActionToolbar.openMoreActionsMenu(toolbar);
108
+
109
+ const url = await contentActionToolbar.getUrlFromNewTab(() =>
110
+ contentActionToolbar.clickMenuOption(toolbar, 'View as Markdown'),
111
+ );
112
+ expect(url.endsWith('.md')).toBe(true);
113
+ });
114
+
115
+ it('should open the site llms.txt in a new tab when selecting View llms.txt', async () => {
116
+ const page = new GuidePage(EN_US_GUIDE_PATH);
117
+ page.open();
118
+ await page.waitPageLoad();
119
+
120
+ const toolbar = await contentActionToolbar.get();
121
+ await contentActionToolbar.openMoreActionsMenu(toolbar);
122
+
123
+ const url = await contentActionToolbar.getUrlFromNewTab(() =>
124
+ contentActionToolbar.clickMenuOption(toolbar, 'View llms.txt'),
125
+ );
126
+ expect(url.endsWith(LLMS_TXT_PATH)).toBe(true);
127
+ });
128
+
129
+ it('should flash the Copied! tooltip when selecting Copy URL to Markdown', async () => {
130
+ const page = new GuidePage(EN_US_GUIDE_PATH);
131
+ page.open();
132
+ await page.waitPageLoad();
133
+
134
+ const toolbar = await contentActionToolbar.get();
135
+ await contentActionToolbar.openMoreActionsMenu(toolbar);
136
+ await contentActionToolbar.clickMenuOption(toolbar, 'Copy URL to Markdown');
137
+
138
+ await browser.waitUntil(
139
+ async () =>
140
+ (await contentActionToolbar.getVisibleCopiedTooltipLabel()) ===
141
+ COPIED_TOOLTIP_LABEL,
142
+ {
143
+ timeout: 5000,
144
+ timeoutMsg: 'Expected the menu tooltip to flash "Copied!"',
145
+ },
146
+ );
147
+ });
148
+
149
+ it('should not show the toolbar on a non-markdown reference', async () => {
58
150
  const referencePage = new ReferencePage(NON_MARKDOWN_REFERENCE_PATH);
59
151
  referencePage.open();
60
152
  await referencePage.waitForSpecBasedReferencePageLoad();
61
153
 
62
- const toolbar = await $('>>>doc-content-action-toolbar');
63
- expect(await toolbar.isExisting()).toBeFalsy();
154
+ expect(await contentActionToolbar.isPresent()).toBeFalsy();
64
155
  });
65
156
 
66
- it("Non en-us locale page shouldn't have toolbar", async () => {
157
+ it('should not show the toolbar on a non en-us page', async () => {
67
158
  const nonEnUsReferencePage = new ReferencePage(NON_EN_US_MARKDOWN_REFERENCE_PATH);
68
159
  nonEnUsReferencePage.open();
69
160
  await nonEnUsReferencePage.waitForMarkdownBasedReferencePageLoad();
70
- expect(await (await $('>>>doc-content-action-toolbar')).isExisting()).toBeFalsy();
161
+
162
+ expect(await contentActionToolbar.isPresent()).toBeFalsy();
71
163
  });
72
164
  });
@@ -66,24 +66,24 @@ describe('Test Guides page components functionality> ', () => {
66
66
 
67
67
  expect(sideBarContent.length).toEqual(6);
68
68
 
69
- const nextStepTreeItem = await sideBarContent[3].shadow$('dx-tree-item');
70
- await nextStepTreeItem.waitForExist();
71
- const nextStepOption = await nextStepTreeItem.shadow$('dx-tree-tile');
72
- await nextStepOption.waitForExist();
73
- expect(await nextStepOption.isExisting()).toBeTruthy();
74
-
75
- const installVSCodeTreeItem = await sideBarContent[1].shadow$('dx-tree-item');
76
- await installVSCodeTreeItem.waitForExist();
77
- const installVSCodeOptionTile = await installVSCodeTreeItem.shadow$('dx-tree-tile');
78
- await installVSCodeOptionTile.waitForExist();
79
- expect(await installVSCodeOptionTile.isExisting()).toBeTruthy();
80
-
81
- await installVSCodeTreeItem.click();
69
+ const nextStepOption = await (
70
+ await sideBarContent[3].shadow$('dx-tree-item')
71
+ ).shadow$('dx-tree-tile');
72
+
73
+ expect(nextStepOption.isExisting()).toBeTruthy();
74
+
75
+ const installVSCodeOptionTile = await (
76
+ await sideBarContent[1].shadow$('dx-tree-item')
77
+ ).shadow$('dx-tree-tile');
78
+
79
+ expect(installVSCodeOptionTile.isExisting()).toBeTruthy();
80
+
81
+ await (await sideBarContent[1].shadow$('dx-tree-item')).click();
82
82
  await page.waitPageLoad();
83
83
 
84
- const installVSCodeTreeItemAfterNav = await sideBarContent[1].shadow$('dx-tree-item');
85
- await installVSCodeTreeItemAfterNav.waitForExist();
86
- const installVSCodeOption = await installVSCodeTreeItemAfterNav.shadow$$('dx-tree-item');
84
+ const installVSCodeOption = await (
85
+ await sideBarContent[1].shadow$('dx-tree-item')
86
+ ).shadow$$('dx-tree-item');
87
87
 
88
88
  expect(installVSCodeOption.length).toEqual(3);
89
89
 
@@ -304,15 +304,9 @@ describe('Search guides', () => {
304
304
  await browser.keys('SFRA');
305
305
 
306
306
  const trees = await sidebar.shadow$$('div.container div.sidebar-content dx-tree');
307
- const rootTreeItem = await trees[0].shadow$('dx-tree-item');
308
- await rootTreeItem.waitForExist();
309
- const servicesTree = await rootTreeItem.shadow$('dx-tree-item');
310
- await servicesTree.waitForExist();
307
+ const servicesTree = await (await trees[0].shadow$('dx-tree-item')).shadow$('dx-tree-item');
311
308
  const treeItem = await servicesTree.shadow$('dx-tree-item');
312
- await treeItem.waitForExist();
313
- const treeTile = await treeItem.shadow$('dx-tree-tile');
314
- await treeTile.waitForExist();
315
- const item = await treeTile.shadow$('span');
309
+ const item = await (await treeItem.shadow$('dx-tree-tile')).shadow$('span');
316
310
  const itemText = await item.getText();
317
311
  expect(itemText).toBe('Find SFRA Tools');
318
312
  });
@@ -328,10 +322,7 @@ describe('Search guides', () => {
328
322
  await browser.keys('SFRA');
329
323
 
330
324
  const trees = await (await sidebar).shadow$$('div.container div.sidebar-content dx-tree');
331
- const rootTreeItem = await trees[0].shadow$('dx-tree-item');
332
- await rootTreeItem.waitForExist();
333
- const servicesTree = await rootTreeItem.shadow$('dx-tree-item');
334
- await servicesTree.waitForExist();
325
+ const servicesTree = await (await trees[0].shadow$('dx-tree-item')).shadow$('dx-tree-item');
335
326
  const treeItem = await servicesTree.shadow$('dx-tree-item');
336
327
  await treeItem.click();
337
328
  await page.waitPageLoad();
@@ -190,13 +190,10 @@ describe('Redoc API Reference page', () => {
190
190
 
191
191
  const secondItem = sideBarContent[1];
192
192
  const treeItem = await secondItem.shadow$('dx-tree-item');
193
- await treeItem.waitForExist();
194
193
  const treeTile = await treeItem.shadow$('a > dx-tree-tile');
195
- await treeTile.waitForExist();
196
194
  const arrowIcon = await treeTile.shadow$(
197
195
  'a > div[role="heading"] > div.tile-forward-arrow',
198
196
  );
199
- await arrowIcon.waitForExist();
200
197
 
201
198
  expect(await arrowIcon.isExisting()).toBeTruthy();
202
199
  });
@@ -109,8 +109,6 @@ describe('Reference Versioning', () => {
109
109
  const versionOptions = await $$('>>>doc-version-picker dx-dropdown-option');
110
110
 
111
111
  expect(versionOptions.length).toEqual(2);
112
- await versionOptions[0].waitForClickable();
113
- await versionOptions[1].waitForClickable();
114
112
  expect(await (await versionOptions[0].shadow$('div>div')).getText()).toEqual('0.1.3');
115
113
  expect(await (await versionOptions[1].shadow$('div>div')).getText()).toEqual('0.1.2');
116
114
  });
@@ -153,8 +151,6 @@ describe('Reference Versioning', () => {
153
151
  await versionPicker.click();
154
152
 
155
153
  const versionOptions = await $$('>>>doc-version-picker dx-dropdown-option');
156
-
157
- await versionOptions[1].waitForClickable();
158
154
  const selectedVersionText = await (await versionOptions[1].shadow$('div>div')).getText();
159
155
 
160
156
  await versionOptions[1].click();
@@ -226,12 +222,11 @@ describe('Markdown-Based Flexible References', () => {
226
222
  const sidebar = await (await $('>>>doc-content-layout')).shadow$('div > dx-sidebar-old');
227
223
  const sideBarContent = await sidebar.shadow$$('div.container div.sidebar-content dx-tree');
228
224
  expect(sideBarContent.length).toEqual(1);
229
- const treeItem = await sideBarContent[0].shadow$('dx-tree-item');
230
- await treeItem.waitForExist();
231
- const tile = await treeItem.shadow$('dx-tree-tile');
232
- await tile.waitForExist();
233
- expect(await tile.isExisting()).toBeTruthy();
234
- await treeItem.click();
225
+ const tile = await (
226
+ await sideBarContent[0].shadow$('dx-tree-item')
227
+ ).shadow$('dx-tree-tile');
228
+ expect(tile.isExisting()).toBeTruthy();
229
+ await (await sideBarContent[0].shadow$('dx-tree-item')).click();
235
230
  await referencePage.waitForMarkdownBasedReferencePageLoad();
236
231
  const title = await $('>>>h1');
237
232
  const titleText = await title.getText();