|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +test.describe('Schema Tabs', () => { |
| 4 | + test('defaults to examples tab on load without adding query parameter', |
| 5 | + async ({ page }) => { |
| 6 | + await page.goto('/test/schemas/string'); |
| 7 | + |
| 8 | + // The examples tab button should be active |
| 9 | + const examplesTab = page.locator( |
| 10 | + '[data-sourcemeta-ui-tab-target="examples"]'); |
| 11 | + await expect(examplesTab).toHaveClass(/active/); |
| 12 | + |
| 13 | + // The examples panel should be visible |
| 14 | + const examplesPanel = page.locator( |
| 15 | + '[data-sourcemeta-ui-tab-id="examples"]'); |
| 16 | + await expect(examplesPanel).not.toHaveClass(/d-none/); |
| 17 | + |
| 18 | + // Other panels should be hidden |
| 19 | + const dependenciesPanel = page.locator( |
| 20 | + '[data-sourcemeta-ui-tab-id="dependencies"]'); |
| 21 | + await expect(dependenciesPanel).toHaveClass(/d-none/); |
| 22 | + const healthPanel = page.locator( |
| 23 | + '[data-sourcemeta-ui-tab-id="health"]'); |
| 24 | + await expect(healthPanel).toHaveClass(/d-none/); |
| 25 | + |
| 26 | + // The URL should NOT have a tab query parameter |
| 27 | + expect(page.url()).not.toContain('tab='); |
| 28 | + }); |
| 29 | + |
| 30 | + test('clicking a tab updates the query parameter and panel visibility', |
| 31 | + async ({ page }) => { |
| 32 | + await page.goto('/test/schemas/string'); |
| 33 | + |
| 34 | + // Wait for the default tab to be active |
| 35 | + const examplesTab = page.locator( |
| 36 | + '[data-sourcemeta-ui-tab-target="examples"]'); |
| 37 | + await expect(examplesTab).toHaveClass(/active/); |
| 38 | + |
| 39 | + // Click on the dependencies tab |
| 40 | + const dependenciesTab = page.locator( |
| 41 | + '[data-sourcemeta-ui-tab-target="dependencies"]'); |
| 42 | + await dependenciesTab.click(); |
| 43 | + |
| 44 | + // Query parameter should update |
| 45 | + await expect(page).toHaveURL(/tab=dependencies/); |
| 46 | + |
| 47 | + // The dependencies tab should be active, others not |
| 48 | + await expect(dependenciesTab).toHaveClass(/active/); |
| 49 | + await expect(examplesTab).not.toHaveClass(/active/); |
| 50 | + |
| 51 | + // The dependencies panel should be visible, others hidden |
| 52 | + const dependenciesPanel = page.locator( |
| 53 | + '[data-sourcemeta-ui-tab-id="dependencies"]'); |
| 54 | + await expect(dependenciesPanel).not.toHaveClass(/d-none/); |
| 55 | + const examplesPanel = page.locator( |
| 56 | + '[data-sourcemeta-ui-tab-id="examples"]'); |
| 57 | + await expect(examplesPanel).toHaveClass(/d-none/); |
| 58 | + |
| 59 | + // Click on the health tab |
| 60 | + const healthTab = page.locator( |
| 61 | + '[data-sourcemeta-ui-tab-target="health"]'); |
| 62 | + await healthTab.click(); |
| 63 | + |
| 64 | + await expect(page).toHaveURL(/tab=health/); |
| 65 | + await expect(healthTab).toHaveClass(/active/); |
| 66 | + await expect(dependenciesTab).not.toHaveClass(/active/); |
| 67 | + const healthPanel = page.locator( |
| 68 | + '[data-sourcemeta-ui-tab-id="health"]'); |
| 69 | + await expect(healthPanel).not.toHaveClass(/d-none/); |
| 70 | + await expect(dependenciesPanel).toHaveClass(/d-none/); |
| 71 | + }); |
| 72 | + |
| 73 | + test('clicking back to the first tab also sets the query parameter', |
| 74 | + async ({ page }) => { |
| 75 | + await page.goto('/test/schemas/string'); |
| 76 | + |
| 77 | + const examplesTab = page.locator( |
| 78 | + '[data-sourcemeta-ui-tab-target="examples"]'); |
| 79 | + await expect(examplesTab).toHaveClass(/active/); |
| 80 | + |
| 81 | + // Click away from the default tab |
| 82 | + const dependenciesTab = page.locator( |
| 83 | + '[data-sourcemeta-ui-tab-target="dependencies"]'); |
| 84 | + await dependenciesTab.click(); |
| 85 | + await expect(page).toHaveURL(/tab=dependencies/); |
| 86 | + |
| 87 | + // Click back to examples |
| 88 | + await examplesTab.click(); |
| 89 | + |
| 90 | + // Now the query parameter should be present |
| 91 | + await expect(page).toHaveURL(/tab=examples/); |
| 92 | + await expect(examplesTab).toHaveClass(/active/); |
| 93 | + await expect(dependenciesTab).not.toHaveClass(/active/); |
| 94 | + }); |
| 95 | + |
| 96 | + test('navigating with a tab query parameter selects that tab', |
| 97 | + async ({ page }) => { |
| 98 | + await page.goto('/test/schemas/string?tab=health'); |
| 99 | + |
| 100 | + // The health tab should be active |
| 101 | + const healthTab = page.locator( |
| 102 | + '[data-sourcemeta-ui-tab-target="health"]'); |
| 103 | + await expect(healthTab).toHaveClass(/active/); |
| 104 | + |
| 105 | + // The health panel should be visible |
| 106 | + const healthPanel = page.locator( |
| 107 | + '[data-sourcemeta-ui-tab-id="health"]'); |
| 108 | + await expect(healthPanel).not.toHaveClass(/d-none/); |
| 109 | + |
| 110 | + // The URL should keep the tab parameter |
| 111 | + await expect(page).toHaveURL(/tab=health/); |
| 112 | + |
| 113 | + // Other tabs and panels should not be active/visible |
| 114 | + const examplesTab = page.locator( |
| 115 | + '[data-sourcemeta-ui-tab-target="examples"]'); |
| 116 | + await expect(examplesTab).not.toHaveClass(/active/); |
| 117 | + const examplesPanel = page.locator( |
| 118 | + '[data-sourcemeta-ui-tab-id="examples"]'); |
| 119 | + await expect(examplesPanel).toHaveClass(/d-none/); |
| 120 | + }); |
| 121 | +}); |
0 commit comments