Skip to content

Improve test reliability with semantic selectors and data attributes#124

Merged
markmur merged 1 commit into
mainfrom
claude/resilient-ui-tests-tpbdq
Apr 12, 2026
Merged

Improve test reliability with semantic selectors and data attributes#124
markmur merged 1 commit into
mainfrom
claude/resilient-ui-tests-tpbdq

Conversation

@markmur

@markmur markmur commented Apr 12, 2026

Copy link
Copy Markdown
Owner

Summary

This PR improves test reliability and maintainability by replacing fragile CSS selectors and class-based queries with semantic HTML attributes, test IDs, and accessible queries. The changes span both e2e tests and unit tests, making them more resilient to styling changes.

Key Changes

E2E Tests (e2e/app.spec.ts)

  • Replaced animation class selectors (.strike-animated) with data-completed attribute checks for task completion verification
  • Updated toast dismissal check from waitForDismiss() to expect().toBeHidden() for better reliability
  • Replaced complex CSS position selectors with getByTestId() for settings and completed panels
  • Updated drag handle selector from .cursor-grab class to data-testid="drag-handle"
  • Simplified panel CSS assertions by extracting locator to variable for reuse

Unit Tests

  • Task.spec.tsx: Updated selectors to use aria-label attributes instead of data-tooltip-content and class names
  • ToggleButton.spec.tsx: Changed from testing implementation details (CSS classes) to testing accessible behavior (aria-label)
  • Toast.spec.tsx: Migrated from document.querySelector to screen queries for better testing practices
  • List.spec.tsx: Updated drag handle selector to use data-testid instead of class name

Source Code Changes

  • Added data-testid attributes to key elements:
    • task-title on task title display element
    • drag-handle on reorderable list handles
    • completed-panel and settings-panel on sidebar panels
    • header-date on header date element
  • Added aria-label attributes to form inputs:
    • "Task title" on textarea input
  • Added data-completed attribute to task title element for completion state tracking
  • Improved semantic HTML with getByRole() queries in e2e tests

Benefits

  • Tests are now decoupled from CSS styling changes
  • Improved accessibility by using semantic selectors
  • Better test maintainability with explicit test IDs
  • More reliable assertions using accessible queries
  • Reduced brittle selectors based on implementation details

https://claude.ai/code/session_01ArE4Fhc46FgTh63NCGPpeS

Replace CSS class selectors (.strike-animated, .cursor-grab, .inline.font-semibold),
inline style queries, tooltip-content attributes, and structural DOM selectors with
semantic alternatives (aria-label, role, data-testid, data-completed). Add test hook
attributes to Task, List, Header, and Todo components. Update E2E regions, E2E specs,
and unit tests to use the new resilient selectors.

https://claude.ai/code/session_01ArE4Fhc46FgTh63NCGPpeS
@netlify

netlify Bot commented Apr 12, 2026

Copy link
Copy Markdown

Deploy Preview for what-todo-web ready!

Name Link
🔨 Latest commit cde64ff
🔍 Latest deploy log https://app.netlify.com/projects/what-todo-web/deploys/69dbaf7eaffe9e0008c91c0a
😎 Deploy Preview https://deploy-preview-124--what-todo-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@markmur markmur merged commit fa3713a into main Apr 12, 2026
8 checks passed
@markmur markmur deleted the claude/resilient-ui-tests-tpbdq branch April 12, 2026 14:46
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