Skip to content

Commit a7d5c8c

Browse files
committed
Merge pull request #13325 from chadhietala/fix-object-replacement
[Glimmer 2] Actually perform R step in helpers
2 parents f3131e3 + d7d0439 commit a7d5c8c

File tree

6 files changed

+171
-143
lines changed

6 files changed

+171
-143
lines changed

packages/ember-glimmer/tests/integration/helpers/concat-test.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ moduleFor('Helpers test: {{concat}}', class extends RenderingTest {
99
}
1010

1111
['@test it updates for bound arguments']() {
12-
this.render(`{{concat first second}}`, {
13-
first: 'one',
14-
second: 'two'
12+
this.render(`{{concat model.first model.second}}`, {
13+
model: { first: 'one', second: 'two' }
1514
});
1615

1716
this.assertText('onetwo');
@@ -20,28 +19,27 @@ moduleFor('Helpers test: {{concat}}', class extends RenderingTest {
2019

2120
this.assertText('onetwo');
2221

23-
this.runTask(() => set(this.context, 'first', 'three'));
22+
this.runTask(() => set(this.context, 'model.first', 'three'));
2423

2524
this.assertText('threetwo');
2625

27-
this.runTask(() => set(this.context, 'second', 'four'));
26+
this.runTask(() => set(this.context, 'model.second', 'four'));
2827

2928
this.assertText('threefour');
3029

31-
this.runTask(() => {
32-
set(this.context, 'first', 'one');
33-
set(this.context, 'second', 'two');
34-
});
30+
this.runTask(() => set(this.context, 'model', { first: 'one', second: 'two' }));
3531

3632
this.assertText('onetwo');
3733
}
3834

3935
['@test it can be used as a sub-expression']() {
40-
this.render(`{{concat (concat first second) (concat third fourth)}}`, {
41-
first: 'one',
42-
second: 'two',
43-
third: 'three',
44-
fourth: 'four'
36+
this.render(`{{concat (concat model.first model.second) (concat model.third model.fourth)}}`, {
37+
model: {
38+
first: 'one',
39+
second: 'two',
40+
third: 'three',
41+
fourth: 'four'
42+
}
4543
});
4644

4745
this.assertText('onetwothreefour');
@@ -50,21 +48,24 @@ moduleFor('Helpers test: {{concat}}', class extends RenderingTest {
5048

5149
this.assertText('onetwothreefour');
5250

53-
this.runTask(() => set(this.context, 'first', 'five'));
51+
this.runTask(() => set(this.context, 'model.first', 'five'));
5452

5553
this.assertText('fivetwothreefour');
5654

5755
this.runTask(() => {
58-
set(this.context, 'second', 'six');
59-
set(this.context, 'third', 'seven');
56+
set(this.context, 'model.second', 'six');
57+
set(this.context, 'model.third', 'seven');
6058
});
6159

6260
this.assertText('fivesixsevenfour');
6361

6462
this.runTask(() => {
65-
set(this.context, 'first', 'one');
66-
set(this.context, 'second', 'two');
67-
set(this.context, 'third', 'three');
63+
set(this.context, 'model', {
64+
first: 'one',
65+
second: 'two',
66+
third: 'three',
67+
fourth: 'four'
68+
});
6869
});
6970

7071
this.assertText('onetwothreefour');
@@ -73,9 +74,11 @@ moduleFor('Helpers test: {{concat}}', class extends RenderingTest {
7374
['@test it can be used as input for other helpers']() {
7475
this.registerHelper('x-eq', ([ actual, expected]) => actual === expected);
7576

76-
this.render(`{{#if (x-eq (concat first second) "onetwo")}}Truthy!{{else}}False{{/if}}`, {
77-
first: 'one',
78-
second: 'two'
77+
this.render(`{{#if (x-eq (concat model.first model.second) "onetwo")}}Truthy!{{else}}False{{/if}}`, {
78+
model: {
79+
first: 'one',
80+
second: 'two'
81+
}
7982
});
8083

8184
this.assertText('Truthy!');
@@ -84,11 +87,11 @@ moduleFor('Helpers test: {{concat}}', class extends RenderingTest {
8487

8588
this.assertText('Truthy!');
8689

87-
this.runTask(() => set(this.context, 'first', 'three'));
90+
this.runTask(() => set(this.context, 'model.first', 'three'));
8891

8992
this.assertText('False');
9093

91-
this.runTask(() => set(this.context, 'first', 'one'));
94+
this.runTask(() => set(this.context, 'model', { first: 'one', second: 'two' }));
9295

9396
this.assertText('Truthy!');
9497
}

packages/ember-glimmer/tests/integration/helpers/custom-helper-test.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest {
117117
return `${value}-value`;
118118
});
119119

120-
this.render('{{hello-world name}}', {
121-
name: 'bob'
120+
this.render('{{hello-world model.name}}', {
121+
model: { name: 'bob' }
122122
});
123123

124124
this.assertText('bob-value');
@@ -131,13 +131,13 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest {
131131

132132
assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time');
133133

134-
this.runTask(() => set(this.context, 'name', 'sal'));
134+
this.runTask(() => set(this.context, 'model.name', 'sal'));
135135

136136
this.assertText('sal-value');
137137

138138
assert.strictEqual(computeCount, 2, 'compute is called exactly 2 times');
139139

140-
this.runTask(() => set(this.context, 'name', 'bob'));
140+
this.runTask(() => set(this.context, 'model', { name: 'bob' }));
141141

142142
this.assertText('bob-value');
143143

@@ -159,8 +159,8 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest {
159159
}
160160
});
161161

162-
this.render('{{hello-world name}}', {
163-
name: 'bob'
162+
this.render('{{hello-world model.name}}', {
163+
model: { name: 'bob' }
164164
});
165165

166166
this.assertText('bob-value');
@@ -173,13 +173,13 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest {
173173

174174
assert.strictEqual(computeCount, 1, 'compute is called exactly 1 time');
175175

176-
this.runTask(() => set(this.context, 'name', 'sal'));
176+
this.runTask(() => set(this.context, 'model.name', 'sal'));
177177

178178
this.assertText('sal-value');
179179

180180
assert.strictEqual(computeCount, 2, 'compute is called exactly 2 times');
181181

182-
this.runTask(() => set(this.context, 'name', 'bob'));
182+
this.runTask(() => set(this.context, 'model', { name: 'bob' }));
183183

184184
this.assertText('bob-value');
185185

@@ -192,9 +192,11 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest {
192192
return `params: ${JSON.stringify(_params)}, hash: ${JSON.stringify(_hash)}`;
193193
});
194194

195-
this.render('{{hello-world name "rich" first=age last="sam"}}', {
196-
name: 'bob',
197-
age: 42
195+
this.render('{{hello-world model.name "rich" first=model.age last="sam"}}', {
196+
model: {
197+
name: 'bob',
198+
age: 42
199+
}
198200
});
199201

200202
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
@@ -203,18 +205,15 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest {
203205

204206
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
205207

206-
this.runTask(() => set(this.context, 'name', 'sal'));
208+
this.runTask(() => set(this.context, 'model.name', 'sal'));
207209

208210
this.assertText('params: ["sal","rich"], hash: {"first":42,"last":"sam"}');
209211

210-
this.runTask(() => set(this.context, 'age', 28));
212+
this.runTask(() => set(this.context, 'model.age', 28));
211213

212214
this.assertText('params: ["sal","rich"], hash: {"first":28,"last":"sam"}');
213215

214-
this.runTask(() => {
215-
set(this.context, 'name', 'bob');
216-
set(this.context, 'age', 42);
217-
});
216+
this.runTask(() => set(this.context, 'model', { name: 'bob', age: 42 }));
218217

219218
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
220219
}
@@ -226,9 +225,11 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest {
226225
}
227226
});
228227

229-
this.render('{{hello-world name "rich" first=age last="sam"}}', {
230-
name: 'bob',
231-
age: 42
228+
this.render('{{hello-world model.name "rich" first=model.age last="sam"}}', {
229+
model: {
230+
name: 'bob',
231+
age: 42
232+
}
232233
});
233234

234235
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
@@ -237,18 +238,15 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest {
237238

238239
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
239240

240-
this.runTask(() => set(this.context, 'name', 'sal'));
241+
this.runTask(() => set(this.context, 'model.name', 'sal'));
241242

242243
this.assertText('params: ["sal","rich"], hash: {"first":42,"last":"sam"}');
243244

244-
this.runTask(() => set(this.context, 'age', 28));
245+
this.runTask(() => set(this.context, 'model.age', 28));
245246

246247
this.assertText('params: ["sal","rich"], hash: {"first":28,"last":"sam"}');
247248

248-
this.runTask(() => {
249-
set(this.context, 'name', 'bob');
250-
set(this.context, 'age', 42);
251-
});
249+
this.runTask(() => set(this.context, 'model', { name: 'bob', age: 42 }));
252250

253251
this.assertText('params: ["bob","rich"], hash: {"first":42,"last":"sam"}');
254252
}
@@ -263,10 +261,10 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest {
263261
this.render(
264262
`{{join-words "Who"
265263
(join-words "overcomes" "by")
266-
reason
264+
model.reason
267265
(join-words (join-words "hath overcome but" "half"))
268266
(join-words "his" (join-words "foe"))}}`, {
269-
reason: 'force'
267+
model: { reason: 'force' }
270268
});
271269

272270
this.assertText('Who overcomes by force hath overcome but half his foe');
@@ -275,11 +273,11 @@ moduleFor('Helpers test: custom helpers', class extends RenderingTest {
275273

276274
this.assertText('Who overcomes by force hath overcome but half his foe');
277275

278-
this.runTask(() => set(this.context, 'reason', 'Nickleback'));
276+
this.runTask(() => set(this.context, 'model.reason', 'Nickleback'));
279277

280278
this.assertText('Who overcomes by Nickleback hath overcome but half his foe');
281279

282-
this.runTask(() => set(this.context, 'reason', 'force'));
280+
this.runTask(() => set(this.context, 'model', { reason: 'force' }));
283281

284282
this.assertText('Who overcomes by force hath overcome but half his foe');
285283
}

0 commit comments

Comments
 (0)