Skip to content

test: add Playwright coverage and test ids for CpsInputComponent - #814

Open
fateeand wants to merge 1 commit into
masterfrom
784-cover-input-component-with-playwright-tests
Open

test: add Playwright coverage and test ids for CpsInputComponent#814
fateeand wants to merge 1 commit into
masterfrom
784-cover-input-component-with-playwright-tests

Conversation

@fateeand

Copy link
Copy Markdown
Collaborator

Summary

Added Playwright E2E coverage for CpsInputComponent

  • Real keyboard-vs-mouse focus detection: isKeyboardFocused (driving the .keyboard-focused CSS class / visible focus ring) is set from a real mousedown-before-focus vs. Tab-only-focus event-ordering distinction (onInputMousedown() sets a flag consumed by the very next onFocus()) - unprovable by JSDOM's direct method calls.
  • Native type="number" keystroke filtering: real browsers reject non-numeric keystrokes entirely, which JSDOM can't simulate. Found a genuinely surprising real-browser behavior while verifying this empirically: 'e' is a valid number-input character (scientific notation), and typing it after an incomplete number (e.g. 12 -> 12e) doesn't just get rejected — the browser clears the entire field the moment the intermediate value becomes syntactically invalid.
  • Action-button focus retention: both the clear button and the password-toggle button use (mousedown)="$event.preventDefault()" specifically to stop the browser's default focus-stealing behavior when clicked - neither button's click handler (onClear()/togglePassword()) explicitly calls .focus() back, so focus retention is proof the trick works, not an assumption. Also verifies focus() is synchronous (no waitForTimeout needed) after the clear button click, unlike the sibling focusElement() helper elsewhere in the codebase which wraps in a setTimeout.
  • valueToDisplay non-interactive display input: this swaps in a second <input> with zero event handlers and hard disabled+readonly.
  • Real ARIA id-relationships: aria-describedby only proves anything if it resolves to a real DOM node - Jest only regex-checks the attribute string format. Added two tests: a loading input's aria-describedby/hint relationship plus aria-busy+role="progressbar", and a real focus->blur cycle on an empty required field driving the component's own _checkErrors() to produce a real "Field is required" error wired into aria-describedby - a genuine browser event sequence, not a mocked NgControl.
  • Real keyboard reachability of the clickable prefix icon: confirms it's a real Tab stop. Deliberately not asserting the click fires prefixIconClicked - Angular's (keydown.enter)/(keydown.space) bindings are on the same node Jest already dispatches synthetic events against (not real-browser-exclusive), and observing the effect in the demo page means asserting on the composition page's own notification toast, which is composition-page logic, not the component's own behavior.

  • Added test ids to the component's template.

  • Added three examples ("Input with a display-only formatted value", "Input with hidden hint/error details", "Unlabeled input with an accessible name").


TODO: Merge with feat: add test ids to input component to generate a release


Release notes:

  • added Playwright E2E coverage for cps-input component
  • added test ids to cps-input component

Copilot AI review requested due to automatic review settings July 30, 2026 12:49
@fateeand fateeand linked an issue Jul 30, 2026 that may be closed by this pull request
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report for library

St.
Category Percentage Covered / Total
🟡 Statements 78.5% 6209/7910
🟡 Branches 68.01% 2864/4211
🟡 Functions 79.59% 1170/1470
🟡 Lines 79.56% 5805/7296

Test suite run success

2438 tests passing in 76 suites.

Report generated by 🧪jest coverage report action from 6875e52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves end-to-end testability and real-browser verification for CpsInputComponent by adding stable data-testid hooks, extending the composition input page with new examples, and introducing Playwright E2E coverage that validates behaviors not reliably provable in JSDOM.

Changes:

  • Added data-testid attributes throughout cps-input’s template to enable robust Playwright selectors.
  • Added new composition examples and wired them into the input composition page for demo + E2E targets.
  • Introduced a new Playwright spec covering focus modality behavior, native type="number" filtering, action-button focus retention, valueToDisplay non-interactivity, ARIA relationships, and keyboard reachability.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
projects/cps-ui-kit/src/lib/components/cps-input/cps-input.component.ts Uses type-only imports for IconType/iconSizeType (no runtime import impact).
projects/cps-ui-kit/src/lib/components/cps-input/cps-input.component.html Adds data-testid hooks to key internal elements (input, display input, buttons, hint/error, etc.).
projects/composition/src/app/pages/input-page/input-page.examples.ts Adds 3 new documented examples used by the composition input page.
projects/composition/src/app/pages/input-page/input-page.component.html Adds data-testid hooks to specific demo instances and renders the new examples.
playwright/cps-ui-kit/components/cps-input.spec.ts New Playwright E2E coverage for real-browser behaviors and accessibility relationships.

@github-actions

Copy link
Copy Markdown
Contributor

Playwright test results

passed  424 passed

Details

stats  424 tests across 13 suites
duration  14 minutes, 38 seconds
commit  6875e52
info  For details, download the Playwright report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cover Input component with Playwright tests

2 participants