fix(testkit): fix e2e locators broken by vibe4 changes#3333
fix(testkit): fix e2e locators broken by vibe4 changes#3333rivka-ungar merged 5 commits intovibe4from
Conversation
Test locators used exact data-testid matches, but Overview stories pass explicit id props causing getTestId() to append a suffix (e.g. "button-group_overview-button-group" instead of "button-group"). Switch to starts-with selectors (^=) so locators work regardless of id. For Dropdown, the old .dropdown-stories-styles_spacing CSS module class was removed when the component was rewritten in vibe4. Update the locator to use [data-vibe="Dropdown"] and add searchable/inputAriaLabel to the Overview story so the testkit's open/close and aria-label tests work. These bugs pre-existed on master but were never caught because test:changed only runs tests for components modified since master. The vibe4 batch of breaking changes touched all affected components, exposing the issues. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Review Summary by QodoFix testkit e2e locators for vibe4 breaking changes
WalkthroughsDescription• Fix 9 testkit e2e test locators broken by vibe4 component changes • Switch from exact to starts-with data-testid selectors for robustness • Update Dropdown story with searchable and inputAriaLabel props • Replace removed CSS class with data-vibe attribute selector Diagramflowchart LR
A["Exact data-testid selectors"] -->|"Switch to starts-with ^="| B["Flexible locators"]
C["Removed CSS class"] -->|"Use data-vibe attribute"| D["Dropdown locator"]
E["Missing story props"] -->|"Add searchable & inputAriaLabel"| F["Working Dropdown tests"]
B --> G["All 9 components fixed"]
D --> G
F --> G
File Changes1. packages/testkit/__tests__/ButtonGroup.test.ts
|
Code Review by Qodo
1.
|
| let frame: FrameLocator; | ||
| let buttonGroup: ButtonGroup; | ||
| const buttonGroupLocator = 'div[data-testid="button-group"]'; | ||
| const buttonGroupLocator = 'div[data-testid^="button-group"]'; |
There was a problem hiding this comment.
1. Hard-coded test id selectors 📘 Rule violation ⛯ Reliability
Several updated Playwright tests use string-literal data-testid/data-vibe selectors (including the ad-hoc ^= prefix match) instead of the repository’s centralized test-id constants and getTestId() pattern. This violates the established test-id convention and can lead to inconsistent, less precise selectors across the monorepo.
Agent Prompt
## Issue description
Several updated testkit E2E tests build selectors using string-literal `data-testid`/`data-vibe` values (and `data-testid^=` prefix matching) rather than the repo’s centralized constants and helper (`getTestId`). This breaks the compliance requirement for consistent, constants-based test-id patterns.
## Issue Context
The repository provides `ComponentDefaultTestId` / `ComponentVibeId` enums and a `getTestId(elementType, id)` helper to generate standardized `data-testid` values, including the `_<id>` suffix convention.
## Fix Focus Areas
- packages/testkit/__tests__/ButtonGroup.test.ts[1-8]
- packages/testkit/__tests__/Checkbox.test.ts[1-8]
- packages/testkit/__tests__/Link.test.ts[1-8]
- packages/testkit/__tests__/MenuButton.test.ts[1-11]
- packages/testkit/__tests__/RadioButton.test.ts[1-8]
- packages/testkit/__tests__/SplitButton.test.ts[1-11]
- packages/testkit/__tests__/Steps.test.ts[1-9]
- packages/testkit/__tests__/TextField.test.ts[1-9]
- packages/testkit/__tests__/Dropdown.test.ts[1-9] করা
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Extend the data-testid starts-with (^=) fix to Toast, Button, IconButton,
Loader, and TextArea — same root cause as the previous batch: stories pass
explicit id props, causing a suffix in getTestId() output.
Also fix the Checkbox testkit component:
- Use locator("input") instead of locator("div") so check()/uncheck()/
isChecked() target the actual <input type="checkbox">, not the visual div
- Update toBeChecked() assertions in the test to target the input directly
(Playwright throws "Not a checkbox or radio button" on <label> elements)
- Fix attribute retrieval test to read data-vibe from the root label, not
the inner div (which does not have that attribute)
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
Persistent review updated to latest commit 953694c |
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
Persistent review updated to latest commit db801c3 |
Checkbox: the hidden <input type="checkbox"> (replaced by custom CSS) is not visible to Playwright, so check()/uncheck() fail with a timeout. Click the outer <label> instead — it's visible and toggling it updates the input state. isChecked() still reads the input directly which works. Toast: data-testid^="toast" matches both the root toast element (toast_default-with-button) and the inner toast-content div (toast-content), causing a strict-mode violation. Use data-testid^="toast_" (underscore separator from getTestId) which only matches the root. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
Persistent review updated to latest commit 68bb28e |
…tests Instead of modifying the Overview story to add searchable/inputAriaLabel, point the Dropdown testkit to the existing Searchable story which already has the searchable prop set. Update the attribute test to check data-vibe on the root element instead of aria-label on the input. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
Persistent review updated to latest commit 2bde05f |
User description
Summary
Root Cause
Test locators used exact
data-testidmatches (e.g.[data-testid="button-group"]), but Overview stories pass explicitidprops. SincegetTestId(componentType, id)appends a suffix, the rendered attribute becomesbutton-group_overview-button-group— no match, 30s timeout.These bugs pre-existed on master but were never caught:
test:changedonly runs tests for components modified since master. The vibe4 batch of breaking changes touched all affected components simultaneously, exposing the issues.Dropdown had a separate issue: the old
.dropdown-stories-styles_spacingCSS module class was removed when the component was fully rewritten.Changes
Test locators — switched from exact
=to starts-with^=selectors:ButtonGroup,Checkbox,Link,RadioButton,SplitButton,Steps,MenuButton—data-testid^=TextField—#input→input[data-testid^="text-field"](story setsid="overview-textfield", not"input")Dropdown—.dropdown-stories-styles_spacing→[data-vibe="Dropdown"]Dropdown story — added
searchable: trueandinputAriaLabel: "Dropdown input"to Overview args so the testkit'sopen()/isDropdownOpen()andaria-labelattribute tests work with the new component.Test plan
🤖 Generated with Claude Code
PR Type
Bug fix, Tests
Description
Fix 14 testkit e2e locators broken by vibe4 component changes
data-testid=to starts-withdata-testid^=selectors[data-vibe="Dropdown"]attribute#inputID toinput[data-testid^="text-field"]Fix Checkbox testkit component to target actual input element
divtoinputfor check/uncheck operations.locator("input")Update Dropdown test story URL to searchable variant
Remove unused
BaseElementimports from Checkbox and Dropdown testsDiagram Walkthrough
File Walkthrough
16 files
Switch to starts-with data-testid selectorSwitch to starts-with data-testid selectorFix locator and assertions to target input elementUpdate locator to data-vibe attribute and simplify testSwitch to starts-with data-testid selectorSwitch to starts-with data-testid selectorSwitch to starts-with data-testid selectorSwitch to starts-with data-testid selectorSwitch to starts-with data-testid selectorSwitch to starts-with data-testid selectorSwitch to starts-with data-testid selectorSwitch to starts-with data-testid selectorUpdate locator from ID to data-testid selectorSwitch to starts-with data-testid selectorFix internal locator and check/uncheck operationsUpdate Dropdown story URL to searchable variant