mirror of https://github.com/requarks/wiki
feat: export creation date in dumped content (#2345)
* Export creation date in dumped content * date_creation -> dateCreated Co-authored-by: Joris Langlois <joris.langlois@knplabs.com>pull/2354/head
parent
ae733392f3
commit
cda1f1e805
@ -1,43 +1,62 @@
|
||||
const { injectPageMetadata } = require('../../helpers/page')
|
||||
|
||||
describe('injectPageMetadata tests', () => {
|
||||
let page = {
|
||||
describe('helpers/page/injectPageMetadata', () => {
|
||||
const page = {
|
||||
title: 'PAGE TITLE',
|
||||
description: 'A PAGE',
|
||||
isPublished: true,
|
||||
updatedAt: new Date(),
|
||||
content: 'TEST CONTENT'
|
||||
content: 'TEST CONTENT',
|
||||
createdAt: new Date('2019-01-01'),
|
||||
}
|
||||
test('injectPageMetadata: default', () => {
|
||||
|
||||
it('returns the page content by default when content type is unknown', () => {
|
||||
const expected = 'TEST CONTENT'
|
||||
const result = injectPageMetadata(page)
|
||||
expect(result).toEqual(expected)
|
||||
})
|
||||
test('injectPageMetadata: markdown', () => {
|
||||
page.contentType = 'markdown'
|
||||
|
||||
it('injects metadata for markdown contents', () => {
|
||||
const markdownPage = {
|
||||
...page,
|
||||
contentType: 'markdown',
|
||||
editorKey: 'markdown',
|
||||
}
|
||||
|
||||
const expected = `---
|
||||
title: ${page.title}
|
||||
description: ${page.description}
|
||||
published: ${page.isPublished.toString()}
|
||||
date: ${page.updatedAt}
|
||||
tags: \n---
|
||||
title: ${markdownPage.title}
|
||||
description: ${markdownPage.description}
|
||||
published: ${markdownPage.isPublished.toString()}
|
||||
date: ${markdownPage.updatedAt}
|
||||
tags:\x20
|
||||
editor: ${markdownPage.editorKey}
|
||||
dateCreated: ${markdownPage.createdAt}\n---
|
||||
|
||||
TEST CONTENT`
|
||||
const result = injectPageMetadata(page)
|
||||
|
||||
const result = injectPageMetadata(markdownPage)
|
||||
expect(result).toEqual(expected)
|
||||
})
|
||||
|
||||
test('injectPageMetadata: hmtl', () => {
|
||||
page.contentType = 'html'
|
||||
it('injects metadata for html contents', () => {
|
||||
const htmlPage = {
|
||||
...page,
|
||||
contentType: 'html',
|
||||
editorKey: 'html',
|
||||
}
|
||||
|
||||
const expected = `<!--
|
||||
title: ${page.title}
|
||||
description: ${page.description}
|
||||
published: ${page.isPublished.toString()}
|
||||
date: ${page.updatedAt}
|
||||
tags: \n-->
|
||||
title: ${htmlPage.title}
|
||||
description: ${htmlPage.description}
|
||||
published: ${htmlPage.isPublished.toString()}
|
||||
date: ${htmlPage.updatedAt}
|
||||
tags:\x20
|
||||
editor: ${htmlPage.editorKey}
|
||||
dateCreated: ${htmlPage.createdAt}\n-->
|
||||
|
||||
TEST CONTENT`
|
||||
const result = injectPageMetadata(page)
|
||||
|
||||
const result = injectPageMetadata(htmlPage)
|
||||
expect(result).toEqual(expected)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in new issue