refactor tests + add snapshot for pageBasePath param

This commit is contained in:
sebastien 2024-02-09 19:43:57 +01:00
parent 6c4c8a5a3e
commit f9b9396a07
2 changed files with 92 additions and 17 deletions

View file

@ -23,7 +23,32 @@ title: This post links to another one!
[Linked post](/blog/2018/12/14/Happy-First-Birthday-Slash)"
`;
exports[`paginateBlogPosts generates right pages 1`] = `
exports[`paginateBlogPosts generates a single page 1`] = `
[
{
"items": [
"post1",
"post2",
"post3",
"post4",
"post5",
],
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"nextPage": undefined,
"page": 1,
"permalink": "/",
"postsPerPage": 10,
"previousPage": undefined,
"totalCount": 5,
"totalPages": 1,
},
},
]
`;
exports[`paginateBlogPosts generates pages 1`] = `
[
{
"items": [
@ -78,7 +103,7 @@ exports[`paginateBlogPosts generates right pages 1`] = `
]
`;
exports[`paginateBlogPosts generates right pages 2`] = `
exports[`paginateBlogPosts generates pages at blog root 1`] = `
[
{
"items": [
@ -133,26 +158,56 @@ exports[`paginateBlogPosts generates right pages 2`] = `
]
`;
exports[`paginateBlogPosts generates right pages 3`] = `
exports[`paginateBlogPosts generates pages with custom pageBasePath 1`] = `
[
{
"items": [
"post1",
"post2",
],
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"nextPage": "/blog/customPageBasePath/2",
"page": 1,
"permalink": "/blog",
"postsPerPage": 2,
"previousPage": undefined,
"totalCount": 5,
"totalPages": 3,
},
},
{
"items": [
"post3",
"post4",
],
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"nextPage": "/blog/customPageBasePath/3",
"page": 2,
"permalink": "/blog/customPageBasePath/2",
"postsPerPage": 2,
"previousPage": "/blog",
"totalCount": 5,
"totalPages": 3,
},
},
{
"items": [
"post5",
],
"metadata": {
"blogDescription": "Blog Description",
"blogTitle": "Blog Title",
"nextPage": undefined,
"page": 1,
"permalink": "/",
"postsPerPage": 10,
"previousPage": undefined,
"page": 3,
"permalink": "/blog/customPageBasePath/3",
"postsPerPage": 2,
"previousPage": "/blog/customPageBasePath/2",
"totalCount": 5,
"totalPages": 1,
"totalPages": 3,
},
},
]

View file

@ -38,7 +38,6 @@ describe('truncate', () => {
});
describe('paginateBlogPosts', () => {
it('generates right pages', () => {
const blogPosts = [
{id: 'post1', metadata: {}, content: 'Foo 1'},
{id: 'post2', metadata: {}, content: 'Foo 2'},
@ -46,6 +45,8 @@ describe('paginateBlogPosts', () => {
{id: 'post4', metadata: {}, content: 'Foo 4'},
{id: 'post5', metadata: {}, content: 'Foo 5'},
] as BlogPost[];
it('generates pages', () => {
expect(
paginateBlogPosts({
blogPosts,
@ -56,6 +57,9 @@ describe('paginateBlogPosts', () => {
pageBasePath: 'page',
}),
).toMatchSnapshot();
});
it('generates pages at blog root', () => {
expect(
paginateBlogPosts({
blogPosts,
@ -66,6 +70,9 @@ describe('paginateBlogPosts', () => {
pageBasePath: 'page',
}),
).toMatchSnapshot();
});
it('generates a single page', () => {
expect(
paginateBlogPosts({
blogPosts,
@ -73,7 +80,20 @@ describe('paginateBlogPosts', () => {
blogTitle: 'Blog Title',
blogDescription: 'Blog Description',
postsPerPageOption: 10,
pageBasePath: 'a-page',
pageBasePath: 'page',
}),
).toMatchSnapshot();
});
it('generates pages with custom pageBasePath', () => {
expect(
paginateBlogPosts({
blogPosts,
basePageUrl: '/blog',
blogTitle: 'Blog Title',
blogDescription: 'Blog Description',
postsPerPageOption: 2,
pageBasePath: 'customPageBasePath',
}),
).toMatchSnapshot();
});