Skip to content

Adding tests for docs-page blueprint #351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions blueprints/docs-page/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const path = require('path');
const fs = require('fs');
const chalk = require('chalk');
const padStart = require('pad-start');
const EmberRouterGenerator = require('ember-router-generator');
const stringUtil = require('ember-cli-string-utils');

Expand Down Expand Up @@ -47,8 +48,6 @@ module.exports = {
},

afterInstall: function(options) {
// eslint-disable-next-line no-debugger
debugger;
updateRouter.call(this, 'add', options);
updateDocsTemplate.call(this, options);
},
Expand Down Expand Up @@ -98,7 +97,7 @@ function writeRoute(action, name, options) {

function updateDocsTemplate(options) {
let routeName = options.entity.name;
let docsTemplatePath = options.pods
let docsTemplatePath = options.pod
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found this wee bug while I was writing tests. I guess I missed it with my manual testing (I'm old and senile...)

? path.join(DUMMY_APP_PATH, 'pods', 'docs', 'template.hbs')
: path.join(DUMMY_APP_PATH, 'templates', 'docs.hbs');

Expand All @@ -115,7 +114,8 @@ function updateDocsTemplate(options) {
templateLines.splice(
templateLines.indexOf(closingViewerNavTag),
0,
`${''.padStart(
`${padStart(
'',
closingViewerNavTag.search(/\S/) * 2,
' '
)}{{nav.item "${dedasherize(routeName)}" "docs.${routeName}"}}`
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"start": "ember serve",
"test": "ember try:each",
"test:browser": "ember test --test-port=0",
"test:node": "mocha tests-node/**/*-test.js",
"test:node": "mocha tests-node --recursive",
"test:test-apps": "cd test-apps/new-addon && yarn test",
"prepare": "./scripts/link-them.sh"
},
Expand Down Expand Up @@ -76,6 +76,7 @@
"lodash": "^4.17.11",
"lunr": "^2.3.3",
"marked": "^0.5.0",
"pad-start": "^1.0.2",
"parse-git-config": "^2.0.3",
"quick-temp": "^0.1.8",
"resolve": "^1.8.1",
Expand All @@ -96,6 +97,7 @@
"ember-cli": "~3.4.3",
"ember-cli-addon-docs-esdoc": "^0.2.1",
"ember-cli-addon-docs-yuidoc": "^0.2.1",
"ember-cli-blueprint-test-helpers": "^0.19.2",
"ember-cli-dependency-checker": "^3.0.0",
"ember-cli-dependency-lint": "^1.1.3",
"ember-cli-deploy": "^1.0.2",
Expand Down
16 changes: 16 additions & 0 deletions tests-node/fixtures/blueprints/docs-subnav.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{docs-header}}

{{#docs-viewer as |viewer|}}
{{#viewer.nav as |nav|}}
{{nav.item 'Introduction' 'docs.index'}}
{{nav.item 'Usage' 'docs.usage'}}

{{#nav.subnav as |nav|}}
{{nav.item 'Subitem' 'docs.items.subitem'}}
{{/nav.subnav}}
{{/viewer.nav}}

{{#viewer.main}}
{{outlet}}
{{/viewer.main}}
{{/docs-viewer}}
12 changes: 12 additions & 0 deletions tests-node/fixtures/blueprints/docs.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{docs-header}}

{{#docs-viewer as |viewer|}}
{{#viewer.nav as |nav|}}
{{nav.item 'Introduction' 'docs.index'}}
{{nav.item 'Usage' 'docs.usage'}}
{{/viewer.nav}}

{{#viewer.main}}
{{outlet}}
{{/viewer.main}}
{{/docs-viewer}}
168 changes: 168 additions & 0 deletions tests-node/unit/blueprints/docs-page-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
'use strict';

const path = require('path');
const fs = require('fs-extra');
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');

let setupTestHooks = blueprintHelpers.setupTestHooks;
let emberNew = blueprintHelpers.emberNew;
let emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;

const expect = require('ember-cli-blueprint-test-helpers/chai').expect;
const file = require('ember-cli-blueprint-test-helpers/chai').file;

describe('Blueprints | non-pods docs page test', function() {
setupTestHooks(this);

it('it generates a docs page and updates router with no docs.hbs present', function() {
return emberNew({ target: 'addon' }).then(() => {
return emberGenerateDestroy(['docs-page', 'foo-bar'], _file => {
expect(_file('tests/dummy/app/templates/docs/foo-bar.md'))
.to.exist.to.contain('# Foo bar')
.to.contain('Foo bar content');

expect(file('tests/dummy/app/router.js')).to.contain(
"this.route('foo-bar');"
);

expect(file('tests/dummy/app/templates/docs.hbs')).to.not.exist;
});
});
});

it('it generates a docs page, updates router, and adds nav item to docs.hbs', function() {
return emberNew({ target: 'addon' })
.then(() =>
copyFixtureFile(
getFixturePath('docs.hbs'),
'tests/dummy/app/templates/docs.hbs'
)
)
.then(() => {
return emberGenerateDestroy(['docs-page', 'foo-bar'], _file => {
expect(_file('tests/dummy/app/templates/docs/foo-bar.md'))
.to.exist.to.contain('# Foo bar')
.to.contain('Foo bar content');

expect(file('tests/dummy/app/router.js')).to.contain(
"this.route('foo-bar');"
);

expect(
file('tests/dummy/app/templates/docs.hbs')
).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}');
});
});
});

it('it generates a docs page, updates router, and adds nav item to docs.hbs when subnav present', function() {
return emberNew({ target: 'addon' })
.then(() =>
copyFixtureFile(
getFixturePath('docs-subnav.hbs'),
'tests/dummy/app/templates/docs.hbs'
)
)
.then(() => {
return emberGenerateDestroy(['docs-page', 'foo-bar'], _file => {
expect(_file('tests/dummy/app/templates/docs/foo-bar.md'))
.to.exist.to.contain('# Foo bar')
.to.contain('Foo bar content');

expect(file('tests/dummy/app/router.js')).to.contain(
"this.route('foo-bar');"
);

expect(
file('tests/dummy/app/templates/docs.hbs')
).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}');
});
});
});
});

describe('Blueprints | pods docs page test', function() {
setupTestHooks(this);

it('it generates a docs page and updates router with no docs.hbs present', function() {
return emberNew({ target: 'addon', pod: true }).then(() => {
return emberGenerateDestroy(['docs-page', 'foo-bar', '--pod'], _file => {
expect(_file('tests/dummy/app/pods/docs/foo-bar/template.md'))
.to.exist.to.contain('# Foo bar')
.to.contain('Foo bar content');

expect(file('tests/dummy/app/router.js')).to.contain(
"this.route('foo-bar');"
);

expect(file('tests/dummy/app/pods/docs/template.hbs')).to.not.exist;
});
});
});

it('it generates a docs page, updates router, and adds nav item to docs.hbs', function() {
return emberNew({ target: 'addon', pod: true })
.then(() =>
copyFixtureFile(
getFixturePath('docs.hbs'),
'tests/dummy/app/pods/docs/template.hbs'
)
)
.then(() => {
return emberGenerateDestroy(
['docs-page', 'foo-bar', '--pod'],
_file => {
expect(_file('tests/dummy/app/pods/docs/foo-bar/template.md'))
.to.exist.to.contain('# Foo bar')
.to.contain('Foo bar content');

expect(file('tests/dummy/app/router.js')).to.contain(
"this.route('foo-bar');"
);

expect(
file('tests/dummy/app/pods/docs/template.hbs')
).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}');
}
);
});
});

it('it generates a docs page, updates router, and adds nav item to docs.hbs when subnav present', function() {
return emberNew({ target: 'addon', pod: true })
.then(() =>
copyFixtureFile(
getFixturePath('docs-subnav.hbs'),
'tests/dummy/app/pods/docs/template.hbs'
)
)
.then(() => {
return emberGenerateDestroy(
['docs-page', 'foo-bar', '--pod'],
_file => {
expect(_file('tests/dummy/app/pods/docs/foo-bar/template.md'))
.to.exist.to.contain('# Foo bar')
.to.contain('Foo bar content');

expect(file('tests/dummy/app/router.js')).to.contain(
"this.route('foo-bar');"
);

expect(
file('tests/dummy/app/pods/docs/template.hbs')
).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}');
}
);
});
});
});

function copyFixtureFile(src, dest) {
return fs.copy(src, path.join(process.cwd(), dest));
}

function getFixturePath(fixtureRelativePath) {
const fixturesPath = path.join(__dirname, '../..', 'fixtures', 'blueprints');

return path.join(fixturesPath, fixtureRelativePath);
}
Loading