diff --git a/packages/ember-glimmer/tests/integration/components/actions-test.js b/packages/ember-glimmer/tests/integration/components/actions-test.js new file mode 100644 index 00000000000..483db6da2ba --- /dev/null +++ b/packages/ember-glimmer/tests/integration/components/actions-test.js @@ -0,0 +1,89 @@ +import { Mixin } from 'ember-metal/mixin'; +import EmberObject from 'ember-runtime/system/object'; +import { moduleFor, RenderingTest } from '../../utils/test-case'; +import { Component } from '../../utils/helpers'; + +moduleFor('Component action handling', class extends RenderingTest { + ['@test Action can be handled by a function on actions object'](assert) { + assert.expect(1); + let component; + let FooBarComponent = Component.extend({ + init() { + this._super(...arguments); + component = this; + }, + actions: { + poke() { + assert.ok(true, 'poked'); + } + } + }); + + this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); + + this.render('{{foo-bar}}'); + + component.send('poke'); + } + + ['@test Action can be handled by a superclass\' actions object'](assert) { + assert.expect(4); + let component; + let SuperComponent = Component.extend({ + actions: { + foo() { + assert.ok(true, 'foo'); + }, + bar(msg) { + assert.equal(msg, 'HELLO'); + } + } + }); + + let SomeMixin = Mixin.create({ + actions: { + bar(msg) { + assert.equal(msg, 'HELLO'); + this._super(msg); + } + } + }); + + let FooBarComponent = SuperComponent.extend(SomeMixin, { + init() { + this._super(...arguments); + component = this; + }, + + actions: { + baz() { + ok(true, 'baz'); + } + } + }); + + this.registerComponent('foo-bar', { ComponentClass: FooBarComponent, template: 'hello' }); + + this.render('{{foo-bar}}'); + + component.send('foo'); + component.send('bar', 'HELLO'); + component.send('baz'); + } + + ['@test Actions cannot be provided at create time']() { + let component; + expectAssertion(() => { + component = Component.create({ + actions: { + foo() {} + } + }); + }); + + // but should be OK on an object that doesn't mix in Ember.ActionHandler + EmberObject.create({ + actions: ['foo'] + }); + } +}); diff --git a/packages/ember-views/tests/views/view/actions_test.js b/packages/ember-views/tests/views/view/actions_test.js deleted file mode 100644 index 85075183cac..00000000000 --- a/packages/ember-views/tests/views/view/actions_test.js +++ /dev/null @@ -1,102 +0,0 @@ -import run from 'ember-metal/run_loop'; -import { Mixin } from 'ember-metal/mixin'; -import Controller from 'ember-runtime/controllers/controller'; -import EmberObject from 'ember-runtime/system/object'; -import View from 'ember-views/views/view'; - -var view; - -QUnit.module('View action handling', { - teardown() { - run(function() { - if (view) { view.destroy(); } - }); - } -}); - -QUnit.test('Action can be handled by a function on actions object', function() { - expect(1); - view = View.extend({ - actions: { - poke() { - ok(true, 'poked'); - } - } - }).create(); - view.send('poke'); -}); - -QUnit.test('A handled action can be bubbled to the target for continued processing', function() { - expect(2); - view = View.extend({ - actions: { - poke() { - ok(true, 'poked 1'); - return true; - } - }, - target: Controller.extend({ - actions: { - poke() { - ok(true, 'poked 2'); - } - } - }).create() - }).create(); - view.send('poke'); -}); - -QUnit.test('Action can be handled by a superclass\' actions object', function() { - expect(4); - - var SuperView = View.extend({ - actions: { - foo() { - ok(true, 'foo'); - }, - bar(msg) { - equal(msg, 'HELLO'); - } - } - }); - - var BarViewMixin = Mixin.create({ - actions: { - bar(msg) { - equal(msg, 'HELLO'); - this._super(msg); - } - } - }); - - var IndexView = SuperView.extend(BarViewMixin, { - actions: { - baz() { - ok(true, 'baz'); - } - } - }); - - view = IndexView.create(); - view.send('foo'); - view.send('bar', 'HELLO'); - view.send('baz'); -}); - -QUnit.test('Actions cannot be provided at create time', function() { - expectAssertion(function() { - view = View.create({ - actions: { - foo() { - ok(true, 'foo'); - } - } - }); - }); - // but should be OK on an object that doesn't mix in Ember.ActionHandler - EmberObject.create({ - actions: ['foo'] - }); -}); - -