|
| 1 | +import { moduleFor, RenderingTest } from '../../utils/test-case'; |
| 2 | +import { classes } from '../../utils/test-helpers'; |
| 3 | + |
| 4 | +class TemplateOnlyComponentsTest extends RenderingTest { |
| 5 | + registerComponent(name, template) { |
| 6 | + super.registerComponent(name, { template, ComponentClass: null }); |
| 7 | + } |
| 8 | + |
| 9 | + ['@test it can render a template-only component']() { |
| 10 | + this.registerComponent('foo-bar', 'hello'); |
| 11 | + |
| 12 | + this.render('{{foo-bar}}'); |
| 13 | + |
| 14 | + this.assertComponentElement(this.firstChild, { content: 'hello' }); |
| 15 | + |
| 16 | + this.assertStableRerender(); |
| 17 | + } |
| 18 | + |
| 19 | + ['@feature(ember-glimmer-named-arguments) it can render named arguments']() { |
| 20 | + this.registerComponent('foo-bar', '|{{@foo}}|{{@bar}}|'); |
| 21 | + |
| 22 | + this.render('{{foo-bar foo=foo bar=bar}}', { |
| 23 | + foo: 'foo', bar: 'bar' |
| 24 | + }); |
| 25 | + |
| 26 | + this.assertComponentElement(this.firstChild, { content: '|foo|bar|' }); |
| 27 | + |
| 28 | + this.assertStableRerender(); |
| 29 | + |
| 30 | + this.runTask(() => this.context.set('foo', 'FOO')); |
| 31 | + |
| 32 | + this.assertComponentElement(this.firstChild, { content: '|FOO|bar|' }); |
| 33 | + |
| 34 | + this.runTask(() => this.context.set('bar', 'BAR')); |
| 35 | + |
| 36 | + this.assertComponentElement(this.firstChild, { content: '|FOO|BAR|' }); |
| 37 | + |
| 38 | + this.runTask(() => this.context.setProperties({ foo: 'foo', bar: 'bar' })); |
| 39 | + |
| 40 | + this.assertComponentElement(this.firstChild, { content: '|foo|bar|' }); |
| 41 | + } |
| 42 | + |
| 43 | + ['@test it renders named arguments as reflected properties']() { |
| 44 | + this.registerComponent('foo-bar', '|{{foo}}|{{this.bar}}|'); |
| 45 | + |
| 46 | + this.render('{{foo-bar foo=foo bar=bar}}', { |
| 47 | + foo: 'foo', bar: 'bar' |
| 48 | + }); |
| 49 | + |
| 50 | + this.assertComponentElement(this.firstChild, { content: '|foo|bar|' }); |
| 51 | + |
| 52 | + this.assertStableRerender(); |
| 53 | + |
| 54 | + this.runTask(() => this.context.set('foo', 'FOO')); |
| 55 | + |
| 56 | + this.assertComponentElement(this.firstChild, { content: '|FOO|bar|' }); |
| 57 | + |
| 58 | + this.runTask(() => this.context.set('bar', null)); |
| 59 | + |
| 60 | + this.assertComponentElement(this.firstChild, { content: '|FOO||' }); |
| 61 | + |
| 62 | + this.runTask(() => this.context.setProperties({ foo: 'foo', bar: 'bar' })); |
| 63 | + |
| 64 | + this.assertComponentElement(this.firstChild, { content: '|foo|bar|' }); |
| 65 | + } |
| 66 | + |
| 67 | + ['@test it has curly component features']() { |
| 68 | + this.registerComponent('foo-bar', 'hello'); |
| 69 | + |
| 70 | + this.render('{{foo-bar tagName="p" class=class}}', { |
| 71 | + class: 'foo bar' |
| 72 | + }); |
| 73 | + |
| 74 | + this.assertComponentElement(this.firstChild, { |
| 75 | + tagName: 'p', |
| 76 | + attrs: { class: classes('foo bar ember-view') }, |
| 77 | + content: 'hello' |
| 78 | + }); |
| 79 | + |
| 80 | + this.assertStableRerender(); |
| 81 | + |
| 82 | + this.runTask(() => this.context.set('class', 'foo')); |
| 83 | + |
| 84 | + this.assertComponentElement(this.firstChild, { |
| 85 | + tagName: 'p', |
| 86 | + attrs: { class: classes('foo ember-view') }, |
| 87 | + content: 'hello' |
| 88 | + }); |
| 89 | + |
| 90 | + this.runTask(() => this.context.set('class', null)); |
| 91 | + |
| 92 | + this.assertComponentElement(this.firstChild, { |
| 93 | + tagName: 'p', |
| 94 | + attrs: { class: classes('ember-view') }, |
| 95 | + content: 'hello' |
| 96 | + }); |
| 97 | + |
| 98 | + this.runTask(() => this.context.set('class', 'foo bar')); |
| 99 | + |
| 100 | + this.assertComponentElement(this.firstChild, { |
| 101 | + tagName: 'p', |
| 102 | + attrs: { class: classes('foo bar ember-view') }, |
| 103 | + content: 'hello' |
| 104 | + }); |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +moduleFor('Components test: template-only components', class extends TemplateOnlyComponentsTest {}); |
0 commit comments