Skip to content

Commit

Permalink
tests: targetted paginator test to compare output
Browse files Browse the repository at this point in the history
  • Loading branch information
ReeceM committed Jul 5, 2022
1 parent fa86e7c commit 4e66736
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/buffer-example.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 23 additions & 2 deletions tests/generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const sitemapConfig = {
post: { changefreq: "weekly", priority: 0.8 },
latest_notice: (doc) => {
return {
lastmod: doc.last_publication_date ? doc.last_publication_date : (new Date()).toJSON(),
lastmod: doc.last_publication_date ? doc.last_publication_date : "2020-07-16",
changefreq: "weekly",
priority: 0.8
}
Expand All @@ -55,7 +55,7 @@ describe('tests for generator.js', () => {
.toHaveBeenCalledTimes(1);
});

it('file write should have been called with ...', () => {
it('file write should have been called with sitemapData Buffer', () => {

expect(jest.spyOn(fs, 'writeFileSync')).toHaveBeenCalledWith(
path.join(__dirname, "../public/sitemap.xml"),
Expand All @@ -73,6 +73,27 @@ describe('tests for generator.js', () => {
// })
});


describe('Pagination Tests', () => {
it('file write should have been called with sitemapData Buffer', async () => {

const paginationConfig = {
pagination: {
pageSize: 5,
}, ...sitemapConfig
};

jest.restoreAllMocks();
await generator(paginationConfig);

expect(jest.spyOn(fs, 'writeFileSync')).toHaveBeenCalledWith(
path.join(__dirname, "../public/sitemap.xml"),
require('./buffer-example'),
"utf-8"
);
});
});

describe('generator errors', () => {
it('will fail if linkResolver is not a function', async () => {
expect(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Using Sitemap Generator visiting page loads sitemap.xml 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:news=\\"http://www.google.com/schemas/sitemap-news/0.9\\" xmlns:xhtml=\\"http://www.w3.org/1999/xhtml\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\" xmlns:video=\\"http://www.google.com/schemas/sitemap-video/1.1\\"><url><loc>https://example.com/notice/sldkfmlksdmfs</loc><lastmod>2020-07-16</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://example.com/page/more-pages-here</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-worldi-need-to-make-a-demo-app2</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-a-lot-i-dont-got</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-page-of-cabbages</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page21</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-worldi-need-to-make-a-demo-app1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-page-of-cabbages1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page2</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/customer-reviews-page-example</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot11</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/another-page-here</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-is-the-time</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-is-the-time1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-world-to-the-cabbages</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/how-many-more-must-there-be</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-worldi-need-to-make-a-demo-app</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/blog/a-demo-blog-post</loc><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://example.com/blog/demo-post</loc><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://example.com/hello-to-me</loc><lastmod>2021-06-29</lastmod></url><url><loc>https://example.com/sup</loc><lastmod>2000-02-02</lastmod></url></urlset>"`;
exports[`Using Sitemap Generator visiting page loads sitemap.xml 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><urlset xmlns=\\"http://www.sitemaps.org/schemas/sitemap/0.9\\" xmlns:news=\\"http://www.google.com/schemas/sitemap-news/0.9\\" xmlns:xhtml=\\"http://www.w3.org/1999/xhtml\\" xmlns:image=\\"http://www.google.com/schemas/sitemap-image/1.1\\" xmlns:video=\\"http://www.google.com/schemas/sitemap-video/1.1\\"><url><loc>https://example.com/notice/sldkfmlksdmfs</loc><lastmod>2020-07-16</lastmod><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://example.com/page/more-pages-here</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-worldi-need-to-make-a-demo-app2</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-a-lot-i-dont-got</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-page-of-cabbages</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page21</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-worldi-need-to-make-a-demo-app1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-page-of-cabbages1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/a-demo-page2</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/customer-reviews-page-example</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/20-is-a-lot11</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/another-page-here</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-is-the-time</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/what-is-the-time1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-world-to-the-cabbages</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/how-many-more-must-there-be</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/hello-worldi-need-to-make-a-demo-app</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/page/another-page-here1</loc><changefreq>monthly</changefreq><priority>1.0</priority></url><url><loc>https://example.com/blog/a-demo-blog-post</loc><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://example.com/blog/demo-post</loc><changefreq>weekly</changefreq><priority>0.8</priority></url><url><loc>https://example.com/hello-to-me</loc><lastmod>2021-06-29</lastmod></url><url><loc>https://example.com/sup</loc><lastmod>2000-02-02</lastmod></url></urlset>"`;

0 comments on commit 4e66736

Please sign in to comment.