Skip to content

Add comprehensive tests for number input#16

Merged
47vigen merged 7 commits intomainfrom
claude/add-number-input-tests-e5KFf
Apr 5, 2026
Merged

Add comprehensive tests for number input#16
47vigen merged 7 commits intomainfrom
claude/add-number-input-tests-e5KFf

Conversation

@47vigen
Copy link
Copy Markdown
Owner

@47vigen 47vigen commented Apr 5, 2026

claude added 7 commits April 5, 2026 10:07
- useNumberFieldState.interactions.test.ts: 31 unit tests covering
  defaultValue init, decimal typing, negative input, compact notation,
  reset-then-retype, and update-containing-value scenarios
- NumberField.interactions.test.tsx: 46 component tests (RTL + userEvent)
  covering all user interactions, keyboard shortcuts, button clicks,
  paste handling, and uncontrolled defaultValue behavior
- e2e/number-input.spec.tsx + e2e/components/number-input-field.tsx:
  Playwright CT tests for real-browser verification of all key scenarios

All 414 unit/component tests pass.

https://claude.ai/code/session_01S39pCHQs2PyrVnNGMimD1h
- Remove duplicate mount() call in defaultValue integer test
- Replace page.evaluate(document.querySelector) with input.evaluate()
  for paste tests — CT components render inside an iframe so page-level
  querySelector cannot find them; locator.evaluate() runs in the correct
  iframe context
- Remove unused `page` fixture from blur test

https://claude.ai/code/session_01S39pCHQs2PyrVnNGMimD1h
…rowser paste

Firefox silently ignores DataTransfer.setData() calls made outside native
event handlers, causing paste tests to fail. Replace DataTransfer usage with
Object.defineProperty to mock clipboardData.getData directly on the event
object — this is cross-browser safe and matches what React's onPaste handler
reads (e.clipboardData.getData("text/plain")).

https://claude.ai/code/session_01S39pCHQs2PyrVnNGMimD1h
Cross-browser paste event simulation in Playwright CT is unreliable:
DataTransfer.setData() is restricted in Firefox outside native events,
Object.defineProperty on ClipboardEvent is non-configurable in Firefox,
and Event object extensibility differs across engines.

Paste behavior is fully covered by NumberField.interactions.test.tsx
using @testing-library/user-event which handles this reliably in jsdom.

https://claude.ai/code/session_01S39pCHQs2PyrVnNGMimD1h
Fixes decimal input UX bug (useNumberField.ts):
When a formatted input already shows a decimal separator (e.g. "1.00"
with fixedDecimalScale), typing the decimal key now moves the cursor to
just after it instead of inserting a duplicate "." that invalidates the
value and clears the field on blur. Only matches localeInfo.decimalSeparator
(not "." universally) so comma-decimal locales (de-DE etc.) are unaffected.

Hardens E2E tests for Firefox (number-input.spec.tsx):
- Replace selectText()+press("Backspace") with fill("") — more reliable
  cross-browser for clearing a controlled input
- Replace selectText()+pressSequentially() with fill("")+pressSequentially()
- Relax compact notation assertions to regex (/K/i, /M/i) since Firefox ICU
  may emit different Unicode spacing characters than Chrome/WebKit

https://claude.ai/code/session_01S39pCHQs2PyrVnNGMimD1h
Replace all snapshot-style expect(await locator.inputValue()).toBe(X)
assertions with Playwright's auto-retrying locator assertions:
  - expect(input).toHaveValue(X)
  - expect(input).toHaveAttribute("aria-valuenow", X)
  - expect(input).not.toHaveAttribute("aria-valuenow")

Snapshot assertions read the DOM once without retrying. Firefox processes
React state updates slightly slower than Chromium/WebKit, so the DOM may
not yet reflect the new value when the assertion fires. Locator assertions
auto-retry up to the configured timeout, eliminating the race condition.

Also adds delay: 50 to pressSequentially calls to give React time to flush
state between keystrokes — matching the pattern used in rtl-cursor.spec.tsx.

https://claude.ai/code/session_01S39pCHQs2PyrVnNGMimD1h
press("Tab") in Firefox CT does not reliably trigger the blur event when
the next focusable element (e.g. a disabled Increment button with no value
set) is not in the tab order, causing focus to escape the iframe without
firing blur. This caused "blur on intermediate '23.'" tests to timeout.

Using input.evaluate(el => el.blur()) calls the DOM blur() method directly,
which always dispatches the blur event regardless of tab order or iframe
focus behavior.

https://claude.ai/code/session_01S39pCHQs2PyrVnNGMimD1h
@47vigen 47vigen merged commit a5b4e37 into main Apr 5, 2026
16 checks passed
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.

2 participants