Skip to content

Commit 570a11b

Browse files
authored
Merge pull request #4260 from Geethegreat/nav-dropdown-redirects
GSOC-E2E: Add test for nav dropdown redirects
2 parents 292cb56 + 226572f commit 570a11b

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

e2e/specs/editor.spec.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { BrowserContext, Page } from '@playwright/test';
12
import { test, expect } from '../fixtures';
23
import { dismissCookieBanner } from '../helpers/cookie-banner';
34

@@ -110,4 +111,56 @@ test.describe('editor page', () => {
110111
)
111112
).toBeVisible();
112113
});
114+
115+
test.describe('nav dropdown redirects', () => {
116+
// Reused by the two Help items that open an external link in a new tab.
117+
const expectHelpLinkOpensNewTab = async (
118+
page: Page,
119+
context: BrowserContext,
120+
locatorId: string,
121+
urlSubstring: string
122+
) => {
123+
await page.getByRole('menuitem', { name: 'Help' }).click();
124+
const [newTab] = await Promise.all([
125+
context.waitForEvent('page'),
126+
page.locator(locatorId).click()
127+
]);
128+
await newTab.waitForLoadState();
129+
expect(newTab.url()).toContain(urlSubstring);
130+
await newTab.close();
131+
};
132+
133+
test('File > Examples opens in the same tab', async ({ page }) => {
134+
await page.getByRole('menuitem', { name: 'File' }).click();
135+
await page.locator('#file-examples').click();
136+
await expect(page).toHaveURL(/\/p5\/sketches/, { timeout: 10_000 });
137+
});
138+
139+
test('Help > About opens in the same tab', async ({ page }) => {
140+
await page.getByRole('menuitem', { name: 'Help' }).click();
141+
await page.locator('#help-about').click();
142+
await expect(page).toHaveURL(/\/about/, { timeout: 10_000 });
143+
});
144+
145+
test('Help > Reference opens in a new tab', async ({ page, context }) => {
146+
await expectHelpLinkOpensNewTab(
147+
page,
148+
context,
149+
'#help-reference',
150+
'p5js.org/reference'
151+
);
152+
});
153+
154+
test('Help > Post on the Forum opens in a new tab', async ({
155+
page,
156+
context
157+
}) => {
158+
await expectHelpLinkOpensNewTab(
159+
page,
160+
context,
161+
'#help-forum',
162+
'discourse.processing.org/c/p5js/10'
163+
);
164+
});
165+
});
113166
});

0 commit comments

Comments
 (0)