mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
test: fix ALL type errors in tests (#7487)
This commit is contained in:
parent
e2e40b8f5f
commit
d50fe3b670
37 changed files with 407 additions and 184 deletions
|
@ -84,11 +84,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
{
|
||||
"loadedVersions": [
|
||||
{
|
||||
"badge": true,
|
||||
"banner": null,
|
||||
"className": "",
|
||||
"contentPath": "any",
|
||||
"contentPathLocalized": "any",
|
||||
"docs": [
|
||||
{
|
||||
"description": "doc1 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc1 title",
|
||||
|
@ -101,12 +105,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc1 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc2 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc2 title",
|
||||
|
@ -119,12 +126,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc2 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc3 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc3 title",
|
||||
|
@ -137,12 +147,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc3 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc4 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc4 title",
|
||||
|
@ -155,12 +168,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc4 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc5 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc5 title",
|
||||
|
@ -173,14 +189,16 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc5 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
],
|
||||
"drafts": [],
|
||||
"isLast": true,
|
||||
"label": "current label (translated)",
|
||||
"mainDocId": "",
|
||||
"path": "/docs/",
|
||||
"routePriority": undefined,
|
||||
"sidebarFilePath": "any",
|
||||
|
@ -188,6 +206,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"docs": [
|
||||
{
|
||||
"collapsed": false,
|
||||
"collapsible": true,
|
||||
"items": [
|
||||
{
|
||||
"id": "doc1",
|
||||
|
@ -233,14 +252,19 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
},
|
||||
],
|
||||
},
|
||||
"tagsPath": "/tags/",
|
||||
"versionName": "current",
|
||||
},
|
||||
{
|
||||
"badge": true,
|
||||
"banner": null,
|
||||
"className": "",
|
||||
"contentPath": "any",
|
||||
"contentPathLocalized": "any",
|
||||
"docs": [
|
||||
{
|
||||
"description": "doc1 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc1 title",
|
||||
|
@ -253,12 +277,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc1 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc2 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc2 title",
|
||||
|
@ -271,12 +298,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc2 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc3 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc3 title",
|
||||
|
@ -289,12 +319,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc3 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc4 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc4 title",
|
||||
|
@ -307,12 +340,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc4 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc5 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc5 title",
|
||||
|
@ -325,14 +361,16 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc5 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
],
|
||||
"drafts": [],
|
||||
"isLast": true,
|
||||
"label": "2.0.0 label (translated)",
|
||||
"mainDocId": "",
|
||||
"path": "/docs/",
|
||||
"routePriority": undefined,
|
||||
"sidebarFilePath": "any",
|
||||
|
@ -340,6 +378,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"docs": [
|
||||
{
|
||||
"collapsed": false,
|
||||
"collapsible": true,
|
||||
"items": [
|
||||
{
|
||||
"id": "doc1",
|
||||
|
@ -385,14 +424,19 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
},
|
||||
],
|
||||
},
|
||||
"tagsPath": "/tags/",
|
||||
"versionName": "2.0.0",
|
||||
},
|
||||
{
|
||||
"badge": true,
|
||||
"banner": null,
|
||||
"className": "",
|
||||
"contentPath": "any",
|
||||
"contentPathLocalized": "any",
|
||||
"docs": [
|
||||
{
|
||||
"description": "doc1 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc1 title",
|
||||
|
@ -405,12 +449,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc1 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc2 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc2 title",
|
||||
|
@ -423,12 +470,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc2 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc3 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc3 title",
|
||||
|
@ -441,12 +491,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc3 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc4 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc4 title",
|
||||
|
@ -459,12 +512,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc4 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
{
|
||||
"description": "doc5 description",
|
||||
"draft": false,
|
||||
"editUrl": "any",
|
||||
"frontMatter": {
|
||||
"sidebar_label": "doc5 title",
|
||||
|
@ -477,14 +533,16 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"previous": undefined,
|
||||
"slug": "any",
|
||||
"source": "any",
|
||||
"sourceDirName": "",
|
||||
"tags": [],
|
||||
"title": "doc5 title",
|
||||
"unversionedId": "any",
|
||||
"version": "any",
|
||||
},
|
||||
],
|
||||
"drafts": [],
|
||||
"isLast": true,
|
||||
"label": "1.0.0 label (translated)",
|
||||
"mainDocId": "",
|
||||
"path": "/docs/",
|
||||
"routePriority": undefined,
|
||||
"sidebarFilePath": "any",
|
||||
|
@ -492,6 +550,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
"docs": [
|
||||
{
|
||||
"collapsed": false,
|
||||
"collapsible": true,
|
||||
"items": [
|
||||
{
|
||||
"id": "doc1",
|
||||
|
@ -537,6 +596,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
|
|||
},
|
||||
],
|
||||
},
|
||||
"tagsPath": "/tags/",
|
||||
"versionName": "1.0.0",
|
||||
},
|
||||
],
|
||||
|
|
|
@ -25,9 +25,11 @@ import {DisabledSidebars} from '../sidebars';
|
|||
import * as cliDocs from '../cli';
|
||||
import {validateOptions} from '../options';
|
||||
|
||||
import type {RouteConfig} from '@docusaurus/types';
|
||||
import type {RouteConfig, Validate, Plugin} from '@docusaurus/types';
|
||||
import type {
|
||||
LoadedVersion,
|
||||
Options,
|
||||
PluginOptions,
|
||||
PropSidebarItemLink,
|
||||
} from '@docusaurus/plugin-content-docs';
|
||||
import type {
|
||||
|
@ -133,7 +135,7 @@ describe('sidebar', () => {
|
|||
const plugin = await pluginContentDocs(
|
||||
context,
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
sidebarPath,
|
||||
},
|
||||
|
@ -150,7 +152,7 @@ describe('sidebar', () => {
|
|||
const plugin = await pluginContentDocs(
|
||||
context,
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
sidebarPath: 'wrong-path-sidebar.json',
|
||||
},
|
||||
|
@ -173,7 +175,7 @@ describe('sidebar', () => {
|
|||
const plugin = await pluginContentDocs(
|
||||
context,
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
sidebarPath: undefined,
|
||||
},
|
||||
|
@ -191,7 +193,7 @@ describe('sidebar', () => {
|
|||
const plugin = await pluginContentDocs(
|
||||
context,
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
sidebarPath: false,
|
||||
},
|
||||
|
@ -212,7 +214,10 @@ describe('empty/no docs website', () => {
|
|||
await fs.ensureDir(path.join(siteDir, 'docs'));
|
||||
const plugin = await pluginContentDocs(
|
||||
context,
|
||||
validateOptions({validate: normalizePluginOptions, options: {}}),
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {},
|
||||
}),
|
||||
);
|
||||
await expect(
|
||||
plugin.loadContent!(),
|
||||
|
@ -227,7 +232,7 @@ describe('empty/no docs website', () => {
|
|||
pluginContentDocs(
|
||||
context,
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
path: 'path/does/not/exist',
|
||||
},
|
||||
|
@ -245,7 +250,7 @@ describe('simple website', () => {
|
|||
const context = await loadContext({siteDir});
|
||||
const sidebarPath = path.join(siteDir, 'sidebars.json');
|
||||
const options = validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
path: 'docs',
|
||||
sidebarPath,
|
||||
|
@ -299,7 +304,7 @@ describe('simple website', () => {
|
|||
const content = await plugin.loadContent?.();
|
||||
|
||||
const config = applyConfigureWebpack(
|
||||
plugin.configureWebpack,
|
||||
plugin.configureWebpack as NonNullable<Plugin['configureWebpack']>,
|
||||
{
|
||||
entry: './src/index.js',
|
||||
output: {
|
||||
|
@ -352,7 +357,7 @@ describe('versioned website', () => {
|
|||
const sidebarPath = path.join(siteDir, 'sidebars.json');
|
||||
const routeBasePath = 'docs';
|
||||
const options = validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
routeBasePath,
|
||||
sidebarPath,
|
||||
|
@ -478,7 +483,7 @@ describe('versioned website (community)', () => {
|
|||
const routeBasePath = 'community';
|
||||
const pluginId = 'community';
|
||||
const options = validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
id: 'community',
|
||||
path: 'community',
|
||||
|
@ -581,7 +586,7 @@ describe('site with doc label', () => {
|
|||
const plugin = await pluginContentDocs(
|
||||
context,
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
path: 'docs',
|
||||
sidebarPath,
|
||||
|
@ -626,7 +631,7 @@ describe('site with full autogenerated sidebar', () => {
|
|||
const plugin = await pluginContentDocs(
|
||||
context,
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
path: 'docs',
|
||||
},
|
||||
|
@ -681,7 +686,7 @@ describe('site with partial autogenerated sidebars', () => {
|
|||
const plugin = await pluginContentDocs(
|
||||
context,
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
path: 'docs',
|
||||
sidebarPath: path.join(
|
||||
|
@ -737,7 +742,7 @@ describe('site with partial autogenerated sidebars 2 (fix #4638)', () => {
|
|||
const plugin = await pluginContentDocs(
|
||||
context,
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
path: 'docs',
|
||||
sidebarPath: path.join(
|
||||
|
@ -774,7 +779,7 @@ describe('site with custom sidebar items generator', () => {
|
|||
const plugin = await pluginContentDocs(
|
||||
context,
|
||||
validateOptions({
|
||||
validate: normalizePluginOptions,
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options: {
|
||||
path: 'docs',
|
||||
sidebarItemsGenerator,
|
||||
|
|
|
@ -13,14 +13,18 @@ import {
|
|||
DefaultNumberPrefixParser,
|
||||
DisabledNumberPrefixParser,
|
||||
} from '../numberPrefix';
|
||||
import type {Options} from '@docusaurus/plugin-content-docs';
|
||||
import type {Options, PluginOptions} from '@docusaurus/plugin-content-docs';
|
||||
import type {Validate} from '@docusaurus/types';
|
||||
|
||||
// The type of remark/rehype plugins can be function/object
|
||||
const markdownPluginsFunctionStub = () => {};
|
||||
const markdownPluginsObjectStub = {};
|
||||
|
||||
function testValidate(options: Options) {
|
||||
return validateOptions({validate: normalizePluginOptions, options});
|
||||
return validateOptions({
|
||||
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
|
||||
options,
|
||||
});
|
||||
}
|
||||
|
||||
const defaultOptions = {
|
||||
|
|
|
@ -19,6 +19,9 @@ import type {
|
|||
|
||||
function createSampleDoc(doc: Pick<DocMetadata, 'id'>): DocMetadata {
|
||||
return {
|
||||
sourceDirName: '',
|
||||
draft: false,
|
||||
tags: [],
|
||||
editUrl: 'any',
|
||||
lastUpdatedAt: 0,
|
||||
lastUpdatedBy: 'any',
|
||||
|
@ -44,12 +47,16 @@ function createSampleVersion(
|
|||
return {
|
||||
label: `${version.versionName} label`,
|
||||
path: '/docs/',
|
||||
mainDocId: '',
|
||||
routePriority: undefined,
|
||||
sidebarFilePath: 'any',
|
||||
isLast: true,
|
||||
contentPath: 'any',
|
||||
contentPathLocalized: 'any',
|
||||
tagsPath: '/tags/',
|
||||
banner: null,
|
||||
badge: true,
|
||||
className: '',
|
||||
drafts: [],
|
||||
docs: [
|
||||
createSampleDoc({id: 'doc1'}),
|
||||
createSampleDoc({id: 'doc2'}),
|
||||
|
@ -63,6 +70,7 @@ function createSampleVersion(
|
|||
type: 'category',
|
||||
label: 'Getting started',
|
||||
collapsed: false,
|
||||
collapsible: true,
|
||||
link: {
|
||||
type: 'generated-index',
|
||||
slug: '/category/getting-started-index-slug',
|
||||
|
|
|
@ -17,6 +17,7 @@ import type {
|
|||
GlobalPluginData,
|
||||
GlobalVersion,
|
||||
ActivePlugin,
|
||||
GlobalDoc,
|
||||
} from '@docusaurus/plugin-content-docs/client';
|
||||
|
||||
describe('docsClientUtils', () => {
|
||||
|
@ -25,10 +26,12 @@ describe('docsClientUtils', () => {
|
|||
pluginIosId: {
|
||||
path: '/ios',
|
||||
versions: [],
|
||||
breadcrumbs: true,
|
||||
},
|
||||
pluginAndroidId: {
|
||||
path: '/android',
|
||||
versions: [],
|
||||
breadcrumbs: true,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -48,7 +51,7 @@ describe('docsClientUtils', () => {
|
|||
|
||||
const activePluginIos: ActivePlugin = {
|
||||
pluginId: 'pluginIosId',
|
||||
pluginData: data.pluginIosId,
|
||||
pluginData: data.pluginIosId!,
|
||||
};
|
||||
expect(getActivePlugin(data, '/ios')).toEqual(activePluginIos);
|
||||
expect(getActivePlugin(data, '/ios/')).toEqual(activePluginIos);
|
||||
|
@ -56,38 +59,42 @@ describe('docsClientUtils', () => {
|
|||
|
||||
const activePluginAndroid: ActivePlugin = {
|
||||
pluginId: 'pluginAndroidId',
|
||||
pluginData: data.pluginAndroidId,
|
||||
pluginData: data.pluginAndroidId!,
|
||||
};
|
||||
expect(getActivePlugin(data, '/android')).toEqual(activePluginAndroid);
|
||||
expect(getActivePlugin(data, '/android/')).toEqual(activePluginAndroid);
|
||||
expect(getActivePlugin(data, '/android/ijk')).toEqual(activePluginAndroid);
|
||||
|
||||
// https://github.com/facebook/docusaurus/issues/6434
|
||||
const onePluginAtRoot = {
|
||||
const onePluginAtRoot: {[key: string]: GlobalPluginData} = {
|
||||
pluginIosId: {
|
||||
path: '/',
|
||||
versions: [],
|
||||
breadcrumbs: true,
|
||||
},
|
||||
pluginAndroidId: {
|
||||
path: '/android',
|
||||
versions: [],
|
||||
breadcrumbs: true,
|
||||
},
|
||||
};
|
||||
expect(getActivePlugin(onePluginAtRoot, '/android/foo').pluginId).toBe(
|
||||
expect(getActivePlugin(onePluginAtRoot, '/android/foo')!.pluginId).toBe(
|
||||
'pluginAndroidId',
|
||||
);
|
||||
const onePluginAtRootReversed = {
|
||||
const onePluginAtRootReversed: {[key: string]: GlobalPluginData} = {
|
||||
pluginAndroidId: {
|
||||
path: '/android',
|
||||
versions: [],
|
||||
breadcrumbs: true,
|
||||
},
|
||||
pluginIosId: {
|
||||
path: '/',
|
||||
versions: [],
|
||||
breadcrumbs: true,
|
||||
},
|
||||
};
|
||||
expect(
|
||||
getActivePlugin(onePluginAtRootReversed, '/android/foo').pluginId,
|
||||
getActivePlugin(onePluginAtRootReversed, '/android/foo')!.pluginId,
|
||||
).toBe('pluginAndroidId');
|
||||
});
|
||||
|
||||
|
@ -100,6 +107,7 @@ describe('docsClientUtils', () => {
|
|||
isLast: false,
|
||||
docs: [],
|
||||
mainDocId: '???',
|
||||
draftIds: [],
|
||||
},
|
||||
{
|
||||
name: 'version2',
|
||||
|
@ -108,6 +116,7 @@ describe('docsClientUtils', () => {
|
|||
isLast: true,
|
||||
docs: [],
|
||||
mainDocId: '???',
|
||||
draftIds: [],
|
||||
},
|
||||
{
|
||||
name: 'version3',
|
||||
|
@ -116,6 +125,7 @@ describe('docsClientUtils', () => {
|
|||
isLast: false,
|
||||
docs: [],
|
||||
mainDocId: '???',
|
||||
draftIds: [],
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -123,6 +133,7 @@ describe('docsClientUtils', () => {
|
|||
getLatestVersion({
|
||||
path: '???',
|
||||
versions,
|
||||
breadcrumbs: true,
|
||||
}),
|
||||
).toEqual(versions[1]);
|
||||
});
|
||||
|
@ -138,6 +149,7 @@ describe('docsClientUtils', () => {
|
|||
path: '/docs/next',
|
||||
docs: [],
|
||||
mainDocId: '???',
|
||||
draftIds: [],
|
||||
},
|
||||
{
|
||||
name: 'version2',
|
||||
|
@ -146,6 +158,7 @@ describe('docsClientUtils', () => {
|
|||
path: '/docs',
|
||||
docs: [],
|
||||
mainDocId: '???',
|
||||
draftIds: [],
|
||||
},
|
||||
{
|
||||
name: 'version1',
|
||||
|
@ -154,8 +167,10 @@ describe('docsClientUtils', () => {
|
|||
path: '/docs/version1',
|
||||
docs: [],
|
||||
mainDocId: '???',
|
||||
draftIds: [],
|
||||
},
|
||||
],
|
||||
breadcrumbs: true,
|
||||
};
|
||||
|
||||
expect(getActiveVersion(data, '/someUnknownPath')).toBeUndefined();
|
||||
|
@ -191,7 +206,8 @@ describe('docsClientUtils', () => {
|
|||
id: 'doc2',
|
||||
path: '/docs/next/doc2',
|
||||
},
|
||||
],
|
||||
] as GlobalDoc[],
|
||||
draftIds: [],
|
||||
};
|
||||
|
||||
const version2: GlobalVersion = {
|
||||
|
@ -209,7 +225,8 @@ describe('docsClientUtils', () => {
|
|||
id: 'doc2',
|
||||
path: '/docs/doc2',
|
||||
},
|
||||
],
|
||||
] as GlobalDoc[],
|
||||
draftIds: [],
|
||||
};
|
||||
|
||||
const version1: GlobalVersion = {
|
||||
|
@ -223,7 +240,8 @@ describe('docsClientUtils', () => {
|
|||
id: 'doc1',
|
||||
path: '/docs/version1/',
|
||||
},
|
||||
],
|
||||
] as GlobalDoc[],
|
||||
draftIds: [],
|
||||
};
|
||||
|
||||
// Shuffle, because order shouldn't matter
|
||||
|
@ -236,6 +254,7 @@ describe('docsClientUtils', () => {
|
|||
const data: GlobalPluginData = {
|
||||
path: 'docs',
|
||||
versions,
|
||||
breadcrumbs: true,
|
||||
};
|
||||
|
||||
expect(getActiveDocContext(data, '/doesNotExist')).toEqual({
|
||||
|
@ -320,7 +339,8 @@ describe('docsClientUtils', () => {
|
|||
id: 'doc2',
|
||||
path: '/docs/next/doc2',
|
||||
},
|
||||
],
|
||||
] as GlobalDoc[],
|
||||
draftIds: [],
|
||||
};
|
||||
|
||||
const version2: GlobalVersion = {
|
||||
|
@ -338,7 +358,8 @@ describe('docsClientUtils', () => {
|
|||
id: 'doc2',
|
||||
path: '/docs/doc2',
|
||||
},
|
||||
],
|
||||
] as GlobalDoc[],
|
||||
draftIds: [],
|
||||
};
|
||||
|
||||
const version1: GlobalVersion = {
|
||||
|
@ -352,7 +373,8 @@ describe('docsClientUtils', () => {
|
|||
id: 'doc1',
|
||||
path: '/docs/version1/',
|
||||
},
|
||||
],
|
||||
] as GlobalDoc[],
|
||||
draftIds: [],
|
||||
};
|
||||
|
||||
// Shuffle, because order shouldn't matter
|
||||
|
@ -365,6 +387,7 @@ describe('docsClientUtils', () => {
|
|||
const data: GlobalPluginData = {
|
||||
path: 'docs',
|
||||
versions,
|
||||
breadcrumbs: true,
|
||||
};
|
||||
|
||||
expect(getDocVersionSuggestions(data, '/doesNotExist')).toEqual({
|
||||
|
|
|
@ -28,8 +28,12 @@ function createFakeVersion({
|
|||
}): VersionMetadata {
|
||||
return {
|
||||
versionName,
|
||||
versionLabel: 'Any',
|
||||
versionPath: 'any',
|
||||
label: 'Any',
|
||||
path: 'any',
|
||||
badge: true,
|
||||
banner: null,
|
||||
tagsPath: '/tags/',
|
||||
className: '',
|
||||
contentPath,
|
||||
contentPathLocalized,
|
||||
sidebarFilePath: 'any',
|
||||
|
|
|
@ -27,10 +27,6 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
contentPath: 'docs',
|
||||
},
|
||||
docs: [],
|
||||
options: {
|
||||
sidebarCollapsed: true,
|
||||
sidebarCollapsible: true,
|
||||
},
|
||||
categoriesMetadata: {},
|
||||
...params,
|
||||
});
|
||||
|
@ -69,6 +65,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
frontMatter: {
|
||||
sidebar_label: 'doc1 sidebar label',
|
||||
},
|
||||
title: '',
|
||||
unversionedId: 'doc1',
|
||||
},
|
||||
{
|
||||
id: 'doc2',
|
||||
|
@ -76,6 +74,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '.',
|
||||
sidebarPosition: 3,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc2',
|
||||
},
|
||||
{
|
||||
id: 'doc3',
|
||||
|
@ -83,6 +83,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '.',
|
||||
sidebarPosition: 1,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc3',
|
||||
},
|
||||
{
|
||||
id: 'doc4',
|
||||
|
@ -90,6 +92,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '.',
|
||||
sidebarPosition: 1.5,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc4',
|
||||
},
|
||||
{
|
||||
id: 'doc5',
|
||||
|
@ -97,12 +101,12 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '.',
|
||||
sidebarPosition: undefined,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc5',
|
||||
},
|
||||
],
|
||||
options: {
|
||||
sidebarCollapsed: true,
|
||||
sidebarCollapsible: true,
|
||||
},
|
||||
isCategoryIndex: () => false,
|
||||
categoriesMetadata: {},
|
||||
});
|
||||
|
||||
expect(sidebarSlice).toMatchSnapshot();
|
||||
|
@ -144,6 +148,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '.',
|
||||
sidebarPosition: 0,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'intro',
|
||||
},
|
||||
{
|
||||
id: 'tutorials-index',
|
||||
|
@ -151,6 +157,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '01-Tutorials',
|
||||
sidebarPosition: 2,
|
||||
frontMatter: {},
|
||||
title: 'Tutorials',
|
||||
unversionedId: 'tutorials-index',
|
||||
},
|
||||
{
|
||||
id: 'tutorial2',
|
||||
|
@ -158,6 +166,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '01-Tutorials',
|
||||
sidebarPosition: 2,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'tutorial2',
|
||||
},
|
||||
{
|
||||
id: 'tutorial1',
|
||||
|
@ -165,12 +175,16 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '01-Tutorials',
|
||||
sidebarPosition: 1,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'tutorial1',
|
||||
},
|
||||
{
|
||||
id: 'guides-index',
|
||||
source: '@site/docs/02-Guides/02-Guides.md', // TODO should we allow to just use "Guides.md" to have an index?
|
||||
sourceDirName: '02-Guides',
|
||||
frontMatter: {},
|
||||
title: 'Guides',
|
||||
unversionedId: 'guides-index',
|
||||
},
|
||||
{
|
||||
id: 'guide2',
|
||||
|
@ -178,6 +192,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '02-Guides',
|
||||
sidebarPosition: 2,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'guide2',
|
||||
},
|
||||
{
|
||||
id: 'guide1',
|
||||
|
@ -187,6 +203,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
frontMatter: {
|
||||
sidebar_class_name: 'foo',
|
||||
},
|
||||
title: '',
|
||||
unversionedId: 'guide1',
|
||||
},
|
||||
{
|
||||
id: 'nested-guide',
|
||||
|
@ -194,6 +212,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '02-Guides/01-SubGuides',
|
||||
sidebarPosition: undefined,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'nested-guide',
|
||||
},
|
||||
{
|
||||
id: 'end',
|
||||
|
@ -201,12 +221,10 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '.',
|
||||
sidebarPosition: 3,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'end',
|
||||
},
|
||||
],
|
||||
options: {
|
||||
sidebarCollapsed: true,
|
||||
sidebarCollapsible: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(sidebarSlice).toMatchSnapshot();
|
||||
|
@ -249,6 +267,7 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
title: 'Subsubsubfolder category label',
|
||||
sidebarPosition: undefined,
|
||||
frontMatter: {},
|
||||
unversionedId: 'doc1',
|
||||
},
|
||||
{
|
||||
id: 'doc2',
|
||||
|
@ -256,6 +275,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: 'subfolder',
|
||||
sidebarPosition: undefined,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc2',
|
||||
},
|
||||
{
|
||||
id: 'doc3',
|
||||
|
@ -263,6 +284,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '.',
|
||||
sidebarPosition: undefined,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc2',
|
||||
},
|
||||
{
|
||||
id: 'doc4',
|
||||
|
@ -270,6 +293,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: 'subfolder/subsubfolder',
|
||||
sidebarPosition: undefined,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc4',
|
||||
},
|
||||
{
|
||||
id: 'doc5',
|
||||
|
@ -277,6 +302,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: 'subfolder/subsubfolder/subsubsubfolder',
|
||||
sidebarPosition: undefined,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc5',
|
||||
},
|
||||
{
|
||||
id: 'doc6',
|
||||
|
@ -284,6 +311,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: 'subfolder/subsubfolder/subsubsubfolder2',
|
||||
sidebarPosition: undefined,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc6',
|
||||
},
|
||||
{
|
||||
id: 'doc7',
|
||||
|
@ -291,6 +320,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: 'subfolder/subsubfolder/subsubsubfolder3',
|
||||
sidebarPosition: 2,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc7',
|
||||
},
|
||||
{
|
||||
id: 'doc8',
|
||||
|
@ -298,12 +329,10 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: 'subfolder/subsubfolder/subsubsubfolder3',
|
||||
sidebarPosition: 1,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'doc8',
|
||||
},
|
||||
],
|
||||
options: {
|
||||
sidebarCollapsed: true,
|
||||
sidebarCollapsible: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(sidebarSlice).toMatchSnapshot();
|
||||
|
@ -339,42 +368,51 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
source: '@site/docs/Category/index.md',
|
||||
sourceDirName: 'Category',
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'parent/doc1',
|
||||
},
|
||||
{
|
||||
id: 'parent/doc2',
|
||||
source: '@site/docs/Category/doc2.md',
|
||||
sourceDirName: 'Category',
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'parent/doc2',
|
||||
},
|
||||
{
|
||||
id: 'parent/doc3',
|
||||
source: '@site/docs/Category/doc3.md',
|
||||
sourceDirName: 'Category',
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'parent/doc3',
|
||||
},
|
||||
{
|
||||
id: 'parent/doc4',
|
||||
source: '@site/docs/Category2/doc1.md',
|
||||
sourceDirName: 'Category2',
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'parent/doc4',
|
||||
},
|
||||
{
|
||||
id: 'parent/doc5',
|
||||
source: '@site/docs/Category2/index.md',
|
||||
sourceDirName: 'Category2',
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'parent/doc5',
|
||||
},
|
||||
{
|
||||
id: 'parent/doc6',
|
||||
source: '@site/docs/Category2/doc3.md',
|
||||
sourceDirName: 'Category2',
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'parent/doc6',
|
||||
},
|
||||
],
|
||||
options: {
|
||||
sidebarCollapsed: true,
|
||||
sidebarCollapsible: true,
|
||||
},
|
||||
isCategoryIndex: () => false,
|
||||
});
|
||||
|
||||
expect(sidebarSlice).toMatchSnapshot();
|
||||
|
@ -387,7 +425,7 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
return (
|
||||
fileName.replace(
|
||||
`${DefaultNumberPrefixParser(
|
||||
directories[0],
|
||||
directories[0]!,
|
||||
).filename.toLowerCase()}-`,
|
||||
'',
|
||||
) === 'index'
|
||||
|
@ -409,6 +447,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '.',
|
||||
sidebarPosition: 0,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'intro',
|
||||
},
|
||||
{
|
||||
id: 'tutorials-index',
|
||||
|
@ -416,6 +456,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '01-Tutorials',
|
||||
sidebarPosition: 2,
|
||||
frontMatter: {},
|
||||
title: 'Tutorials',
|
||||
unversionedId: 'tutorials-index',
|
||||
},
|
||||
{
|
||||
id: 'tutorial2',
|
||||
|
@ -423,6 +465,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '01-Tutorials',
|
||||
sidebarPosition: 2,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'tutorial2',
|
||||
},
|
||||
{
|
||||
id: 'tutorial1',
|
||||
|
@ -430,12 +474,16 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '01-Tutorials',
|
||||
sidebarPosition: 1,
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
unversionedId: 'tutorial1',
|
||||
},
|
||||
{
|
||||
id: 'not-guides-index',
|
||||
source: '@site/docs/02-Guides/README.md',
|
||||
sourceDirName: '02-Guides',
|
||||
frontMatter: {},
|
||||
title: 'Guides',
|
||||
unversionedId: 'not-guides-index',
|
||||
},
|
||||
{
|
||||
id: 'guide2',
|
||||
|
@ -443,6 +491,8 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
sourceDirName: '02-Guides',
|
||||
sidebarPosition: 2,
|
||||
frontMatter: {},
|
||||
title: 'guide2',
|
||||
unversionedId: 'guide2',
|
||||
},
|
||||
{
|
||||
id: 'guide1',
|
||||
|
@ -452,12 +502,10 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
frontMatter: {
|
||||
sidebar_class_name: 'foo',
|
||||
},
|
||||
title: '',
|
||||
unversionedId: 'guide1',
|
||||
},
|
||||
],
|
||||
options: {
|
||||
sidebarCollapsed: true,
|
||||
sidebarCollapsible: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(sidebarSlice).toMatchSnapshot();
|
||||
|
@ -491,12 +539,9 @@ describe('DefaultSidebarItemsGenerator', () => {
|
|||
source: '@site/docs/category/intro.md',
|
||||
sourceDirName: 'category',
|
||||
frontMatter: {},
|
||||
title: '',
|
||||
},
|
||||
],
|
||||
options: {
|
||||
sidebarCollapsed: true,
|
||||
sidebarCollapsible: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(() => generateSidebar()).toThrowErrorMatchingInlineSnapshot(`
|
||||
|
|
|
@ -11,7 +11,10 @@ import {createSlugger} from '@docusaurus/utils';
|
|||
import {loadSidebars, DisabledSidebars} from '../index';
|
||||
import {DefaultSidebarItemsGenerator} from '../generator';
|
||||
import type {SidebarProcessorParams} from '../types';
|
||||
import type {DocMetadata} from '@docusaurus/plugin-content-docs';
|
||||
import type {
|
||||
DocMetadata,
|
||||
VersionMetadata,
|
||||
} from '@docusaurus/plugin-content-docs';
|
||||
|
||||
describe('loadSidebars', () => {
|
||||
const fixtureDir = path.join(__dirname, '__fixtures__', 'sidebars');
|
||||
|
@ -25,14 +28,14 @@ describe('loadSidebars', () => {
|
|||
id: 'bar',
|
||||
frontMatter: {},
|
||||
},
|
||||
],
|
||||
] as DocMetadata[],
|
||||
drafts: [],
|
||||
version: {
|
||||
path: 'version',
|
||||
contentPath: path.join(fixtureDir, 'docs'),
|
||||
contentPathLocalized: path.join(fixtureDir, 'docs'),
|
||||
},
|
||||
categoryLabelSlugger: null,
|
||||
} as VersionMetadata,
|
||||
categoryLabelSlugger: {slug: (v) => v},
|
||||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: true},
|
||||
};
|
||||
it('sidebars with known sidebar item type', async () => {
|
||||
|
@ -137,7 +140,7 @@ describe('loadSidebars', () => {
|
|||
sourceDirName: 'tutorials/tutorial-basics',
|
||||
frontMatter: {},
|
||||
},
|
||||
],
|
||||
] as DocMetadata[],
|
||||
});
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
@ -146,7 +149,7 @@ describe('loadSidebars', () => {
|
|||
const sidebarPath = path.join(fixtureDir, 'sidebars-drafts.json');
|
||||
const result = await loadSidebars(sidebarPath, {
|
||||
...params,
|
||||
drafts: [{id: 'draft1'}, {id: 'draft2'}, {id: 'draft3'}],
|
||||
drafts: [{id: 'draft1'}, {id: 'draft2'}, {id: 'draft3'}] as DocMetadata[],
|
||||
categoryLabelSlugger: createSlugger(),
|
||||
});
|
||||
expect(result).toMatchSnapshot();
|
||||
|
@ -169,7 +172,7 @@ describe('loadSidebars', () => {
|
|||
version: {
|
||||
contentPath: path.join(fixtureDir, 'invalid-docs'),
|
||||
contentPathLocalized: path.join(fixtureDir, 'invalid-docs'),
|
||||
},
|
||||
} as VersionMetadata,
|
||||
}),
|
||||
).rejects.toThrowErrorMatchingInlineSnapshot(`""foo" is not allowed"`);
|
||||
expect(consoleWarnMock).toBeCalledWith(
|
||||
|
|
|
@ -41,7 +41,9 @@ describe('normalization', () => {
|
|||
expect(() =>
|
||||
normalizeSidebars({
|
||||
sidebar: {
|
||||
// @ts-expect-error: test
|
||||
Category: {type: 'autogenerated', dirName: 'foo'},
|
||||
// @ts-expect-error: test
|
||||
Category2: {type: 'autogenerated', dirName: 'bar'},
|
||||
},
|
||||
}),
|
||||
|
@ -55,6 +57,7 @@ describe('normalization', () => {
|
|||
'foo',
|
||||
{
|
||||
Category: {
|
||||
// @ts-expect-error: test
|
||||
type: 'category',
|
||||
items: ['bar', 'baz'],
|
||||
},
|
||||
|
@ -70,6 +73,7 @@ describe('normalization', () => {
|
|||
sidebar: [
|
||||
'foo',
|
||||
{
|
||||
// @ts-expect-error: test
|
||||
Category: 'bar',
|
||||
},
|
||||
],
|
||||
|
@ -80,6 +84,7 @@ describe('normalization', () => {
|
|||
|
||||
expect(() =>
|
||||
normalizeSidebars({
|
||||
// @ts-expect-error: test
|
||||
sidebar: 'item',
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {postProcessSidebars} from '../postProcessor';
|
||||
import {
|
||||
postProcessSidebars,
|
||||
type SidebarPostProcessorParams,
|
||||
} from '../postProcessor';
|
||||
|
||||
describe('postProcess', () => {
|
||||
it('transforms category without subitems', () => {
|
||||
|
@ -36,7 +39,7 @@ describe('postProcess', () => {
|
|||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: true},
|
||||
version: {path: 'version'},
|
||||
drafts: [],
|
||||
},
|
||||
} as unknown as SidebarPostProcessorParams,
|
||||
);
|
||||
|
||||
expect(processedSidebar).toMatchSnapshot();
|
||||
|
@ -56,7 +59,7 @@ describe('postProcess', () => {
|
|||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: true},
|
||||
version: {path: 'version'},
|
||||
drafts: [],
|
||||
},
|
||||
} as unknown as SidebarPostProcessorParams,
|
||||
);
|
||||
}).toThrowErrorMatchingInlineSnapshot(
|
||||
`"Sidebar category Bad category has neither any subitem nor a link. This makes this item not able to link to anything."`,
|
||||
|
@ -82,7 +85,7 @@ describe('postProcess', () => {
|
|||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: true},
|
||||
version: {path: 'version'},
|
||||
drafts: [],
|
||||
},
|
||||
} as unknown as SidebarPostProcessorParams,
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
|
||||
|
@ -103,7 +106,7 @@ describe('postProcess', () => {
|
|||
sidebarOptions: {sidebarCollapsed: false, sidebarCollapsible: false},
|
||||
version: {path: 'version'},
|
||||
drafts: [],
|
||||
},
|
||||
} as unknown as SidebarPostProcessorParams,
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
|
||||
|
@ -123,7 +126,7 @@ describe('postProcess', () => {
|
|||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: false},
|
||||
version: {path: 'version'},
|
||||
drafts: [],
|
||||
},
|
||||
} as unknown as SidebarPostProcessorParams,
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
@ -153,7 +156,7 @@ describe('postProcess', () => {
|
|||
sidebarOptions: {sidebarCollapsed: true, sidebarCollapsible: true},
|
||||
version: {path: 'version'},
|
||||
drafts: [{id: 'foo', unversionedId: 'foo'}],
|
||||
},
|
||||
} as unknown as SidebarPostProcessorParams,
|
||||
),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@ import {DefaultSidebarItemsGenerator} from '../generator';
|
|||
import {DefaultNumberPrefixParser} from '../../numberPrefix';
|
||||
import {isCategoryIndex} from '../../docs';
|
||||
import type {
|
||||
SidebarItem,
|
||||
Sidebar,
|
||||
SidebarItemsGenerator,
|
||||
NormalizedSidebar,
|
||||
NormalizedSidebars,
|
||||
|
@ -24,12 +24,12 @@ import type {VersionMetadata} from '@docusaurus/plugin-content-docs';
|
|||
|
||||
describe('processSidebars', () => {
|
||||
function createStaticSidebarItemGenerator(
|
||||
sidebarSlice: SidebarItem[],
|
||||
sidebarSlice: NormalizedSidebar,
|
||||
): SidebarItemsGenerator {
|
||||
return jest.fn(() => sidebarSlice);
|
||||
}
|
||||
|
||||
const StaticGeneratedSidebarSlice: NormalizedSidebar = [
|
||||
const StaticGeneratedSidebarSlice: Sidebar = [
|
||||
{type: 'doc', id: 'doc-generated-id-1'},
|
||||
{type: 'doc', id: 'doc-generated-id-2'},
|
||||
];
|
||||
|
@ -215,7 +215,7 @@ describe('processSidebars', () => {
|
|||
},
|
||||
];
|
||||
|
||||
const unprocessedSidebars = {
|
||||
const unprocessedSidebars: NormalizedSidebars = {
|
||||
someSidebar: [{type: 'autogenerated', dirName: 'dir2'}],
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ import type {
|
|||
SidebarItemCategoryLink,
|
||||
} from './types';
|
||||
|
||||
type SidebarPostProcessorParams = SidebarProcessorParams & {
|
||||
export type SidebarPostProcessorParams = SidebarProcessorParams & {
|
||||
draftIds: Set<string>;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue