docusaurus/packages/docusaurus-plugin-content-docs/src/__tests__/globalData.test.ts
Jody Heavener 683ba3d2a0
feat(docs,blog,pages): add support for "unlisted" front matter - hide md content in production (#8004)
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
2022-11-03 14:31:41 +01:00

127 lines
3.1 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {toGlobalDataVersion} from '../globalData';
import {createSidebarsUtils} from '../sidebars/utils';
import {getCategoryGeneratedIndexMetadataList} from '../categoryGeneratedIndex';
import type {Sidebars} from '../sidebars/types';
import type {DocMetadata} from '@docusaurus/plugin-content-docs';
describe('toGlobalDataVersion', () => {
it('generates the right docs, sidebars, and metadata', () => {
const docs = [
{
unversionedId: 'main',
permalink: '/current/main',
sidebar: 'tutorial',
frontMatter: {},
unlisted: false,
},
{
unversionedId: 'doc',
permalink: '/current/doc',
sidebar: 'tutorial',
frontMatter: {},
unlisted: undefined,
},
{
unversionedId: 'docNoSidebarUnlisted',
permalink: '/current/docNoSidebarUnlisted',
sidebar: undefined,
frontMatter: {},
unlisted: true,
},
] as DocMetadata[];
const sidebars: Sidebars = {
tutorial: [
{
type: 'doc',
id: 'main',
},
{
type: 'category',
label: 'Generated',
link: {
type: 'generated-index',
permalink: '/current/generated',
slug: '/current/generated',
},
items: [
{
type: 'doc',
id: 'doc',
},
],
collapsed: false,
collapsible: true,
},
],
links: [
{
type: 'link',
href: 'foo',
label: 'Foo',
},
{
type: 'link',
href: 'bar',
label: 'Bar',
},
],
another: [
{
type: 'category',
label: 'Generated',
link: {
type: 'generated-index',
permalink: '/current/generated-2',
slug: '/current/generated-2',
},
items: [
{
type: 'doc',
id: 'doc',
},
],
collapsed: false,
collapsible: true,
},
],
};
const sidebarsUtils = createSidebarsUtils(sidebars);
expect(
toGlobalDataVersion({
versionName: 'current',
label: 'Label',
isLast: true,
path: '/current',
docs,
drafts: [
{
unversionedId: 'some-draft-id',
permalink: '/current/draft',
sidebar: undefined,
},
] as DocMetadata[],
sidebars,
categoryGeneratedIndices: getCategoryGeneratedIndexMetadataList({
docs,
sidebarsUtils,
}),
sidebarsUtils,
banner: 'unreleased',
badge: true,
className: 'current-cls',
tagsPath: '/current/tags',
contentPath: '',
contentPathLocalized: '',
sidebarFilePath: '',
routePriority: 0.5,
}),
).toMatchSnapshot();
});
});