From 2a16d1dbb614cebf08145ff2c1934f06ed7f4f04 Mon Sep 17 00:00:00 2001 From: Marten Schilstra Date: Fri, 24 Jul 2015 17:45:19 +0200 Subject: [PATCH] Add support for closure actions in component integration test --- .../test-module-for-component.js | 9 ++++---- tests/test-module-for-component-test.js | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/lib/ember-test-helpers/test-module-for-component.js b/lib/ember-test-helpers/test-module-for-component.js index f1409b980..1136948aa 100644 --- a/lib/ember-test-helpers/test-module-for-component.js +++ b/lib/ember-test-helpers/test-module-for-component.js @@ -93,9 +93,12 @@ export default TestModule.extend({ setupComponentIntegrationTest: function() { var module = this; var context = this.context; + + this.actionHooks = {}; + context.dispatcher = Ember.EventDispatcher.create(); context.dispatcher.setup({}, '#ember-testing'); - this.actionHooks = {}; + context.actions = module.actionHooks; context.render = function(template) { if (!template) { @@ -111,6 +114,7 @@ export default TestModule.extend({ layout: template, container: module.container }); + module.component.set('context' ,context); module.component.set('controller', module); @@ -157,7 +161,6 @@ export default TestModule.extend({ } }, - send: function(actionName) { var hook = this.actionHooks[actionName]; if (!hook) { @@ -174,6 +177,4 @@ export default TestModule.extend({ }); } } - - }); diff --git a/tests/test-module-for-component-test.js b/tests/test-module-for-component-test.js index de1318f9f..1e5063f18 100644 --- a/tests/test-module-for-component-test.js +++ b/tests/test-module-for-component-test.js @@ -17,6 +17,7 @@ var PrettyColor = Ember.Component.extend({ }.property('name') }); + var ColorController = Ember.Controller.extend({ hexa: function() { switch( this.get('model') ) { @@ -39,11 +40,18 @@ var BoringColor = Ember.Component.extend({ } }); +var ChangingColor = Ember.Component.extend({ + didInsertElement: function() { + this.attrs.change('foo'); + } +}); + function setupRegistry() { setResolverRegistry({ 'component:x-foo': Ember.Component.extend(), 'component:pretty-color': PrettyColor, 'component:boring-color': BoringColor, + 'component:changing-color': ChangingColor, 'template:components/pretty-color': Ember.Handlebars.compile('Pretty Color: {{name}}'), 'controller:color': ColorController }); @@ -203,6 +211,19 @@ test("className", function(){ // the assertion is in the willDestroyElement() hook of the component }); + +moduleForComponent('changing-color', 'component:changing-color -- handles closure actions', { + integration: true +}); + +if (!/^1\.(11|12)/.test(Ember.VERSION)) { + test('handles a closure actions', function() { + expect(1); + this.on('colorChange', function(arg) { equal(arg, 'foo'); }); + this.render(Ember.Handlebars.compile("{{changing-color change=(action 'colorChange')}}")); + }); +} + var testModule; module('moduleForComponent: can be invoked with only the component name', { beforeEach: function(assert) {