Skip to content

Commit bba0ea7

Browse files
committed
Add basic blog routes tests
1 parent ee3990b commit bba0ea7

2 files changed

Lines changed: 111 additions & 17 deletions

File tree

packages/docusaurus-plugin-content-blog/src/__tests__/__snapshots__/routes.test.ts.snap

Lines changed: 96 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ exports[`buildAllRoutes works for realistic blog post 2`] = `
225225
"metadata": {
226226
"authors": [
227227
{
228-
"key": "author2",
228+
"key": "author1",
229229
},
230230
],
231231
"date": 2020-01-01T00:00:00.000Z,
@@ -287,6 +287,9 @@ exports[`buildAllRoutes works for realistic blog post 2`] = `
287287
{
288288
"key": "author2",
289289
},
290+
{
291+
"key": "author3",
292+
},
290293
],
291294
"date": 2020-01-01T00:00:00.000Z,
292295
"description": "Description for post5",
@@ -330,19 +333,22 @@ exports[`buildAllRoutes works for realistic blog post 2`] = `
330333
"props": {
331334
"authors": [
332335
{
333-
"count": 0,
336+
"count": 3,
337+
"key": "author1",
334338
"name": "Author 1",
335339
"page": {
336340
"permalink": "/blog/authors/author1",
337341
},
338342
},
339343
{
340-
"count": 0,
344+
"count": 2,
345+
"key": "author2",
341346
"name": "Author 2",
342347
"page": null,
343348
},
344349
{
345-
"count": 0,
350+
"count": 1,
351+
"key": "author3",
346352
"name": "Author 3",
347353
"page": {
348354
"permalink": "/blog/authors/author3",
@@ -358,13 +364,33 @@ exports[`buildAllRoutes works for realistic blog post 2`] = `
358364
},
359365
"exact": true,
360366
"modules": {
361-
"items": [],
367+
"items": [
368+
{
369+
"content": {
370+
"__import": true,
371+
"path": "@site/blog/post1.md",
372+
"query": {
373+
"truncated": true,
374+
},
375+
},
376+
},
377+
{
378+
"content": {
379+
"__import": true,
380+
"path": "@site/blog/post2.md",
381+
"query": {
382+
"truncated": true,
383+
},
384+
},
385+
},
386+
],
362387
"sidebar": "@aliased/data/blog-post-list-prop-default.json",
363388
},
364389
"path": "/blog/authors/author1",
365390
"props": {
366391
"author": {
367-
"count": 0,
392+
"count": 3,
393+
"key": "author1",
368394
"name": "Author 1",
369395
"page": {
370396
"permalink": "/blog/authors/author1",
@@ -373,13 +399,13 @@ exports[`buildAllRoutes works for realistic blog post 2`] = `
373399
"listMetadata": {
374400
"blogDescription": "Custom blog description",
375401
"blogTitle": "Custom blog title",
376-
"nextPage": undefined,
402+
"nextPage": "/blog/authors/author1/authors/2",
377403
"page": 1,
378404
"permalink": "/blog/authors/author1",
379405
"postsPerPage": 2,
380406
"previousPage": undefined,
381-
"totalCount": 0,
382-
"totalPages": 1,
407+
"totalCount": 3,
408+
"totalPages": 2,
383409
},
384410
},
385411
},
@@ -390,13 +416,67 @@ exports[`buildAllRoutes works for realistic blog post 2`] = `
390416
},
391417
"exact": true,
392418
"modules": {
393-
"items": [],
419+
"items": [
420+
{
421+
"content": {
422+
"__import": true,
423+
"path": "@site/blog/post4.md",
424+
"query": {
425+
"truncated": true,
426+
},
427+
},
428+
},
429+
],
430+
"sidebar": "@aliased/data/blog-post-list-prop-default.json",
431+
},
432+
"path": "/blog/authors/author1/authors/2",
433+
"props": {
434+
"author": {
435+
"count": 3,
436+
"key": "author1",
437+
"name": "Author 1",
438+
"page": {
439+
"permalink": "/blog/authors/author1",
440+
},
441+
},
442+
"listMetadata": {
443+
"blogDescription": "Custom blog description",
444+
"blogTitle": "Custom blog title",
445+
"nextPage": undefined,
446+
"page": 2,
447+
"permalink": "/blog/authors/author1/authors/2",
448+
"postsPerPage": 2,
449+
"previousPage": "/blog/authors/author1",
450+
"totalCount": 3,
451+
"totalPages": 2,
452+
},
453+
},
454+
},
455+
{
456+
"component": "@theme/Blog/Pages/BlogAuthorsPostsPage",
457+
"context": {
458+
"blogMetadata": "@aliased/data/blogMetadata-default.json",
459+
},
460+
"exact": true,
461+
"modules": {
462+
"items": [
463+
{
464+
"content": {
465+
"__import": true,
466+
"path": "@site/blog/post5.md",
467+
"query": {
468+
"truncated": true,
469+
},
470+
},
471+
},
472+
],
394473
"sidebar": "@aliased/data/blog-post-list-prop-default.json",
395474
},
396475
"path": "/blog/authors/author3",
397476
"props": {
398477
"author": {
399-
"count": 0,
478+
"count": 1,
479+
"key": "author3",
400480
"name": "Author 3",
401481
"page": {
402482
"permalink": "/blog/authors/author3",
@@ -410,7 +490,7 @@ exports[`buildAllRoutes works for realistic blog post 2`] = `
410490
"permalink": "/blog/authors/author3",
411491
"postsPerPage": 2,
412492
"previousPage": undefined,
413-
"totalCount": 0,
493+
"totalCount": 1,
414494
"totalPages": 1,
415495
},
416496
},
@@ -463,7 +543,7 @@ exports[`buildAllRoutes works for realistic blog post 3`] = `
463543
"site-blog-post-1-md-235.json": {
464544
"authors": [
465545
{
466-
"key": "author2",
546+
"key": "author1",
467547
},
468548
],
469549
"date": 2020-01-01T00:00:00.000Z,
@@ -529,6 +609,9 @@ exports[`buildAllRoutes works for realistic blog post 3`] = `
529609
{
530610
"key": "author2",
531611
},
612+
{
613+
"key": "author3",
614+
},
532615
],
533616
"date": 2020-01-01T00:00:00.000Z,
534617
"description": "Description for post5",

packages/docusaurus-plugin-content-blog/src/__tests__/routes.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,9 @@ describe('buildAllRoutes', () => {
264264
blogTitle: 'Custom blog title',
265265
blogDescription: 'Custom blog description',
266266
blogSidebarTitle: 'Custom blog sidebar title',
267+
267268
blogPosts: [
268-
blogPost({id: 'post1', metadata: {authors: [{key: 'author2'}]}}),
269+
blogPost({id: 'post1', metadata: {authors: [{key: 'author1'}]}}),
269270
blogPost({id: 'post2', metadata: {authors: [{key: 'author1'}]}}),
270271
blogPost({
271272
id: 'post3',
@@ -280,16 +281,26 @@ describe('buildAllRoutes', () => {
280281
authors: [{key: 'author1'}, {key: 'author2'}],
281282
},
282283
}),
283-
blogPost({id: 'post5', metadata: {authors: [{key: 'author2'}]}}),
284+
blogPost({
285+
id: 'post5',
286+
metadata: {authors: [{key: 'author2'}, {key: 'author3'}]},
287+
}),
284288
blogPost({id: 'post6'}),
285289
],
290+
286291
authorsMap: {
287292
author1: {
293+
key: 'author1',
288294
name: 'Author 1',
289295
page: {permalink: '/blog/authors/author1'},
290296
},
291-
author2: {name: 'Author 2', page: null},
297+
author2: {
298+
key: 'author2',
299+
name: 'Author 2',
300+
page: null,
301+
},
292302
author3: {
303+
key: 'author3',
293304
name: 'Author 3',
294305
page: {permalink: '/blog/authors/author3'},
295306
},
@@ -300,7 +311,7 @@ describe('buildAllRoutes', () => {
300311
expect(_.countBy(routes, 'component')).toMatchInlineSnapshot(`
301312
{
302313
"@theme/Blog/Pages/BlogAuthorsListPage": 1,
303-
"@theme/Blog/Pages/BlogAuthorsPostsPage": 2,
314+
"@theme/Blog/Pages/BlogAuthorsPostsPage": 3,
304315
"@theme/BlogArchivePage": 1,
305316
"@theme/BlogListPage": 3,
306317
"@theme/BlogPostPage": 6,

0 commit comments

Comments
 (0)