1
1
import {
2
- GlimmerishComponent ,
2
+ defineComponent ,
3
3
jitSuite ,
4
4
RenderTest ,
5
5
strip ,
@@ -14,18 +14,15 @@ class IfInlineTest extends RenderTest {
14
14
'inline if helper updates when tracked property changes' ( ) {
15
15
class Person {
16
16
@tracked isActive = false ;
17
-
17
+
18
18
toggle ( ) {
19
19
this . isActive = ! this . isActive ;
20
20
}
21
21
}
22
22
23
23
const person = new Person ( ) ;
24
24
25
- this . render (
26
- strip `<div>{{if this.person.isActive "Active" "Inactive"}}</div>` ,
27
- { person }
28
- ) ;
25
+ this . render ( strip `<div>{{if this.person.isActive "Active" "Inactive"}}</div>` , { person } ) ;
29
26
30
27
this . assertHTML ( '<div>Inactive</div>' , 'Initial render shows inactive state' ) ;
31
28
this . assertStableRerender ( ) ;
@@ -43,18 +40,15 @@ class IfInlineTest extends RenderTest {
43
40
'inline if helper with only truthy value updates when tracked property changes' ( ) {
44
41
class Person {
45
42
@tracked isActive = false ;
46
-
43
+
47
44
toggle ( ) {
48
45
this . isActive = ! this . isActive ;
49
46
}
50
47
}
51
48
52
49
const person = new Person ( ) ;
53
50
54
- this . render (
55
- strip `<div>{{if this.person.isActive "Active"}}</div>` ,
56
- { person }
57
- ) ;
51
+ this . render ( strip `<div>{{if this.person.isActive "Active"}}</div>` , { person } ) ;
58
52
59
53
this . assertHTML ( '<div></div>' , 'Initial render shows empty when false' ) ;
60
54
this . assertStableRerender ( ) ;
@@ -70,142 +64,133 @@ class IfInlineTest extends RenderTest {
70
64
71
65
@test
72
66
'inline if helper updates when component argument changes' ( ) {
73
- let testComponent : TestComponent ;
74
-
75
- class TestComponent extends GlimmerishComponent {
76
- @tracked isActive = false ;
77
-
78
- constructor ( owner : object , args : Record < string , unknown > ) {
79
- super ( owner , args ) ;
80
- testComponent = this ;
81
- }
82
- }
67
+ const TestComponent = defineComponent ( { } , '{{if @isActive "Active" "Inactive"}}' ) ;
83
68
84
- this . registerComponent (
85
- 'Glimmer' ,
86
- 'TestComponent' ,
87
- '{{if @isActive "Active" "Inactive"}}' ,
88
- TestComponent
89
- ) ;
90
-
91
- this . render (
92
- strip `<TestComponent @isActive={{this.isActive}} />` ,
93
- { isActive : false }
94
- ) ;
69
+ this . render ( '<TestComponent @isActive={{this.isActive}} />' , {
70
+ isActive : false ,
71
+ TestComponent,
72
+ } ) ;
95
73
96
74
this . assertHTML ( 'Inactive' , 'Initial render shows inactive state' ) ;
97
75
this . assertStableRerender ( ) ;
98
76
99
- this . rerender ( { isActive : true } ) ;
77
+ this . rerender ( { isActive : true , TestComponent } ) ;
100
78
this . assertHTML ( 'Active' , 'Updates when argument changes to true' ) ;
101
79
102
- this . rerender ( { isActive : false } ) ;
80
+ this . rerender ( { isActive : false , TestComponent } ) ;
103
81
this . assertHTML ( 'Inactive' , 'Updates when argument changes to false' ) ;
104
82
}
105
83
106
84
@test
107
85
'inline if helper with components updates when tracked property changes' ( ) {
108
86
class Person {
109
87
@tracked isActive = false ;
110
-
88
+
111
89
toggle ( ) {
112
90
this . isActive = ! this . isActive ;
113
91
}
114
92
}
115
93
116
94
const person = new Person ( ) ;
117
95
118
- class OkComponent extends GlimmerishComponent { }
119
- class KoComponent extends GlimmerishComponent { }
96
+ const Ok = defineComponent ( { } , '<div>OK Component</div>' ) ;
97
+ const Ko = defineComponent ( { } , '<div>KO Component</div>' ) ;
120
98
121
- this . registerComponent ( 'Glimmer' , 'Ok' , '<div>OK Component</div>' , OkComponent ) ;
122
- this . registerComponent ( 'Glimmer' , 'Ko' , '<div>KO Component </div>' , KoComponent ) ;
99
+ // Create a component with Ok and Ko in scope
100
+ const TestContainer = defineComponent ( { Ok , Ko } , '<div>{{if @isActive Ok Ko}} </div>' ) ;
123
101
124
- this . render (
125
- strip `<div>{{if this.person.isActive Ok Ko}}</div>` ,
126
- { person }
127
- ) ;
102
+ this . render ( '<TestContainer @isActive={{this.person.isActive}} />' , { person, TestContainer } ) ;
128
103
129
104
this . assertHTML ( '<div><div>KO Component</div></div>' , 'Initial render shows KO component' ) ;
130
105
this . assertStableRerender ( ) ;
131
106
132
107
person . toggle ( ) ;
133
108
this . rerender ( ) ;
134
- this . assertHTML ( '<div><div>OK Component</div></div>' , 'Updates to OK component when tracked property changes to true' ) ;
109
+ this . assertHTML (
110
+ '<div><div>OK Component</div></div>' ,
111
+ 'Updates to OK component when tracked property changes to true'
112
+ ) ;
135
113
136
114
person . toggle ( ) ;
137
115
this . rerender ( ) ;
138
- this . assertHTML ( '<div><div>KO Component</div></div>' , 'Updates to KO component when tracked property changes to false' ) ;
116
+ this . assertHTML (
117
+ '<div><div>KO Component</div></div>' ,
118
+ 'Updates to KO component when tracked property changes to false'
119
+ ) ;
139
120
}
140
121
141
122
@test
142
123
'inline if helper with components updates when component argument changes' ( ) {
143
- class OkComponent extends GlimmerishComponent { }
144
- class KoComponent extends GlimmerishComponent { }
145
-
146
- this . registerComponent ( 'Glimmer' , 'Ok' , '<div>OK Component</div>' , OkComponent ) ;
147
- this . registerComponent ( 'Glimmer' , 'Ko' , '<div>KO Component</div>' , KoComponent ) ;
124
+ const Ok = defineComponent ( { } , '<div>OK Component</div>' ) ;
125
+ const Ko = defineComponent ( { } , '<div>KO Component</div>' ) ;
148
126
149
- this . registerComponent (
150
- 'Glimmer' ,
151
- 'TestComponent' ,
152
- '{{if @isOk Ok Ko}}' ,
153
- class extends GlimmerishComponent { }
154
- ) ;
127
+ const TestComponent = defineComponent ( { Ok, Ko } , '{{if @isOk Ok Ko}}' ) ;
155
128
156
- this . render (
157
- strip `<TestComponent @isOk={{this.isOk}} />` ,
158
- { isOk : false }
159
- ) ;
129
+ this . render ( '<TestComponent @isOk={{this.isOk}} />' , { isOk : false , TestComponent } ) ;
160
130
161
131
this . assertHTML ( '<div>KO Component</div>' , 'Initial render shows KO component' ) ;
162
132
this . assertStableRerender ( ) ;
163
133
164
- this . rerender ( { isOk : true } ) ;
165
- this . assertHTML ( '<div>OK Component</div>' , 'Updates to OK component when argument changes to true' ) ;
134
+ this . rerender ( { isOk : true , TestComponent } ) ;
135
+ this . assertHTML (
136
+ '<div>OK Component</div>' ,
137
+ 'Updates to OK component when argument changes to true'
138
+ ) ;
166
139
167
- this . rerender ( { isOk : false } ) ;
168
- this . assertHTML ( '<div>KO Component</div>' , 'Updates to KO component when argument changes to false' ) ;
140
+ this . rerender ( { isOk : false , TestComponent } ) ;
141
+ this . assertHTML (
142
+ '<div>KO Component</div>' ,
143
+ 'Updates to KO component when argument changes to false'
144
+ ) ;
169
145
}
170
146
171
147
@test
172
148
'comparison with block form if helper using components' ( ) {
173
149
class Person {
174
150
@tracked isActive = false ;
175
-
151
+
176
152
toggle ( ) {
177
153
this . isActive = ! this . isActive ;
178
154
}
179
155
}
180
156
181
157
const person = new Person ( ) ;
182
158
183
- class OkComponent extends GlimmerishComponent { }
184
- class KoComponent extends GlimmerishComponent { }
185
-
186
- this . registerComponent ( 'Glimmer' , 'Ok' , '<div>OK Component</div>' , OkComponent ) ;
187
- this . registerComponent ( 'Glimmer' , 'Ko' , '<div>KO Component</div>' , KoComponent ) ;
159
+ const Ok = defineComponent ( { } , '<div>OK Component</div>' ) ;
160
+ const Ko = defineComponent ( { } , '<div>KO Component</div>' ) ;
188
161
189
- this . render (
190
- strip `
162
+ // Create a component with Ok and Ko in scope for both inline and block forms
163
+ const TestContainer = defineComponent (
164
+ { Ok, Ko } ,
165
+ `
191
166
<div>
192
- Inline: {{if this.person. isActive Ok Ko}}
193
- Block: {{#if this.person. isActive}}<Ok />{{else}}<Ko />{{/if}}
167
+ Inline: {{if @ isActive Ok Ko}}
168
+ Block: {{#if @ isActive}}<Ok />{{else}}<Ko />{{/if}}
194
169
</div>
195
- ` ,
196
- { person }
170
+ `
197
171
) ;
198
172
199
- this . assertHTML ( '<div>Inline: <div>KO Component</div> Block: <div>KO Component</div></div>' , 'Initial render both show KO component' ) ;
173
+ this . render ( '<TestContainer @isActive={{this.person.isActive}} />' , { person, TestContainer } ) ;
174
+
175
+ this . assertHTML (
176
+ '<div>Inline: <div>KO Component</div> Block: <div>KO Component</div></div>' ,
177
+ 'Initial render both show KO component'
178
+ ) ;
200
179
this . assertStableRerender ( ) ;
201
180
202
181
person . toggle ( ) ;
203
182
this . rerender ( ) ;
204
- this . assertHTML ( '<div>Inline: <div>OK Component</div> Block: <div>OK Component</div></div>' , 'Both update to OK component when tracked property changes to true' ) ;
183
+ this . assertHTML (
184
+ '<div>Inline: <div>OK Component</div> Block: <div>OK Component</div></div>' ,
185
+ 'Both update to OK component when tracked property changes to true'
186
+ ) ;
205
187
206
188
person . toggle ( ) ;
207
189
this . rerender ( ) ;
208
- this . assertHTML ( '<div>Inline: <div>KO Component</div> Block: <div>KO Component</div></div>' , 'Both update to KO component when tracked property changes to false' ) ;
190
+ this . assertHTML (
191
+ '<div>Inline: <div>KO Component</div> Block: <div>KO Component</div></div>' ,
192
+ 'Both update to KO component when tracked property changes to false'
193
+ ) ;
209
194
}
210
195
}
211
196
0 commit comments