From badb067b4b9d43d43d3809150aeb4fc421fd255c Mon Sep 17 00:00:00 2001 From: endiliey Date: Wed, 15 May 2019 19:16:28 +0800 Subject: [PATCH] test(v2): test different type of sidebar item --- .../__fixtures__/website/bad-sidebars.json | 14 ++++++++++++++ .../__fixtures__/website/sidebars.json | 11 ++++++++++- .../__snapshots__/sidebars.test.js.snap | 13 ++++++++++--- .../src/__tests__/sidebars.test.js | 18 +++++++++++++++--- website/sidebars.js | 10 +++++++++- 5 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/website/bad-sidebars.json diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/website/bad-sidebars.json b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/website/bad-sidebars.json new file mode 100644 index 0000000000..618c52d817 --- /dev/null +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/website/bad-sidebars.json @@ -0,0 +1,14 @@ +{ + "docs": { + "Test": [ + "foo/bar", + "foo/baz", + { + "type": "superman" + } + ], + "Guides": [ + "hello" + ] + } +} diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/website/sidebars.json b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/website/sidebars.json index 24d61b49c7..e355c9b3f0 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/website/sidebars.json +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/website/sidebars.json @@ -2,7 +2,16 @@ "docs": { "Test": [ "foo/bar", - "foo/baz" + "foo/baz", + { + "type": "link", + "label": "Github", + "href": "https://github.com" + }, + { + "type": "ref", + "id": "hello" + } ], "Guides": [ "hello" diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.js.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.js.snap index 60217ba1d2..7e05bac63a 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.js.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/sidebars.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`loadSidebars normal site with sidebars 1`] = ` +exports[`loadSidebars sidebars with known sidebar item type 1`] = ` Object { "docs": Array [ Object { @@ -13,6 +13,15 @@ Object { "id": "foo/baz", "type": "doc", }, + Object { + "href": "https://github.com", + "label": "Github", + "type": "link", + }, + Object { + "id": "hello", + "type": "ref", + }, ], "label": "Test", "type": "category", @@ -30,5 +39,3 @@ Object { ], } `; - -exports[`loadSidebars site without sidebars 1`] = `Object {}`; diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.js b/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.js index 2893284382..da6b5ae560 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.js +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/sidebars.test.js @@ -11,7 +11,7 @@ import loadSidebars from '../sidebars'; /* eslint-disable global-require, import/no-dynamic-require */ describe('loadSidebars', () => { - test('normal site with sidebars', async () => { + test('sidebars with known sidebar item type', async () => { const sidebarPath = path.join( __dirname, '__fixtures__', @@ -22,8 +22,20 @@ describe('loadSidebars', () => { 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); - expect(result).toMatchSnapshot(); + expect(result).toEqual({}); }); }); diff --git a/website/sidebars.js b/website/sidebars.js index de77ec0c41..2f27e1f85e 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -14,7 +14,15 @@ module.exports = { 'deployment', ], Guides: [ - 'configuration', + { + type: 'link', + label: 'Github', + href: 'http://github.com', + }, + { + type: 'ref', + id: 'configuration', + }, 'creating-pages', 'writing-documentation', 'assets',