test(content-docs): refactor navigation test snapshot (#6821)

* test(content-docs): refactor navigation test snapshot

* format
This commit is contained in:
Joshua Chen 2022-03-03 14:00:42 +08:00 committed by GitHub
parent 1c91d2f20e
commit f04cb7abb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 250 additions and 145 deletions

View file

@ -1,144 +1,244 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`simple site custom pagination 1`] = ` exports[`simple site custom pagination 1`] = `
Array [ Object {
Array [ "pagination": Array [
undefined,
Object { Object {
"permalink": "/docs/headingAsTitle", "id": "doc with space",
"title": "My heading as title", "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",
},
}, },
], ],
Array [ "sidebars": Object {
undefined, "defaultSidebar": Array [
undefined, Object {
], "id": "doc with space",
Array [ "type": "doc",
Object { },
"permalink": "/docs/foo/bar", Object {
"title": "Bar", "id": "headingAsTitle",
}, "type": "doc",
Object { },
"permalink": "/docs/absoluteSlug", Object {
"title": "absoluteSlug", "id": "hello",
}, "label": "Hello sidebar_label",
], "type": "doc",
Array [ },
Object { Object {
"permalink": "/docs/doc with space", "id": "ipsum",
"title": "Hoo hoo, if this path tricks you...", "type": "doc",
}, },
Object { Object {
"permalink": "/docs/", "id": "lorem",
"title": "Hello sidebar_label", "type": "doc",
}, },
], Object {
Array [ "id": "rootAbsoluteSlug",
Object { "type": "doc",
"permalink": "/docs/headingAsTitle", },
"title": "My heading as title", Object {
}, "id": "rootRelativeSlug",
Object { "type": "doc",
"permalink": "/docs/ipsum", },
"title": "ipsum", Object {
}, "id": "rootResolvedSlug",
], "type": "doc",
Array [ },
Object { Object {
"permalink": "/docs/", "id": "rootTryToEscapeSlug",
"title": "Hello sidebar_label", "type": "doc",
}, },
Object { Object {
"permalink": "/docs/lorem", "collapsed": false,
"title": "lorem", "collapsible": true,
}, "items": Array [
], Object {
Array [ "id": "foo/bar",
Object { "type": "doc",
"permalink": "/docs/ipsum", },
"title": "ipsum", Object {
}, "id": "foo/baz",
Object { "type": "doc",
"permalink": "/docs/rootAbsoluteSlug", },
"title": "rootAbsoluteSlug", ],
}, "label": "foo",
], "link": undefined,
Array [ "type": "category",
Object { },
"permalink": "/docs/foo/bazSlug.html", Object {
"title": "baz pagination_label", "collapsed": false,
}, "collapsible": true,
Object { "items": Array [
"permalink": "/docs/headingAsTitle", Object {
"title": "My heading as title", "id": "slugs/absoluteSlug",
}, "type": "doc",
], },
Array [ Object {
Object { "id": "slugs/relativeSlug",
"permalink": "/docs/foo/bazSlug.html", "type": "doc",
"title": "baz pagination_label", },
}, Object {
Object { "id": "slugs/resolvedSlug",
"permalink": "/docs/headingAsTitle", "type": "doc",
"title": "My heading as title", },
}, Object {
], "id": "slugs/tryToEscapeSlug",
Array [ "type": "doc",
Object { },
"permalink": "/docs/foo/bazSlug.html", ],
"title": "baz pagination_label", "label": "slugs",
}, "link": undefined,
Object { "type": "category",
"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",
},
undefined,
],
]
`; `;

View file

@ -15,6 +15,7 @@ import {
isCategoryIndex, isCategoryIndex,
} from '../docs'; } from '../docs';
import {loadSidebars} from '../sidebars'; import {loadSidebars} from '../sidebars';
import type {Sidebars} from '../sidebars/types';
import {readVersionsMetadata} from '../versions'; import {readVersionsMetadata} from '../versions';
import type { import type {
DocFile, DocFile,
@ -120,9 +121,10 @@ function createTestUtils({
expect(metadata.permalink).toEqual(expectedPermalink); expect(metadata.permalink).toEqual(expectedPermalink);
} }
async function generateNavigation( async function generateNavigation(docFiles: DocFile[]): Promise<{
docFiles: DocFile[], pagination: {prev?: DocNavLink; next?: DocNavLink; id: string}[];
): Promise<[DocNavLink | undefined, DocNavLink | undefined][]> { sidebars: Sidebars;
}> {
const rawDocs = docFiles.map((docFile) => const rawDocs = docFiles.map((docFile) =>
processDocMetadata({ processDocMetadata({
docFile, docFile,
@ -145,11 +147,14 @@ function createTestUtils({
}); });
const sidebarsUtils = createSidebarsUtils(sidebars); const sidebarsUtils = createSidebarsUtils(sidebars);
return addDocNavigation( return {
rawDocs, pagination: addDocNavigation(
sidebarsUtils, rawDocs,
versionMetadata.sidebarFilePath as string, sidebarsUtils,
).map((doc) => [doc.previous, doc.next]); versionMetadata.sidebarFilePath as string,
).map((doc) => ({prev: doc.previous, next: doc.next, id: doc.id})),
sidebars,
};
} }
return {processDocFile, testMeta, testSlug, generateNavigation}; return {processDocFile, testMeta, testSlug, generateNavigation};