mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 02:08:55 +02:00
fix(content-docs): render category with no subitems as a normal link (#6495)
This commit is contained in:
parent
049b2c84c6
commit
3573b5e4a9
6 changed files with 120 additions and 5 deletions
|
@ -209,6 +209,12 @@ describe('processSidebars', () => {
|
|||
// typing error needing refactor
|
||||
permalink: undefined,
|
||||
},
|
||||
items: [
|
||||
{
|
||||
type: 'doc',
|
||||
id: 'foo',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -232,11 +238,73 @@ describe('processSidebars', () => {
|
|||
slug: 'generated-cat-index-slug',
|
||||
permalink: '/docs/1.0.0/generated-cat-index-slug',
|
||||
},
|
||||
items: [],
|
||||
items: [
|
||||
{
|
||||
type: 'doc',
|
||||
id: 'foo',
|
||||
},
|
||||
],
|
||||
collapsible: true,
|
||||
collapsed: true,
|
||||
},
|
||||
],
|
||||
} as Sidebars);
|
||||
});
|
||||
|
||||
test('transforms category without subitems', async () => {
|
||||
const sidebarSlice: SidebarItem[] = [
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Category',
|
||||
link: {
|
||||
type: 'generated-index',
|
||||
permalink: 'generated/permalink',
|
||||
},
|
||||
items: [],
|
||||
},
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Category 2',
|
||||
link: {
|
||||
type: 'doc',
|
||||
id: 'doc ID',
|
||||
},
|
||||
items: [],
|
||||
},
|
||||
];
|
||||
|
||||
const processedSidebar = await testProcessSidebars(
|
||||
{sidebar: sidebarSlice},
|
||||
{},
|
||||
);
|
||||
|
||||
expect(processedSidebar).toEqual({
|
||||
sidebar: [
|
||||
{
|
||||
type: 'link',
|
||||
label: 'Category',
|
||||
href: 'generated/permalink',
|
||||
},
|
||||
{
|
||||
type: 'doc',
|
||||
label: 'Category 2',
|
||||
id: 'doc ID',
|
||||
},
|
||||
],
|
||||
} as Sidebars);
|
||||
|
||||
await expect(async () => {
|
||||
await testProcessSidebars({
|
||||
sidebar: [
|
||||
{
|
||||
type: 'category',
|
||||
label: 'Bad category',
|
||||
items: [],
|
||||
},
|
||||
],
|
||||
});
|
||||
}).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Sidebar category Bad category has neither any subitem nor a link. This makes this item not able to link to anything."`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue