Repository navigation
add data-testid hooks and aria-labels for future improvement - #2473
Conversation
grzanka
left a comment
There was a problem hiding this comment.
Good direction: a central test-id registry and real accessible names are a big step up from XPath on aria-label.
The main issue is that the Selenium migration weakened the tests. Several "tab became active" checks are now "element exists" checks that always pass, so navigation could break without any test failing. Please fix those (inline on SimulationControls.test.ts and FlukaConverter.test.ts) before merge. The prop-merging comments are small fixes. The rest can be follow-ups.
Prepared by Claude Opus 5.5 (Claude Code) at the request of @grzanka.
|
@cnuart please resolve merge conflicts and update PR description |
grzanka
left a comment
There was a problem hiding this comment.
Thanks, separating test IDs from ARIA is a good direction, and the useId-based dialog IDs fix real duplicate-ID problems. Two things need fixing before merging, plus a few smaller points inline.
1. The converter submodule goes backwards. src/libs/converter moves from 47dfd98 (master) to ea570da, which is older: it lacks "Add simulator detection for input files (#272)". PythonWorker.ts:108 still runs from converter.api import detect_simulators, which doesn't exist at ea570da, so simulator detection in the Input files panel breaks. This PR doesn't need a converter change, so git checkout origin/master -- src/libs/converter should be enough.
2. CI is red. ObjectInfo.test.ts:60 still clicks //div[@aria-label = 'Editor']. That aria-label is removed from NavPanelElement here, and the CI log shows the test timing out on that step in both attempts. Switching it to byTestId(testIds.navItem('editor')) like the other suites should fix it.
Smaller one, outside the diff: EditorSidebar.test.ts still opens the Add menu with By.id('menu-button-21') / menu-content-21, which depend on the menu's position index. Passing name to that MenuPosition and using testIds.menuButton(...) / testIds.menuPopup(...) would finish the migration for this suite.
Closes #1397
This PR separates E2E test selectors from accessibility attributes to prevent changes to the accessibility layer or DOM structure from breaking Selenium tests.
Previously, Selenium tests relied on ARIA attributes and DOM structure to locate elements. As a result, accessibility improvements or markup changes could unintentionally break E2E tests.
With this change,
data-testidis used exclusively for test automation, while ARIA attributes and HTML semantics are dedicated to accessibility. This establishes a clear separation of concerns and makes both the test suite and accessibility implementation more maintainable.Key Principles
data-testidfor testing, ARIA for accessibility. ARIA attributes must not be introduced solely to support tests, anddata-testidshould not be added indiscriminately to every element.<label>, string-based tooltips, oraria-labelledbywhenever possible.aria-labelonly when no visible text is available, for example, icon-only buttons, vector axes, or inputs that rely exclusively on placeholders.aria-labelmust neither contradict nor unnecessarily duplicate visible text.CheckboxandSwitch,aria-labelandaria-labelledbymust be applied throughslotProps.input, since applying them directly to the component places them on the root<span>rather than the actual input. ForModal, which usesrole="presentation", the accessible dialog name must be assigned to the content container.data-testidvalues follow kebab-case naming, avoid file names and UI text, and must be unique across the entire DOM. This is particularly important forTabPanelcomponents, which may coexist in the DOM even when not visible.Test Infrastructure
Two new utilities have been introduced:
src/util/testIds.ts– A centralized registry ofdata-testidvalues, including constants and functions for dynamically generated IDs. Keys are based on domain concepts rather than component or file names.src/test/seleniumUtils.ts– Introduces thebyTestId(id)helper for locating elements by their test IDs.Five Selenium tests have been migrated from ARIA-based and XPath selectors to
byTestId.TopasConverter.test.tshas been temporarily disabled usingxtest. A comment documents that its selectors are outdated. No selector migration has been included for this test.Accessibility Improvements
Automatically Generated IDs and Accessible Names
CustomDialog
useId, preventing potential duplicate IDs.aria-labelledbyandaria-describedby.PropertyField (Properties Panel)
useId.usePropertyFieldLabelId()context hook.aria-labelledby, without changing the DOM structure or styling.aria-labelledbyattribute is generated, preventing dangling ARIA references.Additional wrappers introduced in
PropertyField.tsx:LabelledSelectLabelledAutoCompleteSelectLabelledExclusiveToggleButtonGroupAutoCompleteSelectnow supports optionallabelIdandariaLabelprops.MaterialSelectandParticleSelectretrieve the label ID directly from the context.Dynamic Accessible Names
Accessible names are now composed from relevant application data where appropriate:
Visibility: <object name><label> X/Y/Z<label> valueBoolean operation: <geometry>BatchParametersEditor
aria-labelledbyto batch checkboxes, referencing their visible labels through IDs generated withuseId.Additional ARIA Improvements
aria-labelledbyandaria-controlsreferences.<nav>markup with the accessible nameMain navigation.aria-selectedwitharia-current="page"for the active navigation item.role="dialog"and an accessible name to theInput files editordialog.aria-labelattributes that duplicated visible text or tooltip content.Expected Outcome
Overall, this change establishes a clear boundary between test automation and accessibility, improving the long-term maintainability and reliability of both.