|
| 1 | +import { expect } from '@playwright/test'; |
| 2 | +import { configs, test } from '@utils/test/playwright'; |
| 3 | + |
| 4 | +/** |
| 5 | + * Verifies that the focused state on tab buttons |
| 6 | + * uses a dark-appropriate background in the dark palette, |
| 7 | + * not the light-mode fallback (#e0e0e0) |
| 8 | + */ |
| 9 | +configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => { |
| 10 | + test.describe(title('tabs: focused state in dark palette'), () => { |
| 11 | + test.beforeEach(async ({ page }) => { |
| 12 | + await page.goto('/src/components/tabs/test/basic?ionic:palette=dark', config); |
| 13 | + |
| 14 | + const tabButton = page.locator('.e2eTabOneButton'); |
| 15 | + await tabButton.evaluate((el: HTMLElement) => { |
| 16 | + // focus-visible.ts only adds ion-focused in keyboard mode; trigger it first |
| 17 | + document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Tab', bubbles: true })); |
| 18 | + // the host has no tabindex; focus the actual <a> inside shadow DOM |
| 19 | + (el.shadowRoot?.querySelector('a') as HTMLElement)?.focus(); |
| 20 | + }); |
| 21 | + await page.waitForChanges(); |
| 22 | + }); |
| 23 | + |
| 24 | + test('should not have visual regressions for focused tab button', async ({ page }) => { |
| 25 | + await expect(page.locator('.e2eTabOneButton')).toHaveClass(/ion-focused/); |
| 26 | + await expect(page.locator('ion-tab-bar')).toHaveScreenshot(screenshot('tab-bar-focused-dark')); |
| 27 | + }); |
| 28 | + |
| 29 | + test('focused tab button should not use light-mode fallback color', async ({ page }) => { |
| 30 | + const bgColor = await page.locator('.e2eTabOneButton').evaluate((el: HTMLElement) => |
| 31 | + window.getComputedStyle(el, '::after').backgroundColor |
| 32 | + ); |
| 33 | + // #e0e0e0 (rgb(224, 224, 224)) is the light-mode fallback from get-color-shade(#fff) |
| 34 | + expect(bgColor).not.toBe('rgb(224, 224, 224)'); |
| 35 | + }); |
| 36 | + }); |
| 37 | +}); |
0 commit comments