|
| 1 | +import type { BrowserContext, Page } from '@playwright/test'; |
1 | 2 | import { test, expect } from '../fixtures'; |
2 | 3 | import { dismissCookieBanner } from '../helpers/cookie-banner'; |
3 | 4 |
|
@@ -110,4 +111,56 @@ test.describe('editor page', () => { |
110 | 111 | ) |
111 | 112 | ).toBeVisible(); |
112 | 113 | }); |
| 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 | + }); |
113 | 166 | }); |
0 commit comments