|
| 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 | +const setupTestEnvironment = require('../helpers/setup-test-environment'); |
| 14 | +const enableOctane = setupTestEnvironment.enableOctane; |
| 15 | + |
| 16 | +function glimmerComponentContents(componentName = 'Foo') { |
| 17 | + return `import Component from '@glimmer/component'; |
| 18 | +
|
| 19 | +export interface ${componentName}Signature { |
| 20 | + // The arguments accepted by the component |
| 21 | + Args: {}; |
| 22 | + // Any blocks yielded by the component |
| 23 | + Blocks: { |
| 24 | + default: [] |
| 25 | + }; |
| 26 | + // The element to which \`...attributes\` is applied in the component template |
| 27 | + Element: null; |
| 28 | +} |
| 29 | +
|
| 30 | +export default class ${componentName} extends Component<${componentName}Signature> {} |
| 31 | +`; |
| 32 | +} |
| 33 | + |
| 34 | +const emberComponentContents = `import Component from '@ember/component'; |
| 35 | +
|
| 36 | +
|
| 37 | +export default Component.extend({}); |
| 38 | +`; |
| 39 | + |
| 40 | +const templateOnlyContents = `import templateOnly from '@ember/component/template-only'; |
| 41 | +
|
| 42 | +export interface FooSignature { |
| 43 | + // The arguments accepted by the component |
| 44 | + Args: {}; |
| 45 | + // Any blocks yielded by the component |
| 46 | + Blocks: { |
| 47 | + default: [] |
| 48 | + }; |
| 49 | + // The element to which \`...attributes\` is applied in the component template |
| 50 | + Element: null; |
| 51 | +} |
| 52 | +
|
| 53 | +export default templateOnly<FooSignature>(); |
| 54 | +`; |
| 55 | + |
| 56 | +describe('TS Blueprint: component', function () { |
| 57 | + setupTestHooks(this); |
| 58 | + |
| 59 | + describe('in app - octane', function () { |
| 60 | + enableOctane(); |
| 61 | + |
| 62 | + beforeEach(function () { |
| 63 | + return emberNew({ cliArgs: ['--typescript'] }); |
| 64 | + }); |
| 65 | + |
| 66 | + it('component foo', function () { |
| 67 | + return emberGenerateDestroy(['component', 'foo'], (_file) => { |
| 68 | + expect(_file('app/components/foo.ts')).to.not.exist; |
| 69 | + expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); |
| 70 | + |
| 71 | + expect(_file('tests/integration/components/foo-test.ts')).to.equal( |
| 72 | + fixture('component-test/rfc232-template.ts', { |
| 73 | + replace: { |
| 74 | + component: 'foo', |
| 75 | + componentInvocation: 'Foo', |
| 76 | + }, |
| 77 | + }) |
| 78 | + ); |
| 79 | + }); |
| 80 | + }); |
| 81 | + |
| 82 | + // classic default |
| 83 | + it('component foo --component-structure=classic --component-class=@ember/component', function () { |
| 84 | + return emberGenerateDestroy( |
| 85 | + [ |
| 86 | + 'component', |
| 87 | + 'foo', |
| 88 | + '--component-structure', |
| 89 | + 'classic', |
| 90 | + '--component-class', |
| 91 | + '@ember/component', |
| 92 | + ], |
| 93 | + (_file) => { |
| 94 | + expect(_file('app/components/foo.ts')).to.equal(emberComponentContents); |
| 95 | + |
| 96 | + expect(_file('app/templates/components/foo.hbs')).to.equal('{{yield}}'); |
| 97 | + |
| 98 | + expect(_file('tests/integration/components/foo-test.ts')).to.equal( |
| 99 | + fixture('component-test/rfc232-template.ts', { |
| 100 | + replace: { |
| 101 | + component: 'foo', |
| 102 | + componentInvocation: 'Foo', |
| 103 | + }, |
| 104 | + }) |
| 105 | + ); |
| 106 | + } |
| 107 | + ); |
| 108 | + }); |
| 109 | + |
| 110 | + // Octane default |
| 111 | + it('component foo --component-structure=flat --component-class=@glimmer/component', function () { |
| 112 | + return emberGenerateDestroy( |
| 113 | + [ |
| 114 | + 'component', |
| 115 | + '--component-structure', |
| 116 | + 'flat', |
| 117 | + '--component-class', |
| 118 | + '@glimmer/component', |
| 119 | + 'foo', |
| 120 | + ], |
| 121 | + (_file) => { |
| 122 | + expect(_file('app/components/foo.ts')).to.equal(glimmerComponentContents()); |
| 123 | + expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); |
| 124 | + |
| 125 | + expect(_file('tests/integration/components/foo-test.ts')).to.equal( |
| 126 | + fixture('component-test/rfc232-template.ts', { |
| 127 | + replace: { |
| 128 | + component: 'foo', |
| 129 | + componentInvocation: 'Foo', |
| 130 | + }, |
| 131 | + }) |
| 132 | + ); |
| 133 | + } |
| 134 | + ); |
| 135 | + }); |
| 136 | + |
| 137 | + it('component foo --component-structure=flat', function () { |
| 138 | + return emberGenerateDestroy( |
| 139 | + ['component', '--component-structure', 'flat', 'foo'], |
| 140 | + (_file) => { |
| 141 | + expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); |
| 142 | + |
| 143 | + expect(_file('tests/integration/components/foo-test.ts')).to.equal( |
| 144 | + fixture('component-test/rfc232-template.ts', { |
| 145 | + replace: { |
| 146 | + component: 'foo', |
| 147 | + componentInvocation: 'Foo', |
| 148 | + }, |
| 149 | + }) |
| 150 | + ); |
| 151 | + } |
| 152 | + ); |
| 153 | + }); |
| 154 | + |
| 155 | + it('component foo --component-structure=nested', function () { |
| 156 | + return emberGenerateDestroy( |
| 157 | + ['component', '--component-structure', 'nested', 'foo'], |
| 158 | + (_file) => { |
| 159 | + expect(_file('app/components/foo/index.hbs')).to.equal('{{yield}}'); |
| 160 | + |
| 161 | + expect(_file('tests/integration/components/foo-test.ts')).to.equal( |
| 162 | + fixture('component-test/rfc232-template.ts', { |
| 163 | + replace: { |
| 164 | + component: 'foo', |
| 165 | + componentInvocation: 'Foo', |
| 166 | + }, |
| 167 | + }) |
| 168 | + ); |
| 169 | + } |
| 170 | + ); |
| 171 | + }); |
| 172 | + |
| 173 | + it('component foo --component-structure=classic', function () { |
| 174 | + return emberGenerateDestroy( |
| 175 | + ['component', '--component-structure', 'classic', 'foo'], |
| 176 | + (_file) => { |
| 177 | + expect(_file('app/templates/components/foo.hbs')).to.equal('{{yield}}'); |
| 178 | + |
| 179 | + expect(_file('tests/integration/components/foo-test.ts')).to.equal( |
| 180 | + fixture('component-test/rfc232-template.ts', { |
| 181 | + replace: { |
| 182 | + component: 'foo', |
| 183 | + componentInvocation: 'Foo', |
| 184 | + }, |
| 185 | + }) |
| 186 | + ); |
| 187 | + } |
| 188 | + ); |
| 189 | + }); |
| 190 | + |
| 191 | + it('component foo --component-class=@ember/component', function () { |
| 192 | + return emberGenerateDestroy( |
| 193 | + ['component', '--component-class', '@ember/component', 'foo'], |
| 194 | + (_file) => { |
| 195 | + expect(_file('app/components/foo.ts')).to.equal(emberComponentContents); |
| 196 | + |
| 197 | + expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); |
| 198 | + |
| 199 | + expect(_file('tests/integration/components/foo-test.ts')).to.equal( |
| 200 | + fixture('component-test/rfc232-template.ts', { |
| 201 | + replace: { |
| 202 | + component: 'foo', |
| 203 | + componentInvocation: 'Foo', |
| 204 | + }, |
| 205 | + }) |
| 206 | + ); |
| 207 | + } |
| 208 | + ); |
| 209 | + }); |
| 210 | + |
| 211 | + it('component foo --component-class=@glimmer/component', function () { |
| 212 | + return emberGenerateDestroy( |
| 213 | + ['component', '--component-class', '@glimmer/component', 'foo'], |
| 214 | + (_file) => { |
| 215 | + expect(_file('app/components/foo.ts')).to.equal(glimmerComponentContents()); |
| 216 | + |
| 217 | + expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); |
| 218 | + |
| 219 | + expect(_file('tests/integration/components/foo-test.ts')).to.equal( |
| 220 | + fixture('component-test/rfc232-template.ts', { |
| 221 | + replace: { |
| 222 | + component: 'foo', |
| 223 | + componentInvocation: 'Foo', |
| 224 | + }, |
| 225 | + }) |
| 226 | + ); |
| 227 | + } |
| 228 | + ); |
| 229 | + }); |
| 230 | + |
| 231 | + it('component foo --component-class=@ember/component/template-only', function () { |
| 232 | + return emberGenerateDestroy( |
| 233 | + ['component', '--component-class', '@ember/component/template-only', 'foo'], |
| 234 | + (_file) => { |
| 235 | + expect(_file('app/components/foo.ts')).to.equal(templateOnlyContents); |
| 236 | + |
| 237 | + expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); |
| 238 | + |
| 239 | + expect(_file('tests/integration/components/foo-test.ts')).to.equal( |
| 240 | + fixture('component-test/rfc232-template.ts', { |
| 241 | + replace: { |
| 242 | + component: 'foo', |
| 243 | + componentInvocation: 'Foo', |
| 244 | + }, |
| 245 | + }) |
| 246 | + ); |
| 247 | + } |
| 248 | + ); |
| 249 | + }); |
| 250 | + |
| 251 | + it('component foo --no-component-class', function () { |
| 252 | + return emberGenerateDestroy(['component', '--no-component-class', 'foo'], (_file) => { |
| 253 | + expect(_file('app/components/foo.ts')).to.not.exist; |
| 254 | + |
| 255 | + expect(_file('app/components/foo.hbs')).to.equal('{{yield}}'); |
| 256 | + |
| 257 | + expect(_file('tests/integration/components/foo-test.ts')).to.equal( |
| 258 | + fixture('component-test/rfc232-template.ts', { |
| 259 | + replace: { |
| 260 | + component: 'foo', |
| 261 | + componentInvocation: 'Foo', |
| 262 | + }, |
| 263 | + }) |
| 264 | + ); |
| 265 | + }); |
| 266 | + }); |
| 267 | + |
| 268 | + it('component x-foo', function () { |
| 269 | + return emberGenerateDestroy(['component', 'x-foo'], (_file) => { |
| 270 | + expect(_file('app/components/x-foo.ts')).to.not.exist; |
| 271 | + expect(_file('app/components/x-foo.hbs')).to.equal('{{yield}}'); |
| 272 | + |
| 273 | + expect(_file('tests/integration/components/x-foo-test.ts')).to.equal( |
| 274 | + fixture('component-test/rfc232-template.ts', { |
| 275 | + replace: { |
| 276 | + component: 'x-foo', |
| 277 | + componentInvocation: 'XFoo', |
| 278 | + }, |
| 279 | + }) |
| 280 | + ); |
| 281 | + }); |
| 282 | + }); |
| 283 | + |
| 284 | + it('component x-foo.ts', function () { |
| 285 | + return emberGenerateDestroy(['component', 'x-foo.ts'], (_file) => { |
| 286 | + expect(_file('app/components/x-foo.ts')).to.not.exist; |
| 287 | + expect(_file('app/components/x-foo.js.js')).to.not.exist; |
| 288 | + expect(_file('app/templates/components/x-foo.ts.hbs')).to.not.exist; |
| 289 | + expect(_file('tests/integration/components/x-foo-test.ts.ts')).to.not.exist; |
| 290 | + |
| 291 | + expect(_file('app/components/x-foo.hbs')).to.equal('{{yield}}'); |
| 292 | + |
| 293 | + expect(_file('tests/integration/components/x-foo-test.ts')).to.equal( |
| 294 | + fixture('component-test/rfc232-template.ts', { |
| 295 | + replace: { |
| 296 | + component: 'x-foo', |
| 297 | + componentInvocation: 'XFoo', |
| 298 | + }, |
| 299 | + }) |
| 300 | + ); |
| 301 | + }); |
| 302 | + }); |
| 303 | + |
| 304 | + it('component foo/x-foo', function () { |
| 305 | + return emberGenerateDestroy(['component', 'foo/x-foo'], (_file) => { |
| 306 | + expect(_file('app/components/foo/x-foo.ts')).to.not.exist; |
| 307 | + expect(_file('app/components/foo/x-foo.hbs')).to.equal('{{yield}}'); |
| 308 | + |
| 309 | + expect(_file('tests/integration/components/foo/x-foo-test.ts')).to.equal( |
| 310 | + fixture('component-test/rfc232-template.ts', { |
| 311 | + replace: { |
| 312 | + component: 'foo/x-foo', |
| 313 | + componentInvocation: 'Foo::XFoo', |
| 314 | + }, |
| 315 | + }) |
| 316 | + ); |
| 317 | + }); |
| 318 | + }); |
| 319 | + |
| 320 | + it('component foo/x-foo --component-class="@glimmer/component"', function () { |
| 321 | + return emberGenerateDestroy( |
| 322 | + ['component', 'foo/x-foo', '--component-class', '@glimmer/component'], |
| 323 | + (_file) => { |
| 324 | + expect(_file('app/components/foo/x-foo.ts')).to.equal( |
| 325 | + glimmerComponentContents('FooXFoo') |
| 326 | + ); |
| 327 | + expect(_file('app/components/foo/x-foo.hbs')).to.equal('{{yield}}'); |
| 328 | + |
| 329 | + expect(_file('tests/integration/components/foo/x-foo-test.ts')).to.equal( |
| 330 | + fixture('component-test/rfc232-template.ts', { |
| 331 | + replace: { |
| 332 | + component: 'foo/x-foo', |
| 333 | + componentInvocation: 'Foo::XFoo', |
| 334 | + }, |
| 335 | + }) |
| 336 | + ); |
| 337 | + } |
| 338 | + ); |
| 339 | + }); |
| 340 | + }); |
| 341 | +}); |
0 commit comments