Add data-testids to UI elements in Device areas#608
Add data-testids to UI elements in Device areas#608talhil-rh wants to merge 1 commit intoflightctl:mainfrom
Conversation
WalkthroughThe pull request adds Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
libs/ui-components/src/components/Device/DevicesPage/EnrolledDeviceTableRow.tsx (1)
97-97: Prefer identity-based test id instead ofrowIndex.Line 97 ties the selector to row order, which may change and reduce test stability. Consider anchoring to device identity (for example,
deviceName).Suggested update
- <Td dataLabel={t('Update status')} data-testid={`device-update-status-${rowIndex}`}> + <Td dataLabel={t('Update status')} data-testid={`device-update-status-${deviceName}`}>🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@libs/ui-components/src/components/Device/DevicesPage/EnrolledDeviceTableRow.tsx` at line 97, The test id for the update status cell is currently tied to rowIndex which is brittle; update EnrolledDeviceTableRow so the Td with data-testid={`device-update-status-${rowIndex}`} uses a stable device identity instead (e.g., data-testid={`device-update-status-${deviceName}`} or `device-update-status-${deviceId}`) by referencing the component prop/field (deviceName or deviceId) used elsewhere in the component; ensure you sanitize/slugify the name if needed to produce a valid id.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@libs/ui-components/src/components/Device/DevicesPage/EnrolledDeviceTableRow.tsx`:
- Line 97: The test id for the update status cell is currently tied to rowIndex
which is brittle; update EnrolledDeviceTableRow so the Td with
data-testid={`device-update-status-${rowIndex}`} uses a stable device identity
instead (e.g., data-testid={`device-update-status-${deviceName}`} or
`device-update-status-${deviceId}`) by referencing the component prop/field
(deviceName or deviceId) used elsewhere in the component; ensure you
sanitize/slugify the name if needed to produce a valid id.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: af95b16b-8274-4396-918b-b50b254b70ab
📒 Files selected for processing (8)
libs/ui-components/src/components/Device/DeviceDetails/DeviceDetailsPage.tsxlibs/ui-components/src/components/Device/DeviceDetails/TerminalTab.tsxlibs/ui-components/src/components/Device/DevicesPage/DecommissionedDevicesTable.tsxlibs/ui-components/src/components/Device/DevicesPage/EnrolledDeviceTableRow.tsxlibs/ui-components/src/components/Events/EventsCard.tsxlibs/ui-components/src/components/form/RichValidationTextField.tsxlibs/ui-components/src/components/form/TextField.tsxlibs/ui-components/src/components/modals/ApproveDeviceModal/ApproveDeviceForm.tsx
Summary
This PR introduces stable data-testid hooks across device-related screens and shared form/event components. These hooks enable reliable element targeting for Cypress (and similar tools), eliminating the need for brittle CSS or text-based selectors.
Motivation
End-to-end tests require consistent and predictable selectors for key UI elements such as:
Tabs and tables
Terminal states
Events UI
Approve-device flows
This change ensures test stability by wiring data-testid attributes through existing components without altering any behavior.
Changes
Device Details
Added data-testid to all device details tabs:
device-details-tab-details
device-details-tab-catalog
device-details-tab-yaml
device-details-tab-terminal
device-details-tab-events
Terminal
device-terminal-loading — shown during connecting state
device-terminal-panel — terminal container
Devices List
decommissioned-devices-table — decommissioned devices table
device-update-status-${rowIndex} — update status cell per enrolled device row
Events (Device Context)
events-type-filter-toggle — filter toggle
Filter options:
events-filter-option-all-types
events-filter-option-normal
events-filter-option-warning
device-events-list — events list body
Forms
TextInput (via TextField / RichValidationTextField) uses:
data-testid={fieldId} where applicable
Validation trigger:
${fieldId}-validation-button
Disabled rich-validation fallback:
rich-validation-field-${fieldName}
Approve Device Modal
approve-device-form-cancel — Cancel action
Summary by CodeRabbit