-
Notifications
You must be signed in to change notification settings - Fork 5
test: add Playwright coverage and test ids for CpsTooltipDirective #841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fateeand
merged 4 commits into
master
from
811-cover-tooltip-directive-with-playwright-tests
Aug 13, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5671270
test: add Playwright coverage and test ids for CpsTooltipDirective
fateeand 6002cf2
address feedback
fateeand 087072c
Merge branch 'master' into 811-cover-tooltip-directive-with-playwrigh…
fateeand 0b7625b
Merge branch 'master' into 811-cover-tooltip-directive-with-playwrigh…
fateeand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| import { test, expect, type Page, type Locator } from '@playwright/test'; | ||
|
|
||
| function button(page: Page, testId: string): Locator { | ||
| return page.getByTestId(testId); | ||
| } | ||
|
|
||
| function tooltip(page: Page): Locator { | ||
| return page.getByTestId('cps-tooltip'); | ||
| } | ||
|
|
||
| function gapBetween( | ||
| targetBox: { x: number; y: number; width: number; height: number }, | ||
| tooltipBox: { x: number; y: number; width: number; height: number } | ||
| ): number { | ||
| const horizontalOverlap = | ||
| tooltipBox.x < targetBox.x + targetBox.width && | ||
| tooltipBox.x + tooltipBox.width > targetBox.x; | ||
| if (!horizontalOverlap) { | ||
| return tooltipBox.x >= targetBox.x + targetBox.width | ||
| ? tooltipBox.x - (targetBox.x + targetBox.width) | ||
| : targetBox.x - (tooltipBox.x + tooltipBox.width); | ||
| } | ||
| return tooltipBox.y >= targetBox.y + targetBox.height | ||
| ? tooltipBox.y - (targetBox.y + targetBox.height) | ||
| : targetBox.y - (tooltipBox.y + tooltipBox.height); | ||
| } | ||
|
|
||
| test.describe('cps-tooltip', () => { | ||
| test.beforeEach(async ({ page }) => { | ||
| await page.goto('/tooltip'); | ||
| }); | ||
|
|
||
| test.describe('Real click-trigger isolation from hover', () => { | ||
| test('hovering does nothing, clicking shows the real tooltip', async ({ | ||
| page | ||
| }) => { | ||
| const target = button(page, 'click-open-tooltip'); | ||
|
|
||
| await target.hover(); | ||
| await expect(tooltip(page)).toHaveCount(0); | ||
|
|
||
| await target.click(); | ||
| await expect(tooltip(page)).toBeVisible(); | ||
| await expect(tooltip(page)).toHaveText('Triggered on click'); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Real focus-only-trigger isolation from hover', () => { | ||
| test('hovering the target does not show the tooltip', async ({ page }) => { | ||
| const target = button(page, 'focus-only-tooltip'); | ||
|
|
||
| await target.hover(); | ||
| await expect(tooltip(page)).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('real keyboard focus shows the real tooltip', async ({ page }) => { | ||
| const target = button(page, 'focus-only-tooltip'); | ||
| const innerButton = target.getByTestId('cps-button'); | ||
|
|
||
| await innerButton.focus(); | ||
| const ownTooltip = page.getByRole('tooltip', { | ||
| name: 'Triggered on focus only' | ||
| }); | ||
| await expect(ownTooltip).toBeVisible(); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Real custom open-delay timing', () => { | ||
| test('the tooltip is not visible immediately after hover but appears within the configured delay', async ({ | ||
| page | ||
| }) => { | ||
| const target = button(page, 'open-delay-tooltip'); | ||
|
|
||
| await target.hover(); | ||
| await expect(tooltip(page)).not.toBeVisible({ timeout: 200 }); | ||
| await expect(tooltip(page)).toBeVisible({ timeout: 1500 }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Real custom close-delay timing', () => { | ||
| test('the tooltip stays visible briefly after mouse-leave before disappearing', async ({ | ||
| page | ||
| }) => { | ||
| const target = button(page, 'close-delay-tooltip'); | ||
|
|
||
| await target.hover(); | ||
| await expect(tooltip(page)).toBeVisible(); | ||
|
|
||
| await page.mouse.move(0, 0); | ||
| await expect(tooltip(page)).toBeVisible({ timeout: 200 }); | ||
| await expect(tooltip(page)).toHaveCount(0, { timeout: 1500 }); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('tooltipDisabled renders no popup at all', () => { | ||
| test('hovering a disabled tooltip target creates no real tooltip node', async ({ | ||
| page | ||
| }) => { | ||
| const target = button(page, 'disabled-state-tooltip'); | ||
|
|
||
| await target.hover(); | ||
| await expect(tooltip(page)).toHaveCount(0); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Real tooltipMaxWidth enforcement', () => { | ||
| test('the real rendered tooltip width respects the configured max width', async ({ | ||
| page | ||
| }) => { | ||
| const target = button(page, 'custom-offset-tooltip'); | ||
|
|
||
| await target.hover(); | ||
| const box = await tooltip(page).boundingBox(); | ||
| if (!box) throw new Error('boundingBox() returned null'); | ||
|
|
||
| const maxWidthPx = await page.evaluate( | ||
| () => | ||
| parseFloat(getComputedStyle(document.documentElement).fontSize) * 8 | ||
| ); | ||
| expect(box.width).toBeLessThanOrEqual(maxWidthPx + 1); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Real tooltipOffset distance', () => { | ||
| test('the real gap between target and tooltip matches the configured offset', async ({ | ||
| page | ||
| }) => { | ||
| const target = button(page, 'custom-offset-tooltip'); | ||
|
|
||
| await target.hover(); | ||
| const targetBox = await target.boundingBox(); | ||
| const tooltipBox = await tooltip(page).boundingBox(); | ||
| if (!targetBox || !tooltipBox) | ||
| throw new Error('boundingBox() returned null'); | ||
|
|
||
| const rootFontSizePx = await page.evaluate(() => | ||
| parseFloat(getComputedStyle(document.documentElement).fontSize) | ||
| ); | ||
| const gap = gapBetween(targetBox, tooltipBox); | ||
| expect(gap).toBeGreaterThan(rootFontSizePx * 1.5); | ||
| expect(gap).toBeLessThan(rootFontSizePx * 2.5); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Real click-trigger aria-live announce', () => { | ||
| test('clicking creates a real self-removing aria-live region with the tooltip text', async ({ | ||
| page | ||
| }) => { | ||
| const target = button(page, 'click-open-tooltip'); | ||
|
|
||
| await target.click(); | ||
| const announce = page.locator('.cps-sr-only[aria-live="assertive"]'); | ||
| await expect(announce).toHaveText('Triggered on click'); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('Real destroy on scroll and resize', () => { | ||
| test('a real scroll event immediately removes the tooltip with no lingering node', async ({ | ||
| page | ||
| }) => { | ||
| const target = button(page, 'bottom-position-tooltip'); | ||
|
|
||
| await target.hover(); | ||
| await expect(tooltip(page)).toBeVisible(); | ||
|
|
||
| await page.evaluate(() => window.dispatchEvent(new Event('scroll'))); | ||
|
|
||
| await expect(tooltip(page)).toHaveCount(0); | ||
| }); | ||
|
|
||
| test('a real window resize immediately removes the tooltip with no lingering node', async ({ | ||
| page | ||
| }) => { | ||
| const target = button(page, 'bottom-position-tooltip'); | ||
| const originalSize = page.viewportSize(); | ||
|
|
||
| await target.hover(); | ||
| await expect(tooltip(page)).toBeVisible(); | ||
|
|
||
| await page.setViewportSize({ | ||
| width: (originalSize?.width ?? 1280) - 10, | ||
| height: originalSize?.height ?? 720 | ||
| }); | ||
|
|
||
| await expect(tooltip(page)).toHaveCount(0); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
projects/composition/src/app/pages/tooltip-page/tooltip-page.examples.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,83 +1,104 @@ | ||
| export const tooltipExamples: Record<string, { html: string; ts?: string }> = { | ||
| tooltipPositions: { | ||
| html: ` | ||
| <cps-button | ||
| cpsTooltip="Bottom tooltip" | ||
| tooltipPosition="bottom" | ||
| label="Bottom tooltip"> | ||
| </cps-button> | ||
| <cps-button | ||
| cpsTooltip="Left tooltip" | ||
| tooltipPosition="left" | ||
| label="Left tooltip"> | ||
| </cps-button> | ||
| <cps-button | ||
| cpsTooltip="Right tooltip" | ||
| tooltipPosition="right" | ||
| label="Right tooltip"> | ||
| </cps-button> | ||
| <cps-button | ||
| cpsTooltip="Top tooltip" | ||
| tooltipPosition="top" | ||
| label="Top tooltip"> | ||
| </cps-button>` | ||
| }, | ||
|
|
||
| openingMethods: { | ||
| html: ` | ||
| <cps-button | ||
| label="Open on hover" | ||
| tooltipPosition="bottom" | ||
| cpsTooltip="Triggered on hover" | ||
| tooltipOpenOn="hover"> | ||
| </cps-button> | ||
| <cps-button | ||
| label="Open on click" | ||
| tooltipPosition="right" | ||
| cpsTooltip="Triggered on click" | ||
| tooltipOpenOn="click"> | ||
| </cps-button>` | ||
| }, | ||
|
|
||
| focusOnlyTooltip: { | ||
| html: ` | ||
| <cps-button | ||
| label="Open on focus only" | ||
| tooltipPosition="bottom" | ||
| cpsTooltip="Triggered on focus only" | ||
| tooltipOpenOn="focus"> | ||
| </cps-button>` | ||
| }, | ||
|
|
||
| openCloseDelays: { | ||
| html: ` | ||
| <cps-button | ||
| cpsTooltip="1 second open delay" | ||
| label="Open delay" | ||
| tooltipPosition="bottom" | ||
| [tooltipOpenDelay]="1000"> | ||
| </cps-button> | ||
| <cps-button | ||
| cpsTooltip="1 second close delay" | ||
| label="Close delay" | ||
| tooltipPosition="right" | ||
| [tooltipCloseDelay]="1000"> | ||
| </cps-button>` | ||
| }, | ||
|
|
||
| persistentHtmlTooltip: { | ||
| html: ` | ||
| <cps-button | ||
| cpsTooltip="<span class='ttip-hdr'>Follow the link</span> <a href='https://www.google.com/' target='_blank' rel='noopener noreferrer'>Google</a> <a href='https://www.bing.com/' target='_blank' rel='noopener noreferrer'>Bing</a>" | ||
| tooltipPosition="right" | ||
| tooltipContentClass="my-tooltip-content" | ||
| label="Tooltip with clickable content" | ||
| [tooltipPersistent]="true"> | ||
| </cps-button>` | ||
| }, | ||
|
|
||
| disabledTooltipState: { | ||
| html: ` | ||
| <cps-button | ||
| tooltipPosition="bottom" | ||
| [label]="ttipEnabled ? 'Enabled tooltip' : 'Disabled tooltip'" | ||
| [tooltipDisabled]="!ttipEnabled" | ||
| cpsTooltip="<span><strong>Some bold text</strong></span>"> | ||
| </cps-button> | ||
| <cps-checkbox | ||
| [(ngModel)]="ttipEnabled" | ||
| [label]="ttipEnabled ? 'Deactivate' : 'Activate'"></cps-checkbox>`, | ||
| ts: ` | ||
| ttipEnabled = false;` | ||
| }, | ||
|
|
||
| customOffsetMaxWidthTooltip: { | ||
| html: ` | ||
| <cps-button | ||
| cpsTooltip="A longer tooltip message to demonstrate a constrained max width" | ||
| tooltipPosition="right" | ||
| [tooltipOffset]="'2rem'" | ||
| [tooltipMaxWidth]="'8rem'" | ||
| label="Custom offset & max width"> | ||
| </cps-button>` | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.