You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.5 KiB

  1. const { injectPageMetadata } = require('../../helpers/page')
  2. describe('helpers/page/injectPageMetadata', () => {
  3. const page = {
  4. title: 'PAGE TITLE',
  5. description: 'A PAGE',
  6. isPublished: true,
  7. updatedAt: new Date(),
  8. content: 'TEST CONTENT',
  9. createdAt: new Date('2019-01-01'),
  10. }
  11. it('returns the page content by default when content type is unknown', () => {
  12. const expected = 'TEST CONTENT'
  13. const result = injectPageMetadata(page)
  14. expect(result).toEqual(expected)
  15. })
  16. it('injects metadata for markdown contents', () => {
  17. const markdownPage = {
  18. ...page,
  19. contentType: 'markdown',
  20. editorKey: 'markdown',
  21. }
  22. const expected = `---
  23. title: ${markdownPage.title}
  24. description: ${markdownPage.description}
  25. published: ${markdownPage.isPublished.toString()}
  26. date: ${markdownPage.updatedAt}
  27. tags:\x20
  28. editor: ${markdownPage.editorKey}
  29. dateCreated: ${markdownPage.createdAt}\n---
  30. TEST CONTENT`
  31. const result = injectPageMetadata(markdownPage)
  32. expect(result).toEqual(expected)
  33. })
  34. it('injects metadata for html contents', () => {
  35. const htmlPage = {
  36. ...page,
  37. contentType: 'html',
  38. editorKey: 'html',
  39. }
  40. const expected = `<!--
  41. title: ${htmlPage.title}
  42. description: ${htmlPage.description}
  43. published: ${htmlPage.isPublished.toString()}
  44. date: ${htmlPage.updatedAt}
  45. tags:\x20
  46. editor: ${htmlPage.editorKey}
  47. dateCreated: ${htmlPage.createdAt}\n-->
  48. TEST CONTENT`
  49. const result = injectPageMetadata(htmlPage)
  50. expect(result).toEqual(expected)
  51. })
  52. })