Skip to content

Commit e0fb969

Browse files
committed
fix: Add unit tests for collectVisibleIds with grouped content display
1 parent 8da2406 commit e0fb969

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/collection-preferences/content-display/__tests__/utils.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
import { collectVisibleIds } from '../../../../lib/components/collection-preferences/utils';
34
import {
45
buildOptionTree,
56
getFilteredOptions,
@@ -299,3 +300,34 @@ describe('getFilteredOptions', () => {
299300
expect(result).toEqual([{ id: 'b', label: 'Beta', visible: true }]);
300301
});
301302
});
303+
304+
describe('collectVisibleIds', () => {
305+
it('collects visible leaf ids from grouped content display', () => {
306+
const items = [
307+
{ id: 'id1', visible: true },
308+
{
309+
type: 'group' as const,
310+
id: 'g1',
311+
visible: true,
312+
children: [
313+
{ id: 'id2', visible: true },
314+
{ id: 'id3', visible: false },
315+
],
316+
},
317+
{ type: 'group' as const, id: 'g2', visible: true, children: [{ id: 'id4', visible: true }] },
318+
];
319+
expect(collectVisibleIds(items, true)).toEqual(['id1', 'id2', 'id4']);
320+
});
321+
322+
it('excludes children of non-visible groups', () => {
323+
const items = [
324+
{
325+
type: 'group' as const,
326+
id: 'g1',
327+
visible: false,
328+
children: [{ id: 'id1', visible: true }],
329+
},
330+
];
331+
expect(collectVisibleIds(items, true)).toEqual([]);
332+
});
333+
});

src/collection-preferences/content-display/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ interface HierarchicalContentDisplayProps {
8787
ariaLabelledby?: string;
8888
ariaDescribedby?: string;
8989
i18nStrings: SortableAreaProps.DndAreaI18nStrings;
90-
sortDisabled?: boolean;
90+
sortDisabled: boolean;
9191
parentGroupLabel?: string;
9292
}
9393

@@ -138,7 +138,7 @@ function HierarchicalContentDisplay({
138138
ariaLabelledby,
139139
ariaDescribedby,
140140
i18nStrings,
141-
sortDisabled = false,
141+
sortDisabled,
142142
parentGroupLabel,
143143
}: HierarchicalContentDisplayProps) {
144144
return (

0 commit comments

Comments
 (0)