Skip to content

feat(inspector): suggest role locator when duplicate test IDs have unique roles - #330

Merged
gmegidish merged 1 commit into
mainfrom
feat/inspector-role-for-duplicate-testids
Sep 18, 2026
Merged

gmegidish merged 1 commit into
mainfrom
feat/inspector-role-for-duplicate-testids

Conversation

@gmegidish

Copy link
Copy Markdown
Member

Summary

When several elements share a test ID (e.g. five getByTestId('PXGGridLayout-Info')), the inspector flagged them all as dup but still suggested the ambiguous locator.

Now, for each group of elements sharing a test ID: if every element in the group has a role locator (role + name) that matches nothing else in the tree, role becomes the primary locator for the whole group. The test ID stays listed as a secondary locator in the detail pane.

  • All or nothing per group: if any member has no role, or a role shared with any other element, the group keeps showing the test ID (and the dup badge).
  • Uniqueness is checked against the whole tree, not only within the group, so the promoted locator is never itself a duplicate.

Test plan

  • npm run lint
  • Inspector unit tests (5 new cases in locator-derivation.test.ts)
  • Verified manually against a screen with five elements sharing one test ID

@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: b66d22b0-ea83-4da3-8822-a807830543a2

📥 Commits

Reviewing files that changed from the base of the PR and between cfd8ad8 and 4ce8dea.

📒 Files selected for processing (2)
  • packages/inspector/src/lib/locator-derivation.test.ts
  • packages/inspector/src/lib/locator-derivation.ts

Included review availability: 1 review is currently available. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.


Walkthrough

deriveElementList now returns internal ElementEntry values. When a test ID is duplicated, each entry uses its role locator as the primary locator only if every duplicate has a globally unique role locator. Otherwise, the test-ID locator remains primary. Tests cover distinct roles, missing roles, role collisions outside the duplicate group, duplicate preservation, and unique IDs.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 4ce8d

No actionable merge-blocking issue remains from the supplied evidence.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: promoting unique role locators when duplicate test IDs exist.
Description check ✅ Passed The description accurately explains the duplicate test-ID behavior, uniqueness condition, fallback behavior, tests, lint validation, and manual verification.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@gmegidish
gmegidish merged commit a61399d into main Sep 18, 2026
9 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.

1 participant