From bc5d9961a07ff979fe3dfa5926bf57f54a9abffc Mon Sep 17 00:00:00 2001 From: Minh Hang Nguyen Date: Tue, 16 Nov 2021 12:36:27 -0500 Subject: [PATCH 1/2] added tests for getHtmlTitleBody --- src/create-html.js | 1 + src/create-html.test.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/create-html.js b/src/create-html.js index 40f11ab..73d0b06 100644 --- a/src/create-html.js +++ b/src/create-html.js @@ -240,4 +240,5 @@ module.exports = { getHtmlLayout, getUpdatedHtmlLayout, getHtmlNav, + getHtmlTitleBody, }; diff --git a/src/create-html.test.js b/src/create-html.test.js index 3c9a7b6..65a573b 100644 --- a/src/create-html.test.js +++ b/src/create-html.test.js @@ -2,6 +2,7 @@ const { getHtmlLayout, getUpdatedHtmlLayout, getHtmlNav, + getHtmlTitleBody, } = require('./create-html'); describe('Unit tests for getHtmlNav', () => { @@ -139,3 +140,36 @@ describe('Unit tests for getUpdatedHtmlLayout', () => { expect(result.includes(``)).toBeTruthy(); }); }); + +describe('Unit tests for getHtmlTitleBody', () => { + test('Should return an object of title and body for text file with title', () => { + const txtFile = `Sample Title\n\n\nThis is a sample text file.`; + + const expected = { + title: 'Sample Title', + body: + '

Sample Title

\n' + + '

This is a sample text file.

\n', + }; + expect(getHtmlTitleBody(txtFile, true)).toEqual(expected); + }); + + test('Should return an object of empty title and body for text file with no title', () => { + const txtFile = `This is a sample text file.`; + + const expected = { + title: '', + body: '

This is a sample text file.

\n', + }; + expect(getHtmlTitleBody(txtFile, true)).toEqual(expected); + }); + + test('Should return an object containing empty title and body for markdown file', () => { + const mdFile = `# This is a heading`; + const expected = { + title: '', + body: '

This is a heading

\n', + }; + expect(getHtmlTitleBody(mdFile, false)).toEqual(expected); + }); +}); From 3365510df9f5c205acf03462b27bccd8d619cde7 Mon Sep 17 00:00:00 2001 From: Minh Hang Nguyen Date: Tue, 16 Nov 2021 12:40:17 -0500 Subject: [PATCH 2/2] fixed typo --- src/create-html.test.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/create-html.test.js b/src/create-html.test.js index 65a573b..e54b411 100644 --- a/src/create-html.test.js +++ b/src/create-html.test.js @@ -144,7 +144,6 @@ describe('Unit tests for getUpdatedHtmlLayout', () => { describe('Unit tests for getHtmlTitleBody', () => { test('Should return an object of title and body for text file with title', () => { const txtFile = `Sample Title\n\n\nThis is a sample text file.`; - const expected = { title: 'Sample Title', body: @@ -156,7 +155,6 @@ describe('Unit tests for getHtmlTitleBody', () => { test('Should return an object of empty title and body for text file with no title', () => { const txtFile = `This is a sample text file.`; - const expected = { title: '', body: '

This is a sample text file.

\n',