Skip to content

Commit a3d9235

Browse files
committed
Merge branch 'add-helper-related'
Resolves #107
2 parents 2e1343a + a35f86f commit a3d9235

File tree

20 files changed

+540
-0
lines changed

20 files changed

+540
-0
lines changed

blueprints/-addon-import.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
'use strict';
2+
3+
var stringUtil = require('ember-cli-string-utils');
4+
var path = require('path');
5+
var inflector = require('inflection');
6+
7+
module.exports = {
8+
description: 'Generates an import wrapper.',
9+
10+
fileMapTokens: function() {
11+
return {
12+
__name__: function(options) {
13+
if (options.pod && options.hasPathToken) {
14+
return options.locals.blueprintName;
15+
}
16+
return options.dasherizedModuleName;
17+
},
18+
__path__: function(options) {
19+
if (options.pod && options.hasPathToken) {
20+
return path.join(options.podPath, options.dasherizedModuleName);
21+
}
22+
return inflector.pluralize(options.locals.blueprintName);
23+
},
24+
__root__: function(options) {
25+
if (options.inRepoAddon) {
26+
return path.join('lib', options.inRepoAddon, 'app');
27+
}
28+
return 'app';
29+
}
30+
};
31+
},
32+
33+
locals: function(options) {
34+
var addonRawName = options.inRepoAddon ? options.inRepoAddon : options.project.name();
35+
var addonName = stringUtil.dasherize(addonRawName);
36+
var fileName = stringUtil.dasherize(options.entity.name);
37+
var blueprintName = options.originBlueprintName;
38+
var modulePathSegments = [addonName, inflector.pluralize(options.originBlueprintName), fileName];
39+
40+
if (blueprintName.match(/-addon/)) {
41+
blueprintName = blueprintName.substr(0, blueprintName.indexOf('-addon'));
42+
modulePathSegments = [addonName, inflector.pluralize(blueprintName), fileName];
43+
}
44+
45+
if (options.pod) {
46+
modulePathSegments = [addonName, fileName, blueprintName];
47+
}
48+
49+
return {
50+
modulePath: modulePathSegments.join('/'),
51+
blueprintName: blueprintName
52+
};
53+
}
54+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default, <%= camelizedModuleName %> } from '<%= modulePath %>';

blueprints/helper-addon/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
module.exports = require('../-addon-import');

