import { expect, Locator } from '@playwright/test'; import { test, E2EPage } from '@stencil/playwright'; test.describe('ontario-summary-list', () => { const renderHost = async (page: E2EPage, html: string): Promise => { await page.setContent(html); await page.waitForChanges(); const host = page.locator('ontario-summary-list').last(); await expect(host).toBeAttached(); await expect(host).toHaveClass(/hydrated/); return host; }; test('renders the caption as an h3 heading by default', async ({ page }) => { const host = await renderHost(page, ``); const heading = host.locator('h3.ontario-summary-list__heading'); await expect(heading).toBeAttached(); await expect(heading).toHaveText('Personal information'); }); test('renders the dl container', async ({ page }) => { const host = await renderHost(page, ``); const container = host.locator('dl.ontario-summary-list__container'); await expect(container).toBeAttached(); }); test('renders default layout variant without fullWidth class', async ({ page }) => { const host = await renderHost(page, ``); const defaultWrapper = host.locator('.ontario-summary-list'); await expect(defaultWrapper).toBeAttached(); await expect(defaultWrapper).not.toContainClass('summary-list-full-width'); }); test('renders fullWidth layout variant without errors', async ({ page }) => { const host = await renderHost( page, `
Address
111 Wellington St.
`, ); const fullWidthWrapper = host.locator('.ontario-summary-list'); await expect(fullWidthWrapper).toContainClass('summary-list-full-width'); }); test('supports keyboard tab order and enter activation through slotted change links', async ({ page }) => { const host = await renderHost( page, ` Change section
Name
Jane Doe
Change name
Email
jane@example.com
Change email
`, ); const summaryChangeLink = host.locator('a[slot="caption-action"]'); const rowChangeLink1 = host.locator('#row-change-link-1'); const rowChangeLink2 = host.locator('#row-change-link-2'); await expect(summaryChangeLink).toBeAttached(); await expect(rowChangeLink1).toBeAttached(); await expect(rowChangeLink2).toBeAttached(); await page.keyboard.press('Tab'); await expect(summaryChangeLink).toBeFocused(); await page.keyboard.press('Tab'); await expect(rowChangeLink1).toBeFocused(); await page.keyboard.press('Tab'); await expect(rowChangeLink2).toBeFocused(); await page.keyboard.press('Enter'); await expect(page).toHaveURL(/#row-2$/); }); test('renders localized generated action link text for English', async ({ page }) => { const host = await renderHost( page, ``, ); const enLink = host.locator('.ontario-summary-list__change-button'); await expect(enLink).toContainText('Change'); await expect(enLink).toContainText('your answer for:'); }); test('renders localized generated action link text for French', async ({ page }) => { const host = await renderHost( page, ``, ); const frLink = host.locator('.ontario-summary-list__change-button'); await expect(frLink).toContainText('Modifier'); await expect(frLink).toContainText(/votre réponse pour\s*:/); }); test('renders French slotted content with no generated English text bleed-through', async ({ page }) => { const host = await renderHost( page, ` Modifier
Nom
Dupont
Modifier le nom
`, ); await expect(host).toContainText('Renseignements personnels'); await expect(host).toContainText('Nom'); await expect(host).toContainText('Modifier'); await expect(host).not.toContainText('Change'); await expect(host).not.toContainText('your answer for:'); }); test('has expected accessible heading and action link names for default variant', async ({ page }) => { const host = await renderHost( page, `
Name
Jane Doe
`, ); await expect(host.getByRole('heading', { name: 'Personal information' })).toBeVisible(); await expect(host.getByRole('link', { name: /Change/ })).toBeVisible(); }); test('has expected accessible heading and action link names for fullWidth variant', async ({ page }) => { const host = await renderHost( page, `
Address
111 Wellington St.
`, ); await expect(host.getByRole('heading', { name: 'Personal information' })).toBeVisible(); await expect(host.getByRole('link', { name: /Change/ })).toBeVisible(); }); test('applies focus ring styles to slotted links on keyboard focus', async ({ page }) => { const host = await renderHost( page, ` Change section `, ); const summaryChangeLink = host.locator('a[slot="caption-action"]'); await expect(summaryChangeLink).toBeAttached(); await page.keyboard.press('Tab'); await expect(summaryChangeLink).toBeFocused(); const focusedStyles = await summaryChangeLink.evaluate((el) => { const styles = window.getComputedStyle(el as HTMLElement); return { outlineStyle: styles.outlineStyle, outlineWidth: styles.outlineWidth, boxShadow: styles.boxShadow, }; }); const hasOutline = focusedStyles.outlineStyle !== 'none' && focusedStyles.outlineWidth !== '0px'; const hasBoxShadow = focusedStyles.boxShadow !== 'none'; expect(hasOutline || hasBoxShadow).toBe(true); }); });