Skip to content

Commit

Permalink
Merge pull request #32 from minhhang107/add-test-getHtmlTitleBody
Browse files Browse the repository at this point in the history
Add tests for getHtmlTitleBody
  • Loading branch information
lyu4321 committed Nov 16, 2021
2 parents 1c04e72 + 3365510 commit 2dccb2a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/create-html.js
Expand Up @@ -240,4 +240,5 @@ module.exports = {
getHtmlLayout,
getUpdatedHtmlLayout,
getHtmlNav,
getHtmlTitleBody,
};
32 changes: 32 additions & 0 deletions src/create-html.test.js
Expand Up @@ -2,6 +2,7 @@ const {
getHtmlLayout,
getUpdatedHtmlLayout,
getHtmlNav,
getHtmlTitleBody,
} = require('./create-html');

describe('Unit tests for getHtmlNav', () => {
Expand Down Expand Up @@ -139,3 +140,34 @@ describe('Unit tests for getUpdatedHtmlLayout', () => {
expect(result.includes(`<html lang="fr-CA">`)).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:
'<h1>Sample Title</h1>\n' +
'<p> This is a sample text file.</p>\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: '<p>This is a sample text file.</p>\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: '<h1>This is a heading</h1>\n',
};
expect(getHtmlTitleBody(mdFile, false)).toEqual(expected);
});
});

0 comments on commit 2dccb2a

Please sign in to comment.