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 [
Array [
undefined,
Object { Object {
"pagination": Array [
Object {
"id": "doc with space",
"next": Object {
"permalink": "/docs/headingAsTitle", "permalink": "/docs/headingAsTitle",
"title": "My heading as title", "title": "My heading as title",
}, },
], "prev": undefined,
Array [ },
undefined,
undefined,
],
Array [
Object { 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", "permalink": "/docs/foo/bar",
"title": "Bar", "title": "Bar",
}, },
Object {
"permalink": "/docs/absoluteSlug",
"title": "absoluteSlug",
}, },
],
Array [
Object { Object {
"id": "headingAsTitle",
"next": Object {
"permalink": "/docs/",
"title": "Hello sidebar_label",
},
"prev": Object {
"permalink": "/docs/doc with space", "permalink": "/docs/doc with space",
"title": "Hoo hoo, if this path tricks you...", "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 { Object {
"id": "hello",
"next": Object {
"permalink": "/docs/ipsum", "permalink": "/docs/ipsum",
"title": "ipsum", "title": "ipsum",
}, },
], "prev": Object {
Array [ "permalink": "/docs/headingAsTitle",
Object { "title": "My heading as title",
"permalink": "/docs/", },
"title": "Hello sidebar_label",
}, },
Object { Object {
"id": "ipsum",
"next": Object {
"permalink": "/docs/lorem", "permalink": "/docs/lorem",
"title": "lorem", "title": "lorem",
}, },
], "prev": Object {
Array [ "permalink": "/docs/",
Object { "title": "Hello sidebar_label",
"permalink": "/docs/ipsum", },
"title": "ipsum",
}, },
Object { Object {
"id": "lorem",
"next": Object {
"permalink": "/docs/rootAbsoluteSlug", "permalink": "/docs/rootAbsoluteSlug",
"title": "rootAbsoluteSlug", "title": "rootAbsoluteSlug",
}, },
], "prev": Object {
Array [ "permalink": "/docs/ipsum",
Object { "title": "ipsum",
"permalink": "/docs/foo/bazSlug.html", },
"title": "baz pagination_label",
}, },
Object { Object {
"id": "rootAbsoluteSlug",
"next": Object {
"permalink": "/docs/headingAsTitle", "permalink": "/docs/headingAsTitle",
"title": "My heading as title", "title": "My heading as title",
}, },
], "prev": Object {
Array [
Object {
"permalink": "/docs/foo/bazSlug.html", "permalink": "/docs/foo/bazSlug.html",
"title": "baz pagination_label", "title": "baz pagination_label",
}, },
},
Object { Object {
"id": "rootRelativeSlug",
"next": Object {
"permalink": "/docs/headingAsTitle", "permalink": "/docs/headingAsTitle",
"title": "My heading as title", "title": "My heading as title",
}, },
], "prev": Object {
Array [
Object {
"permalink": "/docs/foo/bazSlug.html", "permalink": "/docs/foo/bazSlug.html",
"title": "baz pagination_label", "title": "baz pagination_label",
}, },
},
Object { Object {
"id": "rootResolvedSlug",
"next": Object {
"permalink": "/docs/headingAsTitle", "permalink": "/docs/headingAsTitle",
"title": "My heading as title", "title": "My heading as title",
}, },
], "prev": Object {
Array [
Object {
"permalink": "/docs/foo/bazSlug.html", "permalink": "/docs/foo/bazSlug.html",
"title": "baz pagination_label", "title": "baz pagination_label",
}, },
},
Object { Object {
"id": "rootTryToEscapeSlug",
"next": Object {
"permalink": "/docs/headingAsTitle", "permalink": "/docs/headingAsTitle",
"title": "My heading as title", "title": "My heading as title",
}, },
], "prev": Object {
Array [
Object {
"permalink": "/docs/foo/bazSlug.html", "permalink": "/docs/foo/bazSlug.html",
"title": "baz pagination_label", "title": "baz pagination_label",
}, },
},
Object { Object {
"id": "slugs/absoluteSlug",
"next": Object {
"permalink": "/docs/slugs/relativeSlug", "permalink": "/docs/slugs/relativeSlug",
"title": "relativeSlug", "title": "relativeSlug",
}, },
], "prev": Object {
Array [ "permalink": "/docs/foo/bazSlug.html",
"title": "baz pagination_label",
},
},
Object { Object {
"id": "slugs/relativeSlug",
"next": Object {
"permalink": "/docs/slugs/hey/resolvedSlug",
"title": "resolvedSlug",
},
"prev": Object {
"permalink": "/docs/absoluteSlug", "permalink": "/docs/absoluteSlug",
"title": "absoluteSlug", "title": "absoluteSlug",
}, },
Object {
"permalink": "/docs/slugs/hey/resolvedSlug",
"title": "resolvedSlug",
},
],
Array [
Object {
"permalink": "/docs/slugs/relativeSlug",
"title": "relativeSlug",
}, },
Object { Object {
"id": "slugs/resolvedSlug",
"next": Object {
"permalink": "/docs/tryToEscapeSlug", "permalink": "/docs/tryToEscapeSlug",
"title": "tryToEscapeSlug", "title": "tryToEscapeSlug",
}, },
], "prev": Object {
Array [ "permalink": "/docs/slugs/relativeSlug",
"title": "relativeSlug",
},
},
Object { Object {
"id": "slugs/tryToEscapeSlug",
"next": undefined,
"prev": Object {
"permalink": "/docs/slugs/hey/resolvedSlug", "permalink": "/docs/slugs/hey/resolvedSlug",
"title": "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",
},
],
},
}
`; `;

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 {
pagination: addDocNavigation(
rawDocs, rawDocs,
sidebarsUtils, sidebarsUtils,
versionMetadata.sidebarFilePath as string, versionMetadata.sidebarFilePath as string,
).map((doc) => [doc.previous, doc.next]); ).map((doc) => ({prev: doc.previous, next: doc.next, id: doc.id})),
sidebars,
};
} }
return {processDocFile, testMeta, testSlug, generateNavigation}; return {processDocFile, testMeta, testSlug, generateNavigation};