From 8c5992376280712a2496f946bba4e455d16ca26c Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Thu, 3 Mar 2022 13:04:12 +0800 Subject: [PATCH 1/2] test(content-docs): refactor navigation test snapshot --- .../__tests__/__snapshots__/docs.test.ts.snap | 376 +++++++++++------- .../src/__tests__/docs.test.ts | 19 +- 2 files changed, 251 insertions(+), 144 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap index d8ad2b8a3ee8..c7e31631032c 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/docs.test.ts.snap @@ -1,144 +1,244 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`simple site custom pagination 1`] = ` -Array [ - Array [ - undefined, - Object { - "permalink": "/docs/headingAsTitle", - "title": "My heading as title", - }, - ], - Array [ - undefined, - undefined, - ], - Array [ - Object { - "permalink": "/docs/foo/bar", - "title": "Bar", - }, - Object { - "permalink": "/docs/absoluteSlug", - "title": "absoluteSlug", - }, - ], - Array [ - Object { - "permalink": "/docs/doc with space", - "title": "Hoo hoo, if this path tricks you...", - }, - Object { - "permalink": "/docs/", - "title": "Hello sidebar_label", - }, - ], - Array [ - Object { - "permalink": "/docs/headingAsTitle", - "title": "My heading as title", - }, - Object { - "permalink": "/docs/ipsum", - "title": "ipsum", - }, - ], - Array [ - Object { - "permalink": "/docs/", - "title": "Hello sidebar_label", - }, - Object { - "permalink": "/docs/lorem", - "title": "lorem", - }, - ], - Array [ - Object { - "permalink": "/docs/ipsum", - "title": "ipsum", - }, - Object { - "permalink": "/docs/rootAbsoluteSlug", - "title": "rootAbsoluteSlug", - }, - ], - Array [ - Object { - "permalink": "/docs/foo/bazSlug.html", - "title": "baz pagination_label", - }, - Object { - "permalink": "/docs/headingAsTitle", - "title": "My heading as title", - }, - ], - Array [ - Object { - "permalink": "/docs/foo/bazSlug.html", - "title": "baz pagination_label", - }, - Object { - "permalink": "/docs/headingAsTitle", - "title": "My heading as title", - }, - ], - Array [ - Object { - "permalink": "/docs/foo/bazSlug.html", - "title": "baz pagination_label", - }, - Object { - "permalink": "/docs/headingAsTitle", - "title": "My heading as title", - }, - ], - Array [ - Object { - "permalink": "/docs/foo/bazSlug.html", - "title": "baz pagination_label", - }, - Object { - "permalink": "/docs/headingAsTitle", - "title": "My heading as title", - }, - ], - Array [ - Object { - "permalink": "/docs/foo/bazSlug.html", - "title": "baz pagination_label", - }, - Object { - "permalink": "/docs/slugs/relativeSlug", - "title": "relativeSlug", - }, - ], - Array [ - Object { - "permalink": "/docs/absoluteSlug", - "title": "absoluteSlug", - }, - Object { - "permalink": "/docs/slugs/hey/resolvedSlug", - "title": "resolvedSlug", - }, - ], - Array [ - Object { - "permalink": "/docs/slugs/relativeSlug", - "title": "relativeSlug", - }, - Object { - "permalink": "/docs/tryToEscapeSlug", - "title": "tryToEscapeSlug", - }, - ], - Array [ - Object { - "permalink": "/docs/slugs/hey/resolvedSlug", - "title": "resolvedSlug", +Object { + "pagination": Array [ + Object { + "id": "doc with space", + "next": Object { + "permalink": "/docs/headingAsTitle", + "title": "My heading as title", + }, + "prev": undefined, + }, + Object { + "id": "foo/bar", + "next": undefined, + "prev": undefined, + }, + Object { + "id": "foo/baz", + "next": Object { + "permalink": "/docs/absoluteSlug", + "title": "absoluteSlug", + }, + "prev": Object { + "permalink": "/docs/foo/bar", + "title": "Bar", + }, + }, + Object { + "id": "headingAsTitle", + "next": Object { + "permalink": "/docs/", + "title": "Hello sidebar_label", + }, + "prev": Object { + "permalink": "/docs/doc with space", + "title": "Hoo hoo, if this path tricks you...", + }, + }, + Object { + "id": "hello", + "next": Object { + "permalink": "/docs/ipsum", + "title": "ipsum", + }, + "prev": Object { + "permalink": "/docs/headingAsTitle", + "title": "My heading as title", + }, + }, + Object { + "id": "ipsum", + "next": Object { + "permalink": "/docs/lorem", + "title": "lorem", + }, + "prev": Object { + "permalink": "/docs/", + "title": "Hello sidebar_label", + }, + }, + Object { + "id": "lorem", + "next": Object { + "permalink": "/docs/rootAbsoluteSlug", + "title": "rootAbsoluteSlug", + }, + "prev": Object { + "permalink": "/docs/ipsum", + "title": "ipsum", + }, + }, + Object { + "id": "rootAbsoluteSlug", + "next": Object { + "permalink": "/docs/headingAsTitle", + "title": "My heading as title", + }, + "prev": Object { + "permalink": "/docs/foo/bazSlug.html", + "title": "baz pagination_label", + }, + }, + Object { + "id": "rootRelativeSlug", + "next": Object { + "permalink": "/docs/headingAsTitle", + "title": "My heading as title", + }, + "prev": Object { + "permalink": "/docs/foo/bazSlug.html", + "title": "baz pagination_label", + }, + }, + Object { + "id": "rootResolvedSlug", + "next": Object { + "permalink": "/docs/headingAsTitle", + "title": "My heading as title", + }, + "prev": Object { + "permalink": "/docs/foo/bazSlug.html", + "title": "baz pagination_label", + }, + }, + Object { + "id": "rootTryToEscapeSlug", + "next": Object { + "permalink": "/docs/headingAsTitle", + "title": "My heading as title", + }, + "prev": Object { + "permalink": "/docs/foo/bazSlug.html", + "title": "baz pagination_label", + }, + }, + Object { + "id": "slugs/absoluteSlug", + "next": Object { + "permalink": "/docs/slugs/relativeSlug", + "title": "relativeSlug", + }, + "prev": Object { + "permalink": "/docs/foo/bazSlug.html", + "title": "baz pagination_label", + }, + }, + Object { + "id": "slugs/relativeSlug", + "next": Object { + "permalink": "/docs/slugs/hey/resolvedSlug", + "title": "resolvedSlug", + }, + "prev": Object { + "permalink": "/docs/absoluteSlug", + "title": "absoluteSlug", + }, + }, + Object { + "id": "slugs/resolvedSlug", + "next": Object { + "permalink": "/docs/tryToEscapeSlug", + "title": "tryToEscapeSlug", + }, + "prev": Object { + "permalink": "/docs/slugs/relativeSlug", + "title": "relativeSlug", + }, + }, + Object { + "id": "slugs/tryToEscapeSlug", + "next": undefined, + "prev": Object { + "permalink": "/docs/slugs/hey/resolvedSlug", + "title": "resolvedSlug", + }, }, - undefined, ], -] + "sidebars": Object { + "defaultSidebar": Array [ + Object { + "id": "doc with space", + "type": "doc", + }, + Object { + "id": "headingAsTitle", + "type": "doc", + }, + Object { + "id": "hello", + "label": "Hello sidebar_label", + "type": "doc", + }, + Object { + "id": "ipsum", + "type": "doc", + }, + Object { + "id": "lorem", + "type": "doc", + }, + Object { + "id": "rootAbsoluteSlug", + "type": "doc", + }, + Object { + "id": "rootRelativeSlug", + "type": "doc", + }, + Object { + "id": "rootResolvedSlug", + "type": "doc", + }, + Object { + "id": "rootTryToEscapeSlug", + "type": "doc", + }, + Object { + "collapsed": false, + "collapsible": true, + "items": Array [ + Object { + "id": "foo/bar", + "type": "doc", + }, + Object { + "id": "foo/baz", + "type": "doc", + }, + ], + "label": "foo", + "link": undefined, + "type": "category", + }, + Object { + "collapsed": false, + "collapsible": true, + "items": Array [ + Object { + "id": "slugs/absoluteSlug", + "type": "doc", + }, + Object { + "id": "slugs/relativeSlug", + "type": "doc", + }, + Object { + "id": "slugs/resolvedSlug", + "type": "doc", + }, + Object { + "id": "slugs/tryToEscapeSlug", + "type": "doc", + }, + ], + "label": "slugs", + "link": undefined, + "type": "category", + }, + ], + }, +} `; diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts index ac0c3724998f..93ce5bea3892 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts @@ -15,6 +15,7 @@ import { isCategoryIndex, } from '../docs'; import {loadSidebars} from '../sidebars'; +import type {Sidebars} from '../sidebars/types'; import {readVersionsMetadata} from '../versions'; import type { DocFile, @@ -122,7 +123,10 @@ function createTestUtils({ async function generateNavigation( docFiles: DocFile[], - ): Promise<[DocNavLink | undefined, DocNavLink | undefined][]> { + ): Promise<{ + pagination: {prev?: DocNavLink; next?: DocNavLink; id: string}[]; + sidebars: Sidebars; + }> { const rawDocs = docFiles.map((docFile) => processDocMetadata({ docFile, @@ -145,11 +149,14 @@ function createTestUtils({ }); const sidebarsUtils = createSidebarsUtils(sidebars); - return addDocNavigation( - rawDocs, - sidebarsUtils, - versionMetadata.sidebarFilePath as string, - ).map((doc) => [doc.previous, doc.next]); + return { + pagination: addDocNavigation( + rawDocs, + sidebarsUtils, + versionMetadata.sidebarFilePath as string, + ).map((doc) => ({prev: doc.previous, next: doc.next, id: doc.id})), + sidebars, + }; } return {processDocFile, testMeta, testSlug, generateNavigation}; From 4b09efb52c60e218ab1664fc57120497882a9861 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Thu, 3 Mar 2022 13:14:24 +0800 Subject: [PATCH 2/2] format --- .../docusaurus-plugin-content-docs/src/__tests__/docs.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts index 93ce5bea3892..0c1d36d50a40 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts @@ -121,9 +121,7 @@ function createTestUtils({ expect(metadata.permalink).toEqual(expectedPermalink); } - async function generateNavigation( - docFiles: DocFile[], - ): Promise<{ + async function generateNavigation(docFiles: DocFile[]): Promise<{ pagination: {prev?: DocNavLink; next?: DocNavLink; id: string}[]; sidebars: Sidebars; }> {