diff --git a/packages/docusaurus-theme-common/src/utils/__tests__/docsUtils.test.tsx b/packages/docusaurus-theme-common/src/utils/__tests__/docsUtils.test.tsx index d1285ad2c95b..230d2fbfa640 100644 --- a/packages/docusaurus-theme-common/src/utils/__tests__/docsUtils.test.tsx +++ b/packages/docusaurus-theme-common/src/utils/__tests__/docsUtils.test.tsx @@ -17,6 +17,7 @@ import { useCurrentSidebarCategory, useSidebarBreadcrumbs, isVisibleSidebarItem, + filterDocCardListItems, } from '../docsUtils'; import {DocsSidebarProvider} from '../../contexts/docsSidebar'; import {DocsVersionProvider} from '../../contexts/docsVersion'; @@ -762,3 +763,33 @@ describe('useCurrentSidebarCategory', () => { ); }); }); + +describe('filterDocCardListItems', () => { + it('returns original list of valid items', () => { + const items = [ + {type: 'link', href: '/foo/bar', label: 'Foo'}, + {type: 'link', href: 'bar/foo', label: 'Bar'}, + {type: 'link', href: '/foo/listed', label: 'Listed'}, + ]; + expect(filterDocCardListItems(items)).toEqual(items); + }); + it('filters out unlisted items', () => { + const items = [ + {type: 'link', href: '/foo/bar', label: 'Foo'}, + {type: 'link', href: 'bar/foo', label: 'Bar'}, + {type: 'link', href: '/foo/unlisted', label: 'Unlisted', unlisted: true}, + ]; + expect(filterDocCardListItems(items)).toEqual([ + {type: 'link', href: '/foo/bar', label: 'Foo'}, + {type: 'link', href: 'bar/foo', label: 'Bar'}, + ]); + }); + it('includes html items', () => { + const items = [ + {type: 'link', href: '/foo/bar', label: 'Foo'}, + {type: 'link', href: 'bar/foo', label: 'Bar'}, + {type: 'html', value: 'baz'}, + ]; + expect(filterDocCardListItems(items)).toEqual(items); + }); +});