Skip to content

Commit b17329a

Browse files
srividyaramasSriRamas23Copilot
authored
test(list-item): cover SPEC selection matrix and avatar precedence (#4416)
Co-authored-by: Srividya Ramaswamy <sriramas@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 4b66f3ef-85ac-4405-bd35-dcc167a077b1
1 parent 80310a6 commit b17329a

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎.changeset/fuzzy-steaks-notice.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
3+
---
4+
5+

‎packages/agentic/components/src/components/list-item/list-item.test.tsx‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,56 @@ function getRootStyle(component: RenderResult): ViewStyle {
2323
}
2424

2525
describe('ListItem', () => {
26+
it.each([
27+
['none', false, undefined],
28+
['none', true, undefined],
29+
['single', false, '○'],
30+
['single', true, '◉'],
31+
['multiple', false, '☐'],
32+
['multiple', true, '☑'],
33+
] as const)('LIT-003 keeps %s selection=%s caller-owned and presents only its glyph', async (selectionMode, selected, glyph) => {
34+
const onPress = jest.fn();
35+
const component = await renderListItem({ content: 'Choice', selectionMode, selected, onPress });
36+
await fireEvent.press(getRoot(component));
37+
expect(onPress).toHaveBeenCalledTimes(1);
38+
expect(getRoot(component).props.accessibilityState.selected).toBe(selected);
39+
for (const candidate of ['○', '◉', '☐', '☑']) {
40+
if (candidate === glyph) {
41+
expect(component.getByText(candidate, { includeHiddenElements: true }).props).toMatchObject({
42+
accessible: false,
43+
accessibilityElementsHidden: true,
44+
importantForAccessibility: 'no-hide-descendants',
45+
});
46+
} else {
47+
expect(component.queryByText(candidate, { includeHiddenElements: true })).toBeNull();
48+
}
49+
}
50+
expect(getRootStyle(component).backgroundColor).toBe(
51+
selected && selectionMode !== 'multiple'
52+
? defaultFlexTokens.color.backgroundNeutralSoft
53+
: defaultFlexTokens.color.backgroundNeutralTransparent,
54+
);
55+
});
56+
57+
it.each([false, true])('LIT-002 gives avatar precedence over both icons when selected=%s', async (selected) => {
58+
const component = await renderListItem({
59+
content: 'Contact',
60+
selected,
61+
avatar: { testID: 'contact-avatar' },
62+
icon: { imageSource: { uri: 'regular.png' }, testID: 'regular-icon' },
63+
selectedIcon: { imageSource: { uri: 'selected.png' }, testID: 'selected-icon' },
64+
});
65+
expect(component.getByTestId('contact-avatar').props.accessible).toBe(false);
66+
expect(component.queryByTestId('regular-icon')).toBeNull();
67+
expect(component.queryByTestId('selected-icon')).toBeNull();
68+
});
69+
70+
it.each(['none', 'single', 'multiple'] as const)('LIT-004 suppresses selected fill while disabled in %s mode', async (selectionMode) => {
71+
const component = await renderListItem({ content: 'Unavailable', selected: true, disabled: true, selectionMode });
72+
expect(getRootStyle(component).backgroundColor).toBe(defaultFlexTokens.color.backgroundNeutralTransparent);
73+
expect(getRoot(component).props.accessibilityState).toEqual({ disabled: true, selected: true });
74+
});
75+
2676
it('renders selection without changing it on press', async () => {
2777
const onPress = jest.fn();
2878
const component = await renderListItem({ content: 'Inbox', onPress, selected: false, selectionMode: 'multiple' });

0 commit comments

Comments
 (0)