-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This migrate the hash helper to glimmer2 and moves tests over as well. As a result I remove a contextual-component flag that was still in the hash tests. I also added tests for yielding a hash which was not covered by any tests.
- Loading branch information
1 parent
3c28cdd
commit b451aa8
Showing
5 changed files
with
207 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { helper } from '../helper'; | ||
/** | ||
@module ember | ||
@submodule ember-templates | ||
*/ | ||
|
||
/** | ||
Use the `{{hash}}` helper to create a hash to pass as an option to your | ||
components. This is specially useful for contextual components where you can | ||
just yield a hash: | ||
```handlebars | ||
{{yield (hash | ||
name='Sarah' | ||
title=office | ||
)}} | ||
``` | ||
Would result in an object such as: | ||
```js | ||
{ name: 'Sarah', title: this.get('office') } | ||
``` | ||
Where the `title` is bound to updates of the `office` property. | ||
@method hash | ||
@for Ember.Templates.helpers | ||
@param {Object} options | ||
@return {Object} Hash | ||
@public | ||
*/ | ||
|
||
function hash(params, hash, options) { | ||
return hash; | ||
} | ||
|
||
export default helper(hash); |
165 changes: 165 additions & 0 deletions
165
packages/ember-glimmer/tests/integration/helpers/hash-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import { RenderingTest, moduleFor } from '../../utils/test-case'; | ||
import { set } from 'ember-metal/property_set'; | ||
import setProperties from 'ember-metal/set_properties'; | ||
import Component from 'ember-views/components/component'; | ||
|
||
moduleFor('Helpers test: {{hash}}', class extends RenderingTest { | ||
|
||
['@test returns a hash with the right key-value']() { | ||
this.render(`{{#with (hash name=\"Sergio\") as |person|}}{{person.name}}{{/with}}`); | ||
|
||
this.assertText('Sergio'); | ||
|
||
this.runTask(() => this.rerender()); | ||
|
||
this.assertText('Sergio'); | ||
} | ||
|
||
['@test can have more than one key-value']() { | ||
this.render(`{{#with (hash name="Sergio" lastName="Arbeo") as |person|}}{{person.name}} {{person.lastName}}{{/with}}`); | ||
|
||
this.assertText('Sergio Arbeo'); | ||
|
||
this.runTask(() => this.rerender()); | ||
|
||
this.assertText('Sergio Arbeo'); | ||
} | ||
|
||
['@test binds values when variables are used']() { | ||
this.render(`{{#with (hash name=firstName lastName="Arbeo") as |person|}}{{person.name}} {{person.lastName}}{{/with}}`, { | ||
firstName: 'Marisa' | ||
}); | ||
|
||
this.assertText('Marisa Arbeo'); | ||
|
||
this.runTask(() => this.rerender()); | ||
|
||
this.assertText('Marisa Arbeo'); | ||
|
||
this.runTask(() => set(this.context, 'firstName', 'Sergio')); | ||
|
||
this.assertText('Sergio Arbeo'); | ||
|
||
this.runTask(() => set(this.context, 'firstName', 'Marisa')); | ||
|
||
this.assertText('Marisa Arbeo'); | ||
} | ||
|
||
['@test binds multiple values when variables are used']() { | ||
this.render(`{{#with (hash name=firstName lastName=lastName) as |person|}}{{person.name}} {{person.lastName}}{{/with}}`, { | ||
firstName: 'Marisa', | ||
lastName: 'Arbeo' | ||
}); | ||
|
||
this.assertText('Marisa Arbeo'); | ||
|
||
this.runTask(() => this.rerender()); | ||
|
||
this.assertText('Marisa Arbeo'); | ||
|
||
this.runTask(() => set(this.context, 'firstName', 'Sergio')); | ||
|
||
this.assertText('Sergio Arbeo'); | ||
|
||
this.runTask(() => set(this.context, 'lastName', 'Smith')); | ||
|
||
this.assertText('Sergio Smith'); | ||
|
||
this.runTask(() => setProperties(this.context, { | ||
firstName: 'Marisa', | ||
lastName: 'Arbeo' | ||
})); | ||
|
||
this.assertText('Marisa Arbeo'); | ||
} | ||
|
||
['@test hash helpers can be nested']() { | ||
this.render(`{{#with (hash person=(hash name=firstName)) as |ctx|}}{{ctx.person.name}}{{/with}}`, { | ||
firstName: 'Balint' | ||
}); | ||
|
||
this.assertText('Balint'); | ||
|
||
this.runTask(() => this.rerender()); | ||
|
||
this.assertText('Balint'); | ||
|
||
this.runTask(() => set(this.context, 'firstName', 'Chad')); | ||
|
||
this.assertText('Chad'); | ||
|
||
this.runTask(() => set(this.context, 'firstName', 'Balint')); | ||
|
||
this.assertText('Balint'); | ||
} | ||
|
||
['@test should yield hash of internal properties']() { | ||
let fooBarInstance; | ||
let FooBarComponent = Component.extend({ | ||
init() { | ||
this._super(); | ||
fooBarInstance = this; | ||
this.firstName = 'Chad'; | ||
} | ||
}); | ||
|
||
this.registerComponent('foo-bar', { | ||
ComponentClass: FooBarComponent, | ||
template: `{{yield (hash firstName=firstName)}}` | ||
}); | ||
|
||
this.render(`{{#foo-bar as |values|}}{{values.firstName}}{{/foo-bar}}`); | ||
|
||
this.assertText('Chad'); | ||
|
||
this.runTask(() => this.rerender()); | ||
|
||
this.assertText('Chad'); | ||
|
||
this.runTask(() => set(fooBarInstance, 'firstName', 'Godfrey')); | ||
|
||
this.assertText('Godfrey'); | ||
|
||
this.runTask(() => set(fooBarInstance, 'firstName', 'Chad')); | ||
|
||
this.assertText('Chad'); | ||
} | ||
|
||
['@test should yield hash of internal and external properties']() { | ||
let fooBarInstance; | ||
let FooBarComponent = Component.extend({ | ||
init() { | ||
this._super(); | ||
fooBarInstance = this; | ||
this.firstName = 'Chad'; | ||
} | ||
}); | ||
|
||
this.registerComponent('foo-bar', { | ||
ComponentClass: FooBarComponent, | ||
template: `{{yield (hash firstName=firstName lastName=lastName)}}` | ||
}); | ||
|
||
this.render(`{{#foo-bar lastName=lastName as |values|}}{{values.firstName}} {{values.lastName}}{{/foo-bar}}`, { | ||
lastName: 'Hietala' | ||
}); | ||
|
||
this.assertText('Chad Hietala'); | ||
|
||
this.runTask(() => this.rerender()); | ||
|
||
this.assertText('Chad Hietala'); | ||
|
||
this.runTask(() => set(fooBarInstance, 'firstName', 'Godfrey')); | ||
|
||
this.runTask(() => set(this.context, 'lastName', 'Chan')); | ||
|
||
this.assertText('Godfrey Chan'); | ||
|
||
this.runTask(() => set(fooBarInstance, 'firstName', 'Chad')); | ||
this.runTask(() => set(this.context, 'lastName', 'Hietala')); | ||
|
||
this.assertText('Chad Hietala'); | ||
} | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.