From 8c036b99e393a7169123c1be08cb446fc4d10781 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Mon, 2 Sep 2019 13:37:55 +0900 Subject: [PATCH 1/6] [CLEANUP] Refactor tests away from implicit `this` Cleaned up a bunch of tests to use `{{this.model}}` explicitly, as opposed to the implicit `{{model}}`. Most of these tests just so happened to use a context variable named `model`, but otherwise has nothing to do with controllers or routing. They probably can be further refactored to use a different name altogether to avoid confusion. Also took the opportunity to convert things into async functions in several places. --- .../angle-bracket-invocation-test.js | 4 +- .../components/attribute-bindings-test.js | 2 +- .../components/class-bindings-test.js | 2 +- .../components/contextual-components-test.js | 57 ++++++++++--------- .../components/curly-components-test.js | 8 +-- .../integration/components/life-cycle-test.js | 20 +++---- .../components/textarea-angle-test.js | 4 +- .../components/textarea-curly-test.js | 4 +- .../glimmer/tests/integration/content-test.js | 35 ++++++------ .../tests/integration/helpers/-class-test.js | 2 +- .../tests/integration/helpers/array-test.js | 15 ++--- .../tests/integration/helpers/concat-test.js | 6 +- .../integration/helpers/custom-helper-test.js | 12 ++-- .../helpers/element-action-test.js | 2 +- .../tests/integration/helpers/hash-test.js | 12 ++-- .../tests/integration/helpers/mut-test.js | 15 +++-- .../tests/integration/helpers/partial-test.js | 20 +++---- .../tests/integration/helpers/tracked-test.js | 4 +- .../tests/integration/helpers/unbound-test.js | 22 +++---- .../glimmer/tests/integration/input-test.js | 2 +- .../glimmer/tests/integration/svg-test.js | 8 +-- .../tests/integration/syntax/each-test.js | 14 ++--- .../tests/routing/decoupled_basic_test.js | 56 ++++++++---------- 23 files changed, 165 insertions(+), 161 deletions(-) diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/angle-bracket-invocation-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/angle-bracket-invocation-test.js index 037f54da93e..40cf897a6c8 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/angle-bracket-invocation-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/angle-bracket-invocation-test.js @@ -418,7 +418,7 @@ moduleFor( template: '{{@foo}}', }); - this.render('', { + this.render('', { model: { bar: 'Hola', }, @@ -444,7 +444,7 @@ moduleFor( template: '{{foo}}', }); - this.render('', { + this.render('', { model: { bar: 'Hola', }, diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/attribute-bindings-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/attribute-bindings-test.js index ea7b83dc9f6..238b6e70552 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/attribute-bindings-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/attribute-bindings-test.js @@ -66,7 +66,7 @@ moduleFor( template: 'hello', }); - this.render('{{foo-bar foo=model.foo baz=model.baz}}', { + this.render('{{foo-bar foo=this.model.foo baz=this.model.baz}}', { model: { foo: undefined, baz: { bar: 'bar' } }, }); diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/class-bindings-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/class-bindings-test.js index 91878aeed43..80634cec759 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/class-bindings-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/class-bindings-test.js @@ -82,7 +82,7 @@ moduleFor( template: 'hello', }); - this.render('{{foo-bar joker=model.wat batman=model.super}}', { + this.render('{{foo-bar joker=this.model.wat batman=this.model.super}}', { model: { wat: false, super: { robin: true } }, }); diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js index e6bb9c711f0..e44812e0b85 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/contextual-components-test.js @@ -51,7 +51,7 @@ moduleFor( template: '{{#each params as |p|}}{{p}}{{/each}}', }); - this.render('{{component (component "-looked-up" model.greeting model.name)}}', { + this.render('{{component (component "-looked-up" this.model.greeting this.model.name)}}', { model: { greeting: 'Gabon ', name: 'Zack', @@ -87,7 +87,7 @@ moduleFor( }); this.render( - '{{component (component "-looked-up" model.greeting model.name) model.name model.greeting}}', + '{{component (component "-looked-up" this.model.greeting this.model.name) this.model.name this.model.greeting}}', { model: { greeting: 'Gabon ', @@ -123,12 +123,15 @@ moduleFor( template: '{{#each params as |p|}}{{p}}{{/each}}', }); - this.render('{{component (component (component "-looked-up" model.greeting model.name))}}', { - model: { - greeting: 'Gabon ', - name: 'Zack', - }, - }); + this.render( + '{{component (component (component "-looked-up" this.model.greeting this.model.name))}}', + { + model: { + greeting: 'Gabon ', + name: 'Zack', + }, + } + ); this.assertText('Gabon Zack'); @@ -158,7 +161,7 @@ moduleFor( }); this.render( - '{{component (component (component "-looked-up" model.greeting model.name) model.name model.greeting)}}', + '{{component (component (component "-looked-up" this.model.greeting this.model.name) this.model.name this.model.greeting)}}', { model: { greeting: 'Gabon ', @@ -214,7 +217,7 @@ moduleFor( template: 'Namaste', }); - this.render('{{component (component model.lookupComponent)}}', { + this.render('{{component (component this.model.lookupComponent)}}', { model: { lookupComponent: '-mandarin', }, @@ -240,7 +243,7 @@ moduleFor( template: '{{greeting}}', }); - this.render(`{{component (component "-looked-up" greeting=model.greeting)}}`, { + this.render(`{{component (component "-looked-up" greeting=this.model.greeting)}}`, { model: { greeting: 'Hodi', }, @@ -268,7 +271,7 @@ moduleFor( this.render( strip` - {{#with (hash comp=(component "-looked-up" greeting=model.greeting)) as |my|}} + {{#with (hash comp=(component "-looked-up" greeting=this.model.greeting)) as |my|}} {{#my.comp}}{{/my.comp}} {{/with}}`, { @@ -338,7 +341,7 @@ moduleFor( strip` {{#with (component "-looked-up" greeting="Hola" name="Dolores" age=33) as |first|}} {{#with (component first greeting="Hej" name="Sigmundur") as |second|}} - {{component second greeting=model.greeting}} + {{component second greeting=this.model.greeting}} {{/with}} {{/with}}`, { @@ -379,7 +382,7 @@ moduleFor( }); this.render( - '{{component "-inner-component" (component "-looked-up" model.outerName model.outerAge)}}', + '{{component "-inner-component" (component "-looked-up" this.model.outerName this.model.outerAge)}}', { model: { outerName: 'Outer', @@ -425,7 +428,7 @@ moduleFor( }); this.render( - '{{component "-inner-component" (component "-looked-up" name=model.outerName age=model.outerAge)}}', + '{{component "-inner-component" (component "-looked-up" name=this.model.outerName age=this.model.outerAge)}}', { model: { outerName: 'Outer', @@ -468,7 +471,7 @@ moduleFor( template: '{{greeting}} {{name}}', }); - this.render('{{component (component "-looked-up" model.name greeting="Hodi")}}', { + this.render('{{component (component "-looked-up" this.model.name greeting="Hodi")}}', { model: { name: 'Hodari', }, @@ -622,7 +625,7 @@ moduleFor( this.render( strip` {{#with (hash lookedup=(component "-looked-up")) as |object|}} - {{object.lookedup expectedText=model.expectedText}} + {{object.lookedup expectedText=this.model.expectedText}} {{/with}}`, { model: { @@ -654,7 +657,7 @@ moduleFor( this.render( strip` - {{#with (hash lookedup=(component "-looked-up" expectedText=model.expectedText)) as |object|}} + {{#with (hash lookedup=(component "-looked-up" expectedText=this.model.expectedText)) as |object|}} {{object.lookedup}} {{/with}}`, { @@ -692,7 +695,7 @@ moduleFor( this.render( strip` {{#with (hash lookedup=(component "-looked-up")) as |object|}} - {{object.lookedup model.expectedText "Hola"}} + {{object.lookedup this.model.expectedText "Hola"}} {{/with}}`, { model: { @@ -774,7 +777,7 @@ moduleFor( `, }); - this.render('{{my-action-component myProp=model.myProp}}', { + this.render('{{my-action-component myProp=this.model.myProp}}', { model: { myProp: 1, }, @@ -839,8 +842,8 @@ moduleFor( this.render( strip` - {{component (component "change-button" model.val2)}} - {{model.val2}}`, + {{component (component "change-button" this.model.val2)}} + {{this.model.val2}}`, { model: { val2: 8, @@ -1363,7 +1366,7 @@ moduleFor( class ContextualComponentMutableParamsTest extends RenderingTestCase { render(templateStr, context = {}) { super.render( - `${templateStr}{{model.val2}}`, + `${templateStr}{{this.model.val2}}`, assign(context, { model: { val2: 8 } }) ); } @@ -1413,7 +1416,7 @@ applyMixins( { title: 'param', setup() { - this.render('{{component (component "change-button" model.val2)}}'); + this.render('{{component (component "change-button" this.model.val2)}}'); }, }, @@ -1427,7 +1430,7 @@ applyMixins( template: '{{component components.comp}}', }); - this.render('{{my-comp (hash comp=(component "change-button" model.val2))}}'); + this.render('{{my-comp (hash comp=(component "change-button" this.model.val2))}}'); }, }, @@ -1438,7 +1441,7 @@ applyMixins( template: '{{component component}}', }); - this.render('{{my-comp component=(component "change-button" val=model.val2)}}'); + this.render('{{my-comp component=(component "change-button" val=this.model.val2)}}'); }, }, @@ -1450,7 +1453,7 @@ applyMixins( }); this.render( - '{{my-comp components=(hash button=(component "change-button" val=model.val2))}}' + '{{my-comp components=(hash button=(component "change-button" val=this.model.val2))}}' ); }, }, diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js index cb0c3dde880..dfd78aef171 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/curly-components-test.js @@ -429,7 +429,7 @@ moduleFor( ['@test should apply classes of the dasherized property name when bound property specified is true']() { this.registerComponent('foo-bar', { template: 'hello' }); - this.render('{{foo-bar class=model.someTruth}}', { + this.render('{{foo-bar class=this.model.someTruth}}', { model: { someTruth: true }, }); @@ -688,7 +688,7 @@ moduleFor( template: '{{@foo}}', }); - this.render('{{foo-bar foo=model.bar}}', { + this.render('{{foo-bar foo=this.model.bar}}', { model: { bar: 'Hola', }, @@ -714,7 +714,7 @@ moduleFor( template: '{{foo}}', }); - this.render('{{foo-bar foo=model.bar}}', { + this.render('{{foo-bar foo=this.model.bar}}', { model: { bar: 'Hola', }, @@ -1478,7 +1478,7 @@ moduleFor( `, }); - this.render('{{foo-bar value=model.value items=model.items}}', { + this.render('{{foo-bar value=this.model.value items=this.model.items}}', { model: { value: 'wat', items: [1, 2, 3], diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js index b62e9ff3951..295a507c72f 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/life-cycle-test.js @@ -1465,16 +1465,16 @@ moduleFor( this.render( strip` - {{#each items as |item|}} - {{#parent-component itemId=item.id}}{{item.id}}{{/parent-component}} - {{/each}} - {{#if model.shouldShow}} - {{#parent-component itemId=6}}6{{/parent-component}} - {{/if}} - {{#if model.shouldShow}} - {{#parent-component itemId=7}}7{{/parent-component}} - {{/if}} - `, + {{#each items as |item|}} + {{#parent-component itemId=item.id}}{{item.id}}{{/parent-component}} + {{/each}} + {{#if this.model.shouldShow}} + {{#parent-component itemId=6}}6{{/parent-component}} + {{/if}} + {{#if this.model.shouldShow}} + {{#parent-component itemId=7}}7{{/parent-component}} + {{/if}} + `, { items: array, model: { shouldShow: true }, diff --git a/packages/@ember/-internals/glimmer/tests/integration/components/textarea-angle-test.js b/packages/@ember/-internals/glimmer/tests/integration/components/textarea-angle-test.js index 97a1a025fa6..592107c7143 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/components/textarea-angle-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/components/textarea-angle-test.js @@ -150,7 +150,7 @@ moduleFor( } ['@test Should bind its contents to the specified @value']() { - this.render('