Skip to content

Commit cb8aad2

Browse files
committed
Move template-only component tests
1 parent 6fe5504 commit cb8aad2

File tree

5 files changed

+112
-15
lines changed

5 files changed

+112
-15
lines changed

packages/ember-glimmer/tests/integration/components/curly-components-test.js

-12
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,6 @@ moduleFor('Components test: curly components', class extends RenderingTest {
5050
this.assertComponentElement(this.firstChild, { content: 'hello' });
5151
}
5252

53-
['@test it can render a template only component']() {
54-
this.registerComponent('foo-bar', { template: 'hello' });
55-
56-
this.render('{{foo-bar}}');
57-
58-
this.assertComponentElement(this.firstChild, { content: 'hello' });
59-
60-
this.runTask(() => this.rerender());
61-
62-
this.assertComponentElement(this.firstChild, { content: 'hello' });
63-
}
64-
6553
['@test it can have a custom id and it is not bound']() {
6654
this.registerComponent('foo-bar', { template: '{{id}} {{elementId}}' });
6755

packages/ember-glimmer/tests/integration/components/local-lookup-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ if (EMBER_MODULE_UNIFICATION) {
263263
return new LocalLookupTestResolver();
264264
}
265265

266-
registerComponent(name, { ComponentClass = null, template = null }) {
266+
registerComponent(name, { ComponentClass = Component, template = null }) {
267267
let { resolver } = this;
268268

269269
if (ComponentClass) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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 {});

packages/internal-test-helpers/lib/test-cases/abstract-rendering.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default class AbstractRenderingTestCase extends AbstractTestCase {
103103
}
104104
}
105105

106-
registerComponent(name, { ComponentClass = null, template = null }) {
106+
registerComponent(name, { ComponentClass = Component, template = null }) {
107107
let { owner } = this;
108108

109109
if (ComponentClass) {

packages/internal-test-helpers/lib/test-cases/test-resolver-application.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import AbstractApplicationTestCase from './abstract-application';
22
import { ModuleBasedResolver } from '../test-resolver';
3+
import { Component } from 'ember-glimmer';
34
import { assign } from 'ember-utils';
45

56
export default class TestResolverApplicationTestCase extends AbstractApplicationTestCase {
@@ -20,7 +21,7 @@ export default class TestResolverApplicationTestCase extends AbstractApplication
2021
}));
2122
}
2223

23-
addComponent(name, { ComponentClass = null, template = null }) {
24+
addComponent(name, { ComponentClass = Component, template = null }) {
2425
if (ComponentClass) {
2526
this.resolver.add(`component:${name}`, ComponentClass);
2627
}

0 commit comments

Comments
 (0)