|
1 | 1 | import { test, expect } from '@playwright/test'; |
2 | | -import { waitForReactMount, CONSOLE_BASE } from './helpers'; |
| 2 | +import { CONSOLE_BASE } from './helpers'; |
| 3 | +import { registerAndLogin } from './helpers/auth'; |
| 4 | + |
| 5 | +/** Timeout for sidebar elements to become visible after auth + page render. */ |
| 6 | +const SIDEBAR_VISIBLE_TIMEOUT = 15_000; |
3 | 7 |
|
4 | 8 | /** |
5 | 9 | * Sidebar text visibility tests |
6 | 10 | * |
7 | 11 | * These tests validate that the sidebar displays text correctly |
8 | 12 | * when toggled between collapsed (icon mode) and expanded states. |
| 13 | + * |
| 14 | + * The MSW mock environment requires authentication, so each test |
| 15 | + * registers a fresh user before navigating to the home page. |
9 | 16 | */ |
10 | 17 |
|
11 | 18 | test.describe('Sidebar Text Visibility', () => { |
12 | 19 | test('should show all text labels when sidebar is expanded in icon mode', async ({ page }) => { |
13 | | - await page.goto(`${CONSOLE_BASE}/`); |
14 | | - await waitForReactMount(page); |
| 20 | + // registerAndLogin navigates to /register, signs up, and waits for the |
| 21 | + // redirect to /home — the page is already authenticated & on the home route. |
| 22 | + await registerAndLogin(page); |
15 | 23 |
|
16 | | - // Wait for sidebar to be visible |
| 24 | + // Wait for sidebar to be visible (page needs time to render after auth redirect) |
17 | 25 | const sidebar = page.locator('[data-sidebar="sidebar"]').first(); |
18 | | - await expect(sidebar).toBeVisible(); |
| 26 | + await expect(sidebar).toBeVisible({ timeout: SIDEBAR_VISIBLE_TIMEOUT }); |
19 | 27 |
|
20 | | - // Find the sidebar toggle button |
| 28 | + // Find the sidebar toggle button (desktop trigger rendered by AppShell) |
21 | 29 | const toggleButton = page.locator('[data-sidebar="trigger"]').first(); |
22 | | - await expect(toggleButton).toBeVisible(); |
| 30 | + await expect(toggleButton).toBeVisible({ timeout: SIDEBAR_VISIBLE_TIMEOUT }); |
23 | 31 |
|
24 | 32 | // Get the parent sidebar element that has data-state attribute |
25 | 33 | const sidebarGroup = page.locator('.group[data-collapsible="icon"]').first(); |
@@ -92,14 +100,13 @@ test.describe('Sidebar Text Visibility', () => { |
92 | 100 | }); |
93 | 101 |
|
94 | 102 | test('should hide text labels when sidebar is collapsed in icon mode', async ({ page }) => { |
95 | | - await page.goto(`${CONSOLE_BASE}/`); |
96 | | - await waitForReactMount(page); |
| 103 | + await registerAndLogin(page); |
97 | 104 |
|
98 | 105 | const sidebar = page.locator('[data-sidebar="sidebar"]').first(); |
99 | | - await expect(sidebar).toBeVisible(); |
| 106 | + await expect(sidebar).toBeVisible({ timeout: SIDEBAR_VISIBLE_TIMEOUT }); |
100 | 107 |
|
101 | 108 | const toggleButton = page.locator('[data-sidebar="trigger"]').first(); |
102 | | - await expect(toggleButton).toBeVisible(); |
| 109 | + await expect(toggleButton).toBeVisible({ timeout: SIDEBAR_VISIBLE_TIMEOUT }); |
103 | 110 |
|
104 | 111 | const sidebarGroup = page.locator('.group[data-collapsible="icon"]').first(); |
105 | 112 |
|
|
0 commit comments