Skip to content

Commit

Permalink
Add UT to check site conversion generates correct number of files
Browse files Browse the repository at this point in the history
  • Loading branch information
amad-person committed Mar 29, 2019
1 parent 40f7dcf commit 22707f0
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Site.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ Site.prototype.addIndexPage = function () {
const indexPagePath = path.join(this.rootPath, INDEX_MARKDOWN_FILE);
const fileNames = ['README.md', 'Home.md'];
const filePath = fileNames.find(fileName => fs.existsSync(path.join(this.rootPath, fileName)));
return fs.copyAsync(filePath, indexPagePath)
return fs.copyAsync(path.join(this.rootPath, filePath), indexPagePath)
.catch(() => Promise.reject(new Error(`Failed to copy over ${filePath}`)));
};

Expand Down
65 changes: 65 additions & 0 deletions test/unit/Site.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ const ghpages = require('gh-pages');
const Site = require('../../src/Site');

const {
ABOUT_MD_DEFAULT,
FOOTER_MD_DEFAULT,
HEADER_MD_DEFAULT,
INDEX_MD_DEFAULT,
PAGE_EJS,
SITE_JSON_DEFAULT,
SITE_NAV_MD_DEFAULT,
TOP_NAV_DEFAULT,
USER_VARIABLES_DEFAULT,
LAYOUT_FILES_DEFAULT,
LAYOUT_SCRIPTS_DEFAULT,
Expand Down Expand Up @@ -351,6 +353,69 @@ test('Site read correct user defined variables', async () => {
expect(subsub.number).toEqual('9999');
});

test('Site convert generates correct assets', async () => {
const json = {
'src/asset/font-awesome.csv': '',
'src/asset/glyphicons.csv': '',
'src/template/page.ejs': PAGE_EJS,
'inner/site.json': SITE_JSON_DEFAULT,

'asset/css/bootstrap.min.css': '',
'asset/css/bootstrap.min.css.map': '',
'asset/css/github.min.css': '',
'asset/css/markbind.css': '',
'asset/css/page-nav.css': '',
'asset/css/site-nav.css': '',

'asset/js/bootstrap-utility.min.js': '',
'asset/js/setup.js': '',
'asset/js/vue.min.js': '',
'asset/js/vue-strap.min.js': '',

'node_modules/@fortawesome/fontawesome-free/css/all.min.css': '',
'node_modules/@fortawesome/fontawesome-free/webfonts/font1.svg': '',
'node_modules/@fortawesome/fontawesome-free/webfonts/font2.ttf': '',

'inner/_markbind/layouts/default/footer.md': '',
'inner/_markbind/layouts/default/head.md': '',
'inner/_markbind/layouts/default/header.md': '',
'inner/_markbind/layouts/default/navigation.md': '',
'inner/_markbind/layouts/default/scripts.js': '',
'inner/_markbind/layouts/default/styles.css': '',

'inner/index.md': INDEX_MD_DEFAULT,

'inner/_Footer.md': '',
'inner/_Sidebar.md': '',
'inner/Home.md': '',
};
fs.vol.fromJSON(json, '');
const site = new Site('inner/', 'inner/_site/');
await site.generate();
await new Site('inner/', 'inner/_site/').convert();

// number of files
const paths = Object.keys(fs.vol.toJSON());
const originalNumFiles = Object.keys(json).length;
const expectedNumBuilt = 22;
expect(paths.length).toEqual(originalNumFiles + expectedNumBuilt);

// footer
expect(fs.existsSync(path.resolve('inner/_site/markbind/layouts/default/footer.md'))).toEqual(true);

// site navigation
expect(fs.existsSync(path.resolve('inner/_site/markbind/layouts/default/navigation.md'))).toEqual(true);

// top navigation
expect(fs.readFileSync(path.resolve('inner/_markbind/common/top-nav.md'), 'utf8')).toEqual(TOP_NAV_DEFAULT);

// index page
expect(fs.existsSync(path.resolve('inner/index.md'))).toEqual(true);

// about page
expect(fs.readFileSync(path.resolve('inner/about.md'), 'utf8')).toEqual(ABOUT_MD_DEFAULT);
});

test('Site deploys with default settings', async () => {
const json = {
'src/template/page.ejs': PAGE_EJS,
Expand Down
16 changes: 16 additions & 0 deletions test/unit/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ module.exports.SITE_JSON_DEFAULT = '{\n'
+ ' }\n'
+ '}\n';

module.exports.ABOUT_MD_DEFAULT = '# About\n'
+ 'Welcome to your **About Us** page.\n';

module.exports.FOOTER_MD_DEFAULT = '<footer>\n'
+ ' <div class="text-center">\n'
+ ' This is a dynamic height footer that supports markdown <md>:smile:</md>!\n'
Expand Down Expand Up @@ -108,6 +111,19 @@ module.exports.SITE_NAV_MD_DEFAULT = '<navigation>\n'
+ '* [Home :glyphicon-home:]({{baseUrl}}/index.html)\n'
+ '</navigation>\n';

module.exports.TOP_NAV_DEFAULT = '<navbar placement="top" type="inverse">\n'
+ ' <a slot="brand" href="{{baseUrl}}/index.html" title="Home" class="navbar-brand">'
+ '<i class="far fa-file-image"></i></a>\n'
+ ' <li><a href="{{baseUrl}}/index.html" class="nav-link">HOME</a></li>\n'
+ ' <li><a href="{{baseUrl}}/about.html" class="nav-link">ABOUT</a></li>\n'
+ ' <li slot="right">\n'
+ ' <form class="navbar-form">\n'
+ ' <searchbar :data="searchData" placeholder="Search" :on-hit="searchCallback"'
+ ' menu-align-right></searchbar>\n'
+ ' </form>\n'
+ ' </li>\n'
+ '</navbar>';

module.exports.USER_VARIABLES_DEFAULT = '<variable name="example">\n'
+ 'To inject this HTML segment in your markbind files, use {{ example }} where you want to place it.\n'
+ 'More generally, surround the segment\'s id with double curly braces.\n'
Expand Down

0 comments on commit 22707f0

Please sign in to comment.