Skip to content

Commit a64bfca

Browse files
scalvertsamselikoff
authored andcommitted
Adding tests for docs-page blueprint (ember-learn#351)
* Adding tests for docs-page blueprint * Adding pad-start package for node 6 compatibility
1 parent 99318eb commit a64bfca

File tree

6 files changed

+390
-443
lines changed

6 files changed

+390
-443
lines changed

blueprints/docs-page/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const path = require('path');
33
const fs = require('fs');
44
const chalk = require('chalk');
5+
const padStart = require('pad-start');
56
const EmberRouterGenerator = require('ember-router-generator');
67
const stringUtil = require('ember-cli-string-utils');
78

@@ -47,8 +48,6 @@ module.exports = {
4748
},
4849

4950
afterInstall: function(options) {
50-
// eslint-disable-next-line no-debugger
51-
debugger;
5251
updateRouter.call(this, 'add', options);
5352
updateDocsTemplate.call(this, options);
5453
},
@@ -98,7 +97,7 @@ function writeRoute(action, name, options) {
9897

9998
function updateDocsTemplate(options) {
10099
let routeName = options.entity.name;
101-
let docsTemplatePath = options.pods
100+
let docsTemplatePath = options.pod
102101
? path.join(DUMMY_APP_PATH, 'pods', 'docs', 'template.hbs')
103102
: path.join(DUMMY_APP_PATH, 'templates', 'docs.hbs');
104103

@@ -115,7 +114,8 @@ function updateDocsTemplate(options) {
115114
templateLines.splice(
116115
templateLines.indexOf(closingViewerNavTag),
117116
0,
118-
`${''.padStart(
117+
`${padStart(
118+
'',
119119
closingViewerNavTag.search(/\S/) * 2,
120120
' '
121121
)}{{nav.item "${dedasherize(routeName)}" "docs.${routeName}"}}`

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"start": "ember serve",
2121
"test": "ember try:each",
2222
"test:browser": "ember test --test-port=0",
23-
"test:node": "mocha tests-node/**/*-test.js",
23+
"test:node": "mocha tests-node --recursive",
2424
"test:test-apps": "cd test-apps/new-addon && yarn test",
2525
"prepare": "./scripts/link-them.sh"
2626
},
@@ -76,6 +76,7 @@
7676
"lodash": "^4.17.11",
7777
"lunr": "^2.3.3",
7878
"marked": "^0.5.0",
79+
"pad-start": "^1.0.2",
7980
"parse-git-config": "^2.0.3",
8081
"quick-temp": "^0.1.8",
8182
"resolve": "^1.8.1",
@@ -96,6 +97,7 @@
9697
"ember-cli": "~3.4.3",
9798
"ember-cli-addon-docs-esdoc": "^0.2.1",
9899
"ember-cli-addon-docs-yuidoc": "^0.2.1",
100+
"ember-cli-blueprint-test-helpers": "^0.19.2",
99101
"ember-cli-dependency-checker": "^3.0.0",
100102
"ember-cli-dependency-lint": "^1.1.3",
101103
"ember-cli-deploy": "^1.0.2",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{docs-header}}
2+
3+
{{#docs-viewer as |viewer|}}
4+
{{#viewer.nav as |nav|}}
5+
{{nav.item 'Introduction' 'docs.index'}}
6+
{{nav.item 'Usage' 'docs.usage'}}
7+
8+
{{#nav.subnav as |nav|}}
9+
{{nav.item 'Subitem' 'docs.items.subitem'}}
10+
{{/nav.subnav}}
11+
{{/viewer.nav}}
12+
13+
{{#viewer.main}}
14+
{{outlet}}
15+
{{/viewer.main}}
16+
{{/docs-viewer}}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{{docs-header}}
2+
3+
{{#docs-viewer as |viewer|}}
4+
{{#viewer.nav as |nav|}}
5+
{{nav.item 'Introduction' 'docs.index'}}
6+
{{nav.item 'Usage' 'docs.usage'}}
7+
{{/viewer.nav}}
8+
9+
{{#viewer.main}}
10+
{{outlet}}
11+
{{/viewer.main}}
12+
{{/docs-viewer}}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const fs = require('fs-extra');
5+
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
6+
7+
let setupTestHooks = blueprintHelpers.setupTestHooks;
8+
let emberNew = blueprintHelpers.emberNew;
9+
let emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
10+
11+
const expect = require('ember-cli-blueprint-test-helpers/chai').expect;
12+
const file = require('ember-cli-blueprint-test-helpers/chai').file;
13+
14+
describe('Blueprints | non-pods docs page test', function() {
15+
setupTestHooks(this);
16+
17+
it('it generates a docs page and updates router with no docs.hbs present', function() {
18+
return emberNew({ target: 'addon' }).then(() => {
19+
return emberGenerateDestroy(['docs-page', 'foo-bar'], _file => {
20+
expect(_file('tests/dummy/app/templates/docs/foo-bar.md'))
21+
.to.exist.to.contain('# Foo bar')
22+
.to.contain('Foo bar content');
23+
24+
expect(file('tests/dummy/app/router.js')).to.contain(
25+
"this.route('foo-bar');"
26+
);
27+
28+
expect(file('tests/dummy/app/templates/docs.hbs')).to.not.exist;
29+
});
30+
});
31+
});
32+
33+
it('it generates a docs page, updates router, and adds nav item to docs.hbs', function() {
34+
return emberNew({ target: 'addon' })
35+
.then(() =>
36+
copyFixtureFile(
37+
getFixturePath('docs.hbs'),
38+
'tests/dummy/app/templates/docs.hbs'
39+
)
40+
)
41+
.then(() => {
42+
return emberGenerateDestroy(['docs-page', 'foo-bar'], _file => {
43+
expect(_file('tests/dummy/app/templates/docs/foo-bar.md'))
44+
.to.exist.to.contain('# Foo bar')
45+
.to.contain('Foo bar content');
46+
47+
expect(file('tests/dummy/app/router.js')).to.contain(
48+
"this.route('foo-bar');"
49+
);
50+
51+
expect(
52+
file('tests/dummy/app/templates/docs.hbs')
53+
).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}');
54+
});
55+
});
56+
});
57+
58+
it('it generates a docs page, updates router, and adds nav item to docs.hbs when subnav present', function() {
59+
return emberNew({ target: 'addon' })
60+
.then(() =>
61+
copyFixtureFile(
62+
getFixturePath('docs-subnav.hbs'),
63+
'tests/dummy/app/templates/docs.hbs'
64+
)
65+
)
66+
.then(() => {
67+
return emberGenerateDestroy(['docs-page', 'foo-bar'], _file => {
68+
expect(_file('tests/dummy/app/templates/docs/foo-bar.md'))
69+
.to.exist.to.contain('# Foo bar')
70+
.to.contain('Foo bar content');
71+
72+
expect(file('tests/dummy/app/router.js')).to.contain(
73+
"this.route('foo-bar');"
74+
);
75+
76+
expect(
77+
file('tests/dummy/app/templates/docs.hbs')
78+
).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}');
79+
});
80+
});
81+
});
82+
});
83+
84+
describe('Blueprints | pods docs page test', function() {
85+
setupTestHooks(this);
86+
87+
it('it generates a docs page and updates router with no docs.hbs present', function() {
88+
return emberNew({ target: 'addon', pod: true }).then(() => {
89+
return emberGenerateDestroy(['docs-page', 'foo-bar', '--pod'], _file => {
90+
expect(_file('tests/dummy/app/pods/docs/foo-bar/template.md'))
91+
.to.exist.to.contain('# Foo bar')
92+
.to.contain('Foo bar content');
93+
94+
expect(file('tests/dummy/app/router.js')).to.contain(
95+
"this.route('foo-bar');"
96+
);
97+
98+
expect(file('tests/dummy/app/pods/docs/template.hbs')).to.not.exist;
99+
});
100+
});
101+
});
102+
103+
it('it generates a docs page, updates router, and adds nav item to docs.hbs', function() {
104+
return emberNew({ target: 'addon', pod: true })
105+
.then(() =>
106+
copyFixtureFile(
107+
getFixturePath('docs.hbs'),
108+
'tests/dummy/app/pods/docs/template.hbs'
109+
)
110+
)
111+
.then(() => {
112+
return emberGenerateDestroy(
113+
['docs-page', 'foo-bar', '--pod'],
114+
_file => {
115+
expect(_file('tests/dummy/app/pods/docs/foo-bar/template.md'))
116+
.to.exist.to.contain('# Foo bar')
117+
.to.contain('Foo bar content');
118+
119+
expect(file('tests/dummy/app/router.js')).to.contain(
120+
"this.route('foo-bar');"
121+
);
122+
123+
expect(
124+
file('tests/dummy/app/pods/docs/template.hbs')
125+
).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}');
126+
}
127+
);
128+
});
129+
});
130+
131+
it('it generates a docs page, updates router, and adds nav item to docs.hbs when subnav present', function() {
132+
return emberNew({ target: 'addon', pod: true })
133+
.then(() =>
134+
copyFixtureFile(
135+
getFixturePath('docs-subnav.hbs'),
136+
'tests/dummy/app/pods/docs/template.hbs'
137+
)
138+
)
139+
.then(() => {
140+
return emberGenerateDestroy(
141+
['docs-page', 'foo-bar', '--pod'],
142+
_file => {
143+
expect(_file('tests/dummy/app/pods/docs/foo-bar/template.md'))
144+
.to.exist.to.contain('# Foo bar')
145+
.to.contain('Foo bar content');
146+
147+
expect(file('tests/dummy/app/router.js')).to.contain(
148+
"this.route('foo-bar');"
149+
);
150+
151+
expect(
152+
file('tests/dummy/app/pods/docs/template.hbs')
153+
).to.exist.to.contain('{{nav.item "Foo bar" "docs.foo-bar"}}');
154+
}
155+
);
156+
});
157+
});
158+
});
159+
160+
function copyFixtureFile(src, dest) {
161+
return fs.copy(src, path.join(process.cwd(), dest));
162+
}
163+
164+
function getFixturePath(fixtureRelativePath) {
165+
const fixturesPath = path.join(__dirname, '../..', 'fixtures', 'blueprints');
166+
167+
return path.join(fixturesPath, fixtureRelativePath);
168+
}

0 commit comments

Comments
 (0)