import { RenderingTest, moduleFor } from '../../utils/test-case'; import { set } from '@ember/-internals/metal'; import { Component } from '../../utils/helpers'; moduleFor( 'Helpers test: {{yield}} helper', class extends RenderingTest { ['@test can yield to block']() { this.registerComponent('yield-comp', { template: '[In layout:] {{yield}}', }); this.render('{{#yield-comp}}[In Block:] {{object.title}}{{/yield-comp}}', { object: { title: 'Seattle' }, }); this.assertText('[In layout:] [In Block:] Seattle'); this.assertStableRerender(); this.runTask(() => set(this.context, 'object.title', 'Vancouver')); this.assertText('[In layout:] [In Block:] Vancouver'); this.runTask(() => set(this.context, 'object', { title: 'Seattle' })); this.assertText('[In layout:] [In Block:] Seattle'); } ['@test templates should yield to block inside a nested component']() { this.registerComponent('outer-comp', { template: '
{{boundText}}
{{yield}}
', }); this.render('{{#kiwi-comp}}{{boundText}}{{/kiwi-comp}}', { boundText: 'Original', }); this.assertText('InnerOriginal'); this.assertStableRerender(); this.runTask(() => set(this.context, 'boundText', 'Otherworld')); this.assertText('InnerOtherworld'); this.runTask(() => set(this.context, 'boundText', 'Original')); this.assertText('InnerOriginal'); } ["@test outer block param doesn't mask inner component property"]() { let KiwiCompComponent = Component.extend({ boundText: 'Inner' }); this.registerComponent('kiwi-comp', { ComponentClass: KiwiCompComponent, template: '{{boundText}}
{{yield}}
', }); this.render('{{#with boundText as |item|}}{{#kiwi-comp}}{{item}}{{/kiwi-comp}}{{/with}}', { boundText: 'Outer', }); this.assertText('InnerOuter'); this.assertStableRerender(); this.runTask(() => set(this.context, 'boundText', 'Otherworld')); this.assertText('InnerOtherworld'); this.runTask(() => set(this.context, 'boundText', 'Outer')); this.assertText('InnerOuter'); } ["@test inner block param doesn't mask yield property"]() { let KiwiCompComponent = Component.extend({ boundText: 'Inner' }); this.registerComponent('kiwi-comp', { ComponentClass: KiwiCompComponent, template: '{{#with boundText as |item|}}{{item}}
{{yield}}
{{/with}}', }); this.render('{{#kiwi-comp}}{{item}}{{/kiwi-comp}}', { item: 'Outer' }); this.assertText('InnerOuter'); this.assertStableRerender(); this.runTask(() => set(this.context, 'item', 'Otherworld')); this.assertText('InnerOtherworld'); this.runTask(() => set(this.context, 'item', 'Outer')); this.assertText('InnerOuter'); } ['@test can bind a block param to a component and use it in yield']() { this.registerComponent('kiwi-comp', { template: '{{content}}
{{yield}}
', }); this.render( '{{#with boundText as |item|}}{{#kiwi-comp content=item}}{{item}}{{/kiwi-comp}}{{/with}}', { boundText: 'Outer' } ); this.assertText('OuterOuter'); this.assertStableRerender(); this.runTask(() => set(this.context, 'boundText', 'Update')); this.assertText('UpdateUpdate'); this.runTask(() => set(this.context, 'boundText', 'Outer')); this.assertText('OuterOuter'); } // INUR not need with no data update ['@test yield should not introduce a view'](assert) { let ParentCompComponent = Component.extend({ isParentComponent: true }); let ChildCompComponent = Component.extend({ didReceiveAttrs() { this._super(); let parentView = this.get('parentView'); assert.ok(parentView.get('isParentComponent')); }, }); this.registerComponent('parent-comp', { ComponentClass: ParentCompComponent, template: '{{yield}}', }); this.registerComponent('child-comp', { ComponentClass: ChildCompComponent, }); this.render('{{#parent-comp}}{{child-comp}}{{/parent-comp}}'); } ['@test yield with nested components (#3220)']() { this.registerComponent('inner-component', { template: '{{yield}}' }); this.registerComponent('outer-component', { template: '{{#inner-component}}{{yield}}{{/inner-component}}', }); this.render('{{#outer-component}}Hello {{boundText}}{{/outer-component}}', { boundText: 'world', }); this.assertText('Hello world'); this.assertStableRerender(); this.runTask(() => set(this.context, 'boundText', 'update')); this.assertText('Hello update'); this.runTask(() => set(this.context, 'boundText', 'world')); this.assertText('Hello world'); } } );