diff --git a/packages/ember-glimmer/tests/integration/components/curly-components-test.js b/packages/ember-glimmer/tests/integration/components/curly-components-test.js index 93acdb28afc..a0c0a69bc3c 100644 --- a/packages/ember-glimmer/tests/integration/components/curly-components-test.js +++ b/packages/ember-glimmer/tests/integration/components/curly-components-test.js @@ -2725,4 +2725,57 @@ moduleFor('Components test: curly components', class extends RenderingTest { this.render('{{foo-bar}}'); }, /didInitAttrs called/); } + + ['@test returning `true` from an action does not bubble if `target` is not specified (GH#14275)'](assert) { + this.registerComponent('display-toggle', { + ComponentClass: Component.extend({ + actions: { + show() { + assert.ok(true, 'display-toggle show action was called'); + return true; + } + } + }), + + template: `` + }); + + this.render(`{{display-toggle}}`, { + send() { + assert.notOk(true, 'send should not be called when action is not "subscribed" to'); + } + }); + + this.assertText('Show'); + + this.runTask(() => this.$('button').click()); + } + + ['@test returning `true` from an action bubbles to the `target` if specified'](assert) { + assert.expect(4); + + this.registerComponent('display-toggle', { + ComponentClass: Component.extend({ + actions: { + show() { + assert.ok(true, 'display-toggle show action was called'); + return true; + } + } + }), + + template: `` + }); + + this.render(`{{display-toggle target=this}}`, { + send(actionName) { + assert.ok(true, 'send should be called when action is "subscribed" to'); + assert.equal(actionName, 'show'); + } + }); + + this.assertText('Show'); + + this.runTask(() => this.$('button').click()); + } }); diff --git a/packages/ember-glimmer/tests/integration/components/target-action-test.js b/packages/ember-glimmer/tests/integration/components/target-action-test.js index 0aead208302..caf198a915a 100644 --- a/packages/ember-glimmer/tests/integration/components/target-action-test.js +++ b/packages/ember-glimmer/tests/integration/components/target-action-test.js @@ -205,11 +205,30 @@ moduleFor('Components test: sendAction', class extends RenderingTest { } ['@test calling sendAction on a component within a block sends to the outer scope GH#14216'](assert) { - this.registerTemplate('components/action-delegate', strip` - {{#component-a}} - {{component-b bar="derp"}} - {{/component-a}} - `); + let testContext = this; + // overrides default action-delegate so actions can be added + this.registerComponent('action-delegate', { + ComponentClass: Component.extend({ + init() { + this._super(); + testContext.delegate = this; + this.name = 'action-delegate'; + }, + + actions: { + derp(arg1) { + assert.ok(true, 'action called on action-delgate'); + assert.equal(arg1, 'something special', 'argument passed through properly'); + } + } + }), + + template: strip` + {{#component-a}} + {{component-b bar="derp"}} + {{/component-a}} + ` + }); this.registerComponent('component-a', { ComponentClass: Component.extend({ @@ -238,10 +257,7 @@ moduleFor('Components test: sendAction', class extends RenderingTest { this.renderDelegate(); - this.runTask(() => innerChild.sendAction('bar')); - - this.assertSendCount(1); - this.assertNamedSendCount('derp', 1); + this.runTask(() => innerChild.sendAction('bar', 'something special')); } }); diff --git a/packages/ember-views/lib/mixins/action_support.js b/packages/ember-views/lib/mixins/action_support.js index 174e49a73c7..df0fb77cf5a 100644 --- a/packages/ember-views/lib/mixins/action_support.js +++ b/packages/ember-views/lib/mixins/action_support.js @@ -137,7 +137,7 @@ export default Mixin.create({ if (!shouldBubble) { return; } } - target = get(this, 'target') || get(this, '_targetObject'); + target = get(this, 'target'); if (target) { assert(