|
| 1 | +const { test, expect } = require('@playwright/test'); |
| 2 | + |
| 3 | +test.describe('Mobile Navigation', () => { |
| 4 | + test('should toggle mobile menu when clicking menu button', async ({ page }) => { |
| 5 | + await page.goto('/'); |
| 6 | + |
| 7 | + // Verify we're in mobile view by checking if the menu button is visible |
| 8 | + const menuButton = page.locator('#menu-button'); |
| 9 | + await expect(menuButton).toBeVisible(); |
| 10 | + |
| 11 | + // Initially, the navigation should be hidden (not have nav-open class) |
| 12 | + const siteNav = page.locator('#site-nav'); |
| 13 | + await expect(siteNav).not.toHaveClass(/nav-open/); |
| 14 | + |
| 15 | + // Click the menu button to open the navigation |
| 16 | + await menuButton.click(); |
| 17 | + |
| 18 | + // After clicking, navigation should have nav-open class |
| 19 | + await expect(siteNav).toHaveClass(/nav-open/); |
| 20 | + |
| 21 | + // Menu button should also have nav-open class |
| 22 | + await expect(menuButton).toHaveClass(/nav-open/); |
| 23 | + |
| 24 | + // Menu button aria-pressed should be true |
| 25 | + await expect(menuButton).toHaveAttribute('aria-pressed', 'true'); |
| 26 | + |
| 27 | + // Click again to close |
| 28 | + await menuButton.click(); |
| 29 | + |
| 30 | + // Navigation should no longer have nav-open class |
| 31 | + await expect(siteNav).not.toHaveClass(/nav-open/); |
| 32 | + await expect(menuButton).not.toHaveClass(/nav-open/); |
| 33 | + await expect(menuButton).toHaveAttribute('aria-pressed', 'false'); |
| 34 | + }); |
| 35 | + |
| 36 | + test('should show navigation links when menu is open', async ({ page }) => { |
| 37 | + await page.goto('/'); |
| 38 | + |
| 39 | + const menuButton = page.locator('#menu-button'); |
| 40 | + const siteNav = page.locator('#site-nav'); |
| 41 | + |
| 42 | + // Initially, navigation links might be hidden/not visible in mobile view |
| 43 | + // Click to open |
| 44 | + await menuButton.click(); |
| 45 | + |
| 46 | + // Wait for navigation to be open |
| 47 | + await expect(siteNav).toHaveClass(/nav-open/); |
| 48 | + |
| 49 | + // Check that navigation links are accessible |
| 50 | + const navLinks = page.locator('#site-nav .nav-list-link'); |
| 51 | + const count = await navLinks.count(); |
| 52 | + expect(count).toBeGreaterThan(0); |
| 53 | + }); |
| 54 | +}); |
0 commit comments