-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some TS component blueprint tests
This setup can verify that the .ts blueprints are working as expected.
- Loading branch information
Showing
4 changed files
with
371 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,341 @@ | ||
'use strict'; | ||
|
||
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers'); | ||
const setupTestHooks = blueprintHelpers.setupTestHooks; | ||
const emberNew = blueprintHelpers.emberNew; | ||
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy; | ||
|
||
const chai = require('ember-cli-blueprint-test-helpers/chai'); | ||
const expect = chai.expect; | ||
|
||
const fixture = require('../helpers/fixture'); | ||
|
||
const setupTestEnvironment = require('../helpers/setup-test-environment'); | ||
const enableOctane = setupTestEnvironment.enableOctane; | ||
|
||
function glimmerComponentContents(componentName = 'Foo') { | ||
return `import Component from '@glimmer/component'; | ||
export interface ${componentName}Signature { | ||
// The arguments accepted by the component | ||
Args: {}; | ||
// Any blocks yielded by the component | ||
Blocks: { | ||
default: [] | ||
}; | ||
// The element to which \`...attributes\` is applied in the component template | ||
Element: null; | ||
} | ||
export default class ${componentName} extends Component<${componentName}Signature> {} | ||
`; | ||
} | ||
|
||
const emberComponentContents = `import Component from '@ember/component'; | ||
export default Component.extend({}); | ||
`; | ||
|
||
const templateOnlyContents = `import templateOnly from '@ember/component/template-only'; | ||
export interface FooSignature { | ||
// The arguments accepted by the component | ||
Args: {}; | ||
// Any blocks yielded by the component | ||
Blocks: { | ||
default: [] | ||
}; | ||
// The element to which \`...attributes\` is applied in the component template | ||
Element: null; | ||
} | ||
export default templateOnly<FooSignature>(); | ||
`; | ||
|
||
describe('TS Blueprint: component', function () { | ||
setupTestHooks(this); | ||
|
||
describe('in app - octane', function () { | ||
enableOctane(); | ||
|
||
beforeEach(function () { | ||
return emberNew({ cliArgs: ['--typescript'] }); | ||
}); | ||
|
||
it('component foo', function () { | ||
return emberGenerateDestroy(['component', 'foo'], (_file) => { | ||
expect(_file('app/components/foo.ts')).to.not.exist; | ||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
// classic default | ||
it('component foo --component-structure=classic --component-class=@ember/component', function () { | ||
return emberGenerateDestroy( | ||
[ | ||
'component', | ||
'foo', | ||
'--component-structure', | ||
'classic', | ||
'--component-class', | ||
'@ember/component', | ||
], | ||
(_file) => { | ||
expect(_file('app/components/foo.ts')).to.equal(emberComponentContents); | ||
|
||
expect(_file('app/templates/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
// Octane default | ||
it('component foo --component-structure=flat --component-class=@glimmer/component', function () { | ||
return emberGenerateDestroy( | ||
[ | ||
'component', | ||
'--component-structure', | ||
'flat', | ||
'--component-class', | ||
'@glimmer/component', | ||
'foo', | ||
], | ||
(_file) => { | ||
expect(_file('app/components/foo.ts')).to.equal(glimmerComponentContents()); | ||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-structure=flat', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-structure', 'flat', 'foo'], | ||
(_file) => { | ||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-structure=nested', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-structure', 'nested', 'foo'], | ||
(_file) => { | ||
expect(_file('app/components/foo/index.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-structure=classic', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-structure', 'classic', 'foo'], | ||
(_file) => { | ||
expect(_file('app/templates/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-class=@ember/component', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-class', '@ember/component', 'foo'], | ||
(_file) => { | ||
expect(_file('app/components/foo.ts')).to.equal(emberComponentContents); | ||
|
||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-class=@glimmer/component', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-class', '@glimmer/component', 'foo'], | ||
(_file) => { | ||
expect(_file('app/components/foo.ts')).to.equal(glimmerComponentContents()); | ||
|
||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --component-class=@ember/component/template-only', function () { | ||
return emberGenerateDestroy( | ||
['component', '--component-class', '@ember/component/template-only', 'foo'], | ||
(_file) => { | ||
expect(_file('app/components/foo.ts')).to.equal(templateOnlyContents); | ||
|
||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
|
||
it('component foo --no-component-class', function () { | ||
return emberGenerateDestroy(['component', '--no-component-class', 'foo'], (_file) => { | ||
expect(_file('app/components/foo.ts')).to.not.exist; | ||
|
||
expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo', | ||
componentInvocation: 'Foo', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('component x-foo', function () { | ||
return emberGenerateDestroy(['component', 'x-foo'], (_file) => { | ||
expect(_file('app/components/x-foo.ts')).to.not.exist; | ||
expect(_file('app/components/x-foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/x-foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'x-foo', | ||
componentInvocation: 'XFoo', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('component x-foo.ts', function () { | ||
return emberGenerateDestroy(['component', 'x-foo.ts'], (_file) => { | ||
expect(_file('app/components/x-foo.ts')).to.not.exist; | ||
expect(_file('app/components/x-foo.js.js')).to.not.exist; | ||
expect(_file('app/templates/components/x-foo.ts.hbs')).to.not.exist; | ||
expect(_file('tests/integration/components/x-foo-test.ts.ts')).to.not.exist; | ||
|
||
expect(_file('app/components/x-foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/x-foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'x-foo', | ||
componentInvocation: 'XFoo', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('component foo/x-foo', function () { | ||
return emberGenerateDestroy(['component', 'foo/x-foo'], (_file) => { | ||
expect(_file('app/components/foo/x-foo.ts')).to.not.exist; | ||
expect(_file('app/components/foo/x-foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo/x-foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo/x-foo', | ||
componentInvocation: 'Foo::XFoo', | ||
}, | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('component foo/x-foo --component-class="@glimmer/component"', function () { | ||
return emberGenerateDestroy( | ||
['component', 'foo/x-foo', '--component-class', '@glimmer/component'], | ||
(_file) => { | ||
expect(_file('app/components/foo/x-foo.ts')).to.equal( | ||
glimmerComponentContents('FooXFoo') | ||
); | ||
expect(_file('app/components/foo/x-foo.hbs')).to.equal('{{yield}}'); | ||
|
||
expect(_file('tests/integration/components/foo/x-foo-test.ts')).to.equal( | ||
fixture('component-test/rfc232-template.ts', { | ||
replace: { | ||
component: 'foo/x-foo', | ||
componentInvocation: 'Foo::XFoo', | ||
}, | ||
}) | ||
); | ||
} | ||
); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'my-app/tests/helpers'; | ||
import { render } from '@ember/test-helpers'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
module('Integration | Component | <%= component =%>', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it renders', async function (assert) { | ||
// Set any properties with this.set('myProperty', 'value'); | ||
// Handle any actions with this.set('myAction', function(val) { ... }); | ||
|
||
await render(hbs`<<%= componentInvocation =%> />`); | ||
|
||
assert.dom().hasText(''); | ||
|
||
// Template block usage: | ||
await render(hbs` | ||
<<%= componentInvocation =%>> | ||
template block text | ||
</<%= componentInvocation =%>> | ||
`); | ||
|
||
assert.dom().hasText('template block text'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters