Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(theme-common): increase filterDocCardListItems test coverage #9064

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,6 +17,7 @@ import {
useCurrentSidebarCategory,
useSidebarBreadcrumbs,
isVisibleSidebarItem,
filterDocCardListItems,
} from '../docsUtils';
import {DocsSidebarProvider} from '../../contexts/docsSidebar';
import {DocsVersionProvider} from '../../contexts/docsVersion';
Expand Down Expand Up @@ -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);
});
Comment on lines +768 to +775
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add html items here, and also valid categories with valid items as children

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'},
]);
});
Comment on lines +776 to +786
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add other filtered item types here?

  • link with no href
  • category with unlisted link
  • category with no href
  • category having all its direct childs being filtered

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);
});
Comment on lines +787 to +794
Copy link
Collaborator

@slorber slorber Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe html items can be included in the first test case? "list of valid items"

});