test: improve test coverage; multiple internal refactors ()

This commit is contained in:
Joshua Chen 2022-03-14 21:53:57 +08:00 committed by GitHub
parent 12a7305238
commit ad88f5cc87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
78 changed files with 1613 additions and 1149 deletions
packages/docusaurus-plugin-content-docs/src/sidebars

View file

@ -58,22 +58,17 @@ function postProcessSidebarItem(
`Sidebar category ${item.label} has neither any subitem nor a link. This makes this item not able to link to anything.`,
);
}
switch (category.link.type) {
case 'doc':
return {
return category.link.type === 'doc'
? {
type: 'doc',
label: category.label,
id: category.link.id,
};
case 'generated-index':
return {
}
: {
type: 'link',
label: category.label,
href: category.link.permalink,
};
default:
throw new Error('Unexpected sidebar category link type');
}
}
// A non-collapsible category can't be collapsed!
if (category.collapsible === false) {

View file

@ -376,18 +376,13 @@ export function toNavigationLink(
return undefined;
}
if (navigationItem.type === 'doc') {
return toDocNavigationLink(getDocById(navigationItem.id));
} else if (navigationItem.type === 'category') {
if (navigationItem.link.type === 'doc') {
return toDocNavigationLink(getDocById(navigationItem.link.id));
} else if (navigationItem.link.type === 'generated-index') {
return {
title: navigationItem.label,
permalink: navigationItem.link.permalink,
};
}
throw new Error('unexpected category link type');
if (navigationItem.type === 'category') {
return navigationItem.link.type === 'doc'
? toDocNavigationLink(getDocById(navigationItem.link.id))
: {
title: navigationItem.label,
permalink: navigationItem.link.permalink,
};
}
throw new Error('unexpected navigation item');
return toDocNavigationLink(getDocById(navigationItem.id));
}