mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
feat(content-docs): allow omitting enclosing array consistently for category shorthand (#6602)
* feat(content-docs): allow omitting enclosing array consistently for category shorthand * update snapshot * fix doc
This commit is contained in:
parent
e3fd3e74ce
commit
0c4dc00443
6 changed files with 302 additions and 80 deletions
|
@ -0,0 +1,96 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`normalization normalizes shorthands 1`] = `
|
||||
Object {
|
||||
"sidebar": Array [
|
||||
Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "doc1",
|
||||
"type": "doc",
|
||||
},
|
||||
Object {
|
||||
"id": "doc2",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Category",
|
||||
"type": "category",
|
||||
},
|
||||
Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "doc3",
|
||||
"type": "doc",
|
||||
},
|
||||
Object {
|
||||
"id": "doc4",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Subcategory 1",
|
||||
"type": "category",
|
||||
},
|
||||
Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "doc5",
|
||||
"type": "doc",
|
||||
},
|
||||
Object {
|
||||
"id": "doc6",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Subcategory 2",
|
||||
"type": "category",
|
||||
},
|
||||
],
|
||||
"label": "Category 2",
|
||||
"type": "category",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`normalization normalizes shorthands 2`] = `
|
||||
Object {
|
||||
"sidebar": Array [
|
||||
Object {
|
||||
"href": "https://google.com",
|
||||
"label": "Google",
|
||||
"type": "link",
|
||||
},
|
||||
Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "doc1",
|
||||
"type": "doc",
|
||||
},
|
||||
Object {
|
||||
"id": "doc2",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Category 1",
|
||||
"type": "category",
|
||||
},
|
||||
Object {
|
||||
"items": Array [
|
||||
Object {
|
||||
"id": "doc3",
|
||||
"type": "doc",
|
||||
},
|
||||
Object {
|
||||
"id": "doc4",
|
||||
"type": "doc",
|
||||
},
|
||||
],
|
||||
"label": "Category 2",
|
||||
"type": "category",
|
||||
},
|
||||
],
|
||||
}
|
||||
`;
|
|
@ -58,7 +58,7 @@ describe('loadSidebars', () => {
|
|||
await expect(() =>
|
||||
loadSidebars(sidebarPath, params),
|
||||
).rejects.toThrowErrorMatchingInlineSnapshot(
|
||||
`"Invalid category {\\"type\\":\\"category\\",\\"label\\":\\"Category Label\\",\\"items\\":\\"doc1\\"}: items must be an array"`,
|
||||
`"Invalid category {\\"type\\":\\"category\\",\\"label\\":\\"Category Label\\",\\"items\\":\\"doc1\\"}: items must be an array of sidebar items or a category shorthand"`,
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* 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 {normalizeSidebars} from '../normalization';
|
||||
|
||||
describe('normalization', () => {
|
||||
test('normalizes shorthands', () => {
|
||||
expect(
|
||||
normalizeSidebars({
|
||||
sidebar: {
|
||||
Category: ['doc1', 'doc2'],
|
||||
'Category 2': {
|
||||
'Subcategory 1': ['doc3', 'doc4'],
|
||||
'Subcategory 2': ['doc5', 'doc6'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toMatchSnapshot();
|
||||
|
||||
expect(
|
||||
normalizeSidebars({
|
||||
sidebar: [
|
||||
{
|
||||
type: 'link',
|
||||
label: 'Google',
|
||||
href: 'https://google.com',
|
||||
},
|
||||
{
|
||||
'Category 1': ['doc1', 'doc2'],
|
||||
'Category 2': ['doc3', 'doc4'],
|
||||
},
|
||||
],
|
||||
}),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue