2019-08-04 20:31:13 +00:00
|
|
|
const { injectPageMetadata } = require('../../helpers/page')
|
|
|
|
|
2020-08-31 15:28:55 +00:00
|
|
|
describe('helpers/page/injectPageMetadata', () => {
|
|
|
|
const page = {
|
2019-08-04 20:31:13 +00:00
|
|
|
title: 'PAGE TITLE',
|
|
|
|
description: 'A PAGE',
|
|
|
|
isPublished: true,
|
|
|
|
updatedAt: new Date(),
|
2020-08-31 15:28:55 +00:00
|
|
|
content: 'TEST CONTENT',
|
|
|
|
createdAt: new Date('2019-01-01'),
|
2019-08-04 20:31:13 +00:00
|
|
|
}
|
2020-08-31 15:28:55 +00:00
|
|
|
|
|
|
|
it('returns the page content by default when content type is unknown', () => {
|
2019-08-04 20:31:13 +00:00
|
|
|
const expected = 'TEST CONTENT'
|
|
|
|
const result = injectPageMetadata(page)
|
|
|
|
expect(result).toEqual(expected)
|
|
|
|
})
|
2020-08-31 15:28:55 +00:00
|
|
|
|
|
|
|
it('injects metadata for markdown contents', () => {
|
|
|
|
const markdownPage = {
|
|
|
|
...page,
|
|
|
|
contentType: 'markdown',
|
|
|
|
editorKey: 'markdown',
|
|
|
|
}
|
|
|
|
|
2019-08-04 20:31:13 +00:00
|
|
|
const expected = `---
|
2020-08-31 15:28:55 +00:00
|
|
|
title: ${markdownPage.title}
|
|
|
|
description: ${markdownPage.description}
|
|
|
|
published: ${markdownPage.isPublished.toString()}
|
|
|
|
date: ${markdownPage.updatedAt}
|
|
|
|
tags:\x20
|
|
|
|
editor: ${markdownPage.editorKey}
|
|
|
|
dateCreated: ${markdownPage.createdAt}\n---
|
2019-08-04 20:31:13 +00:00
|
|
|
|
|
|
|
TEST CONTENT`
|
2020-08-31 15:28:55 +00:00
|
|
|
|
|
|
|
const result = injectPageMetadata(markdownPage)
|
2019-08-04 20:31:13 +00:00
|
|
|
expect(result).toEqual(expected)
|
|
|
|
})
|
|
|
|
|
2020-08-31 15:28:55 +00:00
|
|
|
it('injects metadata for html contents', () => {
|
|
|
|
const htmlPage = {
|
|
|
|
...page,
|
|
|
|
contentType: 'html',
|
|
|
|
editorKey: 'html',
|
|
|
|
}
|
|
|
|
|
2019-08-04 20:31:13 +00:00
|
|
|
const expected = `<!--
|
2020-08-31 15:28:55 +00:00
|
|
|
title: ${htmlPage.title}
|
|
|
|
description: ${htmlPage.description}
|
|
|
|
published: ${htmlPage.isPublished.toString()}
|
|
|
|
date: ${htmlPage.updatedAt}
|
|
|
|
tags:\x20
|
|
|
|
editor: ${htmlPage.editorKey}
|
|
|
|
dateCreated: ${htmlPage.createdAt}\n-->
|
2019-08-04 20:31:13 +00:00
|
|
|
|
|
|
|
TEST CONTENT`
|
2020-08-31 15:28:55 +00:00
|
|
|
|
|
|
|
const result = injectPageMetadata(htmlPage)
|
2019-08-04 20:31:13 +00:00
|
|
|
expect(result).toEqual(expected)
|
|
|
|
})
|
|
|
|
})
|