Skip to content

Commit

Permalink
refactor tests + add snapshot for pageBasePath param
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber authored and ilg-ul committed Feb 11, 2024
1 parent 6c4c8a5 commit dd81393
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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,
},
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ describe('truncate', () => {
});

describe('paginateBlogPosts', () => {
it('generates right pages', () => {
const blogPosts = [
{id: 'post1', metadata: {}, content: 'Foo 1'},
{id: 'post2', metadata: {}, content: 'Foo 2'},
{id: 'post3', metadata: {}, content: 'Foo 3'},
{id: 'post4', metadata: {}, content: 'Foo 4'},
{id: 'post5', metadata: {}, content: 'Foo 5'},
] as BlogPost[];
const blogPosts = [
{id: 'post1', metadata: {}, content: 'Foo 1'},
{id: 'post2', metadata: {}, content: 'Foo 2'},
{id: 'post3', metadata: {}, content: 'Foo 3'},
{id: 'post4', metadata: {}, content: 'Foo 4'},
{id: 'post5', metadata: {}, content: 'Foo 5'},
] as BlogPost[];

it('generates pages', () => {
expect(
paginateBlogPosts({
blogPosts,
Expand All @@ -56,6 +57,9 @@ describe('paginateBlogPosts', () => {
pageBasePath: 'page',
}),
).toMatchSnapshot();
});

it('generates pages at blog root', () => {
expect(
paginateBlogPosts({
blogPosts,
Expand All @@ -66,14 +70,30 @@ describe('paginateBlogPosts', () => {
pageBasePath: 'page',
}),
).toMatchSnapshot();
});

it('generates a single page', () => {
expect(
paginateBlogPosts({
blogPosts,
basePageUrl: '/',
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();
});
Expand Down

0 comments on commit dd81393

Please sign in to comment.