test(v2): test different type of sidebar item

This commit is contained in:
endiliey 2019-05-15 19:16:28 +08:00
parent f47059b5bd
commit badb067b4b
5 changed files with 58 additions and 8 deletions

View file

@ -0,0 +1,14 @@
{
"docs": {
"Test": [
"foo/bar",
"foo/baz",
{
"type": "superman"
}
],
"Guides": [
"hello"
]
}
}

View file

@ -2,7 +2,16 @@
"docs": { "docs": {
"Test": [ "Test": [
"foo/bar", "foo/bar",
"foo/baz" "foo/baz",
{
"type": "link",
"label": "Github",
"href": "https://github.com"
},
{
"type": "ref",
"id": "hello"
}
], ],
"Guides": [ "Guides": [
"hello" "hello"

View file

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`loadSidebars normal site with sidebars 1`] = ` exports[`loadSidebars sidebars with known sidebar item type 1`] = `
Object { Object {
"docs": Array [ "docs": Array [
Object { Object {
@ -13,6 +13,15 @@ Object {
"id": "foo/baz", "id": "foo/baz",
"type": "doc", "type": "doc",
}, },
Object {
"href": "https://github.com",
"label": "Github",
"type": "link",
},
Object {
"id": "hello",
"type": "ref",
},
], ],
"label": "Test", "label": "Test",
"type": "category", "type": "category",
@ -30,5 +39,3 @@ Object {
], ],
} }
`; `;
exports[`loadSidebars site without sidebars 1`] = `Object {}`;

View file

@ -11,7 +11,7 @@ import loadSidebars from '../sidebars';
/* eslint-disable global-require, import/no-dynamic-require */ /* eslint-disable global-require, import/no-dynamic-require */
describe('loadSidebars', () => { describe('loadSidebars', () => {
test('normal site with sidebars', async () => { test('sidebars with known sidebar item type', async () => {
const sidebarPath = path.join( const sidebarPath = path.join(
__dirname, __dirname,
'__fixtures__', '__fixtures__',
@ -22,8 +22,20 @@ describe('loadSidebars', () => {
expect(result).toMatchSnapshot(); expect(result).toMatchSnapshot();
}); });
test('site without sidebars', () => { test('sidebars with unknown sidebar item type', async () => {
const sidebarPath = path.join(
__dirname,
'__fixtures__',
'website',
'bad-sidebars.json',
);
expect(() => loadSidebars(sidebarPath)).toThrowErrorMatchingInlineSnapshot(
`"Unknown sidebar item type: superman"`,
);
});
test('no sidebars', () => {
const result = loadSidebars(null); const result = loadSidebars(null);
expect(result).toMatchSnapshot(); expect(result).toEqual({});
}); });
}); });

View file

@ -14,7 +14,15 @@ module.exports = {
'deployment', 'deployment',
], ],
Guides: [ Guides: [
'configuration', {
type: 'link',
label: 'Github',
href: 'http://github.com',
},
{
type: 'ref',
id: 'configuration',
},
'creating-pages', 'creating-pages',
'writing-documentation', 'writing-documentation',
'assets', 'assets',