blueprints/helper-test/index.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
const stringUtils = require('ember-cli-string-utils');
4+
const isPackageMissing = require('ember-cli-is-package-missing');
5+
6+
const useTestFrameworkDetector = require('../test-framework-detector');
7+
8+
module.exports = useTestFrameworkDetector({
9+
description: 'Generates a helper integration test or a unit test.',
10+
11+
availableOptions: [
12+
{
13+
name: 'test-type',
14+
type: ['integration', 'unit'],
15+
default: 'integration',
16+
aliases: [
17+
{ 'i': 'integration' },
18+
{ 'u': 'unit' },
19+
{ 'integration': 'integration' },
20+
{ 'unit': 'unit' }
21+
]
22+
}
23+
],
24+
25+
fileMapTokens: function() {
26+
return {
27+
__testType__: function(options) {
28+
return options.locals.testType || 'integration';
29+
}
30+
};
31+
},
32+
33+
locals: function(options) {
34+
let testType = options.testType || 'integration';
35+
let testName = testType === 'integration' ? 'Integration' : 'Unit';
36+
let friendlyTestName = [testName, 'Helper', options.entity.name].join(' | ');
37+
38+
return {
39+
friendlyTestName: friendlyTestName,
40+
dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix),
41+
testType: testType
42+
};
43+
},
44+
45+
afterInstall: function(options) {
46+
if (!options.dryRun && options.testType === 'integration' && isPackageMissing(this, 'ember-cli-htmlbars-inline-precompile')) {
47+
return this.addPackagesToProject([
48+
{ name: 'ember-cli-htmlbars-inline-precompile', target: '^0.3.1' }
49+
]);
50+
}
51+
}
52+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect } from 'chai';
2+
<% if (testType == 'integration') { %>import { describe, it } from 'mocha';
3+
import { setupComponentTest } from 'ember-mocha';
4+
import hbs from 'htmlbars-inline-precompile';
5+
6+
describe('<%= friendlyTestName %>', function() {
7+
setupComponentTest('<%= dasherizedModuleName %>', {
8+
integration: true
9+
});
10+
11+
it('renders', function() {
12+
// Set any properties with this.set('myProperty', 'value');
13+
// Handle any actions with this.on('myAction', function(val) { ... });
14+
// Template block usage:
15+
// this.render(hbs`
16+
// {{#<%= dasherizedModuleName %>}}
17+
// template content
18+
// {{/<%= dasherizedModuleName %>}}
19+
// `);
20+
this.set('inputValue', '1234');
21+
22+
this.render(hbs`{{<%= dasherizedModuleName %> inputValue}}`);
23+
24+
expect(this.$().text().trim()).to.equal('1234');
25+
});
26+
});
27+
<% } else if (testType == 'unit') { %>import { describe, it } from 'mocha';
28+
import { <%= camelizedModuleName %> } from '<%= dasherizedPackageName %>/helpers/<%= dasherizedModuleName %>';
29+
30+
describe('<%= friendlyTestName %>', function() {
31+
32+
// Replace this with your real tests.
33+
it('works', function() {
34+
let result = <%= camelizedModuleName %>(42);
35+
expect(result).to.be.ok;
36+
});
37+
});
38+
<% } %>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { expect } from 'chai';
2+
<% if (testType == 'integration') { %>
3+
import { describeComponent, it } from 'ember-mocha';
4+
import hbs from 'htmlbars-inline-precompile';
5+
6+
describeComponent('<%= dasherizedModuleName %>', 'helper:<%= dasherizedModuleName %>',
7+
{
8+
integration: true
9+
},
10+
function() {
11+
it('renders', function() {
12+
// Set any properties with this.set('myProperty', 'value');
13+
// Handle any actions with this.on('myAction', function(val) { ... });
14+
// Template block usage:
15+
// this.render(hbs`
16+
// {{#<%= dasherizedModuleName %>}}
17+
// template content
18+
// {{/<%= dasherizedModuleName %>}}
19+
// `);
20+
this.set('inputValue', '1234');
21+
22+
this.render(hbs`{{<%= dasherizedModuleName %> inputValue}}`);
23+
24+
expect(this.$().text().trim()).to.equal('1234');
25+
});
26+
}
27+
);
28+
<% } else if (testType == 'unit') { %>import { describe, it } from 'mocha';
29+
import { <%= camelizedModuleName %> } from '<%= dasherizedPackageName %>/helpers/<%= dasherizedModuleName %>';
30+
31+
describe('<%= friendlyTestName %>', function() {
32+
33+
// Replace this with your real tests.
34+
it('works', function() {
35+
let result = <%= camelizedModuleName %>(42);
36+
expect(result).to.be.ok;
37+
});
38+
});
39+
<% } %>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<% if (testType == 'integration') { %>import { moduleForComponent, test } from 'ember-qunit';
2+
import hbs from 'htmlbars-inline-precompile';
3+
4+
moduleForComponent('<%= dasherizedModuleName %>', 'helper:<%= dasherizedModuleName %>', {
5+
integration: true
6+
});
7+
8+
// Replace this with your real tests.
9+
test('it renders', function(assert) {
10+
this.set('inputValue', '1234');
11+
12+
this.render(hbs`{{<%= dasherizedModuleName %> inputValue}}`);
13+
14+
assert.equal(this.$().text().trim(), '1234');
15+
});<% } else if (testType == 'unit') { %>
16+
import { <%= camelizedModuleName %> } from '<%= dasherizedModulePrefix %>/helpers/<%= dasherizedModuleName %>';
17+
import { module, test } from 'qunit';
18+
19+
module('<%= friendlyTestName %>');
20+
21+
// Replace this with your real tests.
22+
test('it works', function(assert) {
23+
let result = <%= camelizedModuleName %>([42]);
24+
assert.ok(result);
25+
});
26+
<% } %>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<% if (testType === 'integration') { %>import { module, test } from 'qunit';
2+
import { setupRenderingTest } from 'ember-qunit';
3+
import { render } from '@ember/test-helpers';
4+
import hbs from 'htmlbars-inline-precompile';
5+
6+
module('<%= friendlyTestName %>', function(hooks) {
7+
setupRenderingTest(hooks);
8+
9+
// Replace this with your real tests.
10+
test('it renders', async function(assert) {
11+
this.set('inputValue', '1234');
12+
13+
await render(hbs`{{<%= dasherizedModuleName %> inputValue}}`);
14+
15+
assert.equal(this.element.textContent.trim(), '1234');
16+
});
17+
});<% } else if (testType === 'unit') { %>import { <%= camelizedModuleName %> } from '<%= dasherizedModulePrefix %>/helpers/<%= dasherizedModuleName %>';
18+
import { module, test } from 'qunit';
19+
import { setupTest } from 'ember-qunit';
20+
21+
module('<%= friendlyTestName %>', function(hooks) {
22+
setupTest(hooks);
23+
24+
// Replace this with your real tests.
25+
test('it works', function(assert) {
26+
let result = <%= camelizedModuleName %>([42]);
27+
assert.ok(result);
28+
});
29+
});<% } %>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
4+
const setupTestHooks = blueprintHelpers.setupTestHooks;
5+
const emberNew = blueprintHelpers.emberNew;
6+
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
7+
8+
const chai = require('ember-cli-blueprint-test-helpers/chai');
9+
const expect = chai.expect;
10+
11+
const fixture = require('../helpers/fixture');
12+
13+
describe('Blueprint: helper-addon', function() {
14+
setupTestHooks(this);
15+
16+
describe('in addon', function() {
17+
beforeEach(function() {
18+
return emberNew({ target: 'addon' });
19+
});
20+
21+
it('helper-addon foo/bar-baz', function() {
22+
return emberGenerateDestroy(['helper-addon', 'foo/bar-baz'], _file => {
23+
expect(_file('app/helpers/foo/bar-baz.ts'))
24+
.to.equal(fixture('helper-addon.ts'));
25+
});
26+
});
27+
});
28+
});

0 commit comments

Comments
 (0)