test(ui): add unit tests for 10 more UI components#1622
test(ui): add unit tests for 10 more UI components#1622
Conversation
Agent-Logs-Url: https://github.com/jetstreamapp/jetstream/sessions/1918d0ef-01a8-4de2-ade9-ca087433adfd Co-authored-by: paustint <5461649+paustint@users.noreply.github.com>
Agent-Logs-Url: https://github.com/jetstreamapp/jetstream/sessions/1918d0ef-01a8-4de2-ade9-ca087433adfd Co-authored-by: paustint <5461649+paustint@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds Vitest/@testing-library unit test coverage across additional libs/ui components to better lock in expected DOM structure, SLDS class generation, callbacks, and basic a11y roles/attributes.
Changes:
- Added new test suites for
Section,Toolbar*,Grid/GridCol,Spinner,Pill, andBreadcrumbs. - Added new test suites for
Checkbox,ProgressStepIndicator*,List/ReadonlyList, andTree(including imperative ref behaviors). - Expanded coverage around ARIA attributes/roles and component callback wiring.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libs/ui/src/lib/widgets/tests/Widgets.spec.tsx | Adds tests for Spinner, Pill, and Breadcrumbs rendering, classes, and callbacks. |
| libs/ui/src/lib/tree/tests/Tree.spec.tsx | Adds tests for Tree rendering, expansion behaviors, selection, and imperative ref methods. |
| libs/ui/src/lib/toolbar/tests/Toolbar.spec.tsx | Adds tests for toolbar components’ roles, classes, and basic rendering. |
| libs/ui/src/lib/section/tests/Section.spec.tsx | Adds tests for expand/collapse, ARIA attributes, and removeFromDomOnCollapse. |
| libs/ui/src/lib/progress-indicator/tests/ProgressStepIndicator.spec.tsx | Adds tests for progressbar ARIA values and list-item variants/callbacks. |
| libs/ui/src/lib/list/tests/List.spec.tsx | Adds tests for list rendering/selection plus basic keyboard-event coverage. |
| libs/ui/src/lib/grid/tests/Grid.spec.tsx | Adds tests for class generation and prop passthrough on Grid/GridCol. |
| libs/ui/src/lib/form/checkbox/tests/Checkbox.spec.tsx | Adds tests for controlled behavior, error states, required indicator, and labeling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| test('keyboard ArrowDown moves focus to next item', () => { | ||
| const onSelected = vi.fn(); | ||
| render( | ||
| <List | ||
| items={items} | ||
| isActive={(item) => item.id === 'item-1'} | ||
| getContent={getContent} | ||
| onSelected={onSelected} | ||
| />, | ||
| ); | ||
| const listbox = screen.getByRole('listbox'); | ||
| fireEvent.keyDown(listbox, { key: 'ArrowDown', code: 'ArrowDown' }); | ||
| // No error means keyboard handler ran successfully | ||
| }); |
There was a problem hiding this comment.
The keyboard navigation tests here don’t assert any observable outcome (they pass even if the key handler is removed). Since List moves focus via the internal focusedItem state, consider asserting that focus actually changes (e.g., document.activeElement becomes the expected option after ArrowDown).
| ); | ||
| const listbox = screen.getByRole('listbox'); | ||
| fireEvent.keyDown(listbox, { key: 'Home', code: 'Home' }); | ||
| // No error means keyboard handler ran successfully |
There was a problem hiding this comment.
This Home-key test currently only fires a keyDown event without asserting behavior. To ensure keyboard support doesn’t regress, assert the expected focused element (e.g., after pressing Home, the first option receives focus).
| // No error means keyboard handler ran successfully | |
| const options = screen.getAllByRole('option'); | |
| const firstOption = options[0]; | |
| expect(document.activeElement).toBe(firstOption); |
| // Note: Section.tsx sets aria-expanded={!expanded} on the toggle button, | ||
| // which is inverted from the ARIA spec convention. These tests reflect the | ||
| // actual component behavior. |
There was a problem hiding this comment.
These tests document that Section sets aria-expanded={!expanded}, which is inverted from the ARIA expected meaning (aria-expanded should be true when the controlled region is expanded). Adding tests that lock in this inverted behavior will make an accessibility fix harder later; please consider fixing Section.tsx to use the correct aria-expanded={expanded} and updating these expectations accordingly (keeping aria-hidden aligned).
|
@copilot - there are test failures and there are some code review feedack requests - address them all ... |
…rtions
- Fix Section.tsx: use aria-expanded={expanded} (was incorrectly inverted as {!expanded})
- Update Section tests to expect correct ARIA values (true=open, false=closed)
- Add document.activeElement assertions to List ArrowDown and Home key tests
- Mock @jetstream/ui/app-state in Popover test to prevent unhandled rejection from fetchUserProfile() at module init time
Agent-Logs-Url: https://github.com/jetstreamapp/jetstream/sessions/15c8c0da-07de-4bca-83f5-b9771f4ae11d
Co-authored-by: paustint <5461649+paustint@users.noreply.github.com>
Addressed in commit CI failure (Popover unhandled rejection): Added Section List keyboard navigation tests: Replaced the no-op comment tests with real |
Uh oh!
There was an error while loading. Please reload this page.