Created
March 11, 2014 19:23
-
-
Save coderberry/9493138 to your computer and use it in GitHub Desktop.
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
var EmbedBtnDropdownComponent = Ember.Component.extend({ | |
classNames: 'return-types', | |
actions: { | |
embedItem: function(returnType) { | |
this.sendAction('embedItem', returnType); | |
} | |
} | |
}); | |
export default EmbedBtnDropdownComponent; | |
------- | |
<div class="btn-group"> | |
<button type="button" rel="default-embed" class="btn btn-xs btn-info" {{action 'embedItem' item.defaultReturnType}}>Embed</button> | |
<button type="button" class="btn btn-xs btn-info dropdown-toggle" data-toggle="dropdown"> | |
<span class="caret"></span> | |
<span class="sr-only">Toggle Dropdown</span> | |
</button> | |
<ul class="dropdown-menu pull-right" role="menu"> | |
{{#each returnType in item.returnableReturnTypes}} | |
<li><a style="text-align: left !important;" href="#" {{action 'embedItem' returnType}}>{{returnType.displayReturnType}}</a></li> | |
{{/each}} | |
</ul> | |
</div> | |
---- | |
import { test, moduleForComponent } from 'ember-qunit'; | |
import EmbedBtnDropdownComponent from 'appkit/components/embed-btn-dropdown'; | |
var component, item, rt1, rt2, rt3; | |
moduleForComponent('embed-btn-dropdown', 'Unit: components/embed-btn-dropdown', { | |
setup: function() { | |
rt1 = Ember.Object.create({ displayReturnType: 'rt1' }); | |
rt2 = Ember.Object.create({ displayReturnType: 'rt2' }); | |
rt3 = Ember.Object.create({ displayReturnType: 'rt3' }); | |
item = Ember.Object.create({ | |
returnableReturnTypes: [rt1, rt2, rt3], | |
defaultReturnType: rt2 | |
}); | |
component = this.subject({ item: item }); | |
} | |
}); | |
test('sends the defaultReturnType when clicking the default button', function() { | |
expect(1); | |
var spy = sinon.spy(component, 'sendAction'); | |
this.append(); | |
component.$('button[rel="default-embed"]').simulate('click'); | |
ok(spy.withArgs('embedItem', rt2).calledOnce, 'embedItem was called with rt2 (default) as argument'); | |
}); | |
test('sends the selected return type when clicking the dropdown button option', function() { | |
expect(2); | |
var spy = sinon.spy(component, 'sendAction'); | |
this.append(); | |
component.$('button.dropdown-toggle').simulate('click'); | |
equal(component.$('ul li').length, 3); | |
component.$('ul li:first a').simulate('click'); | |
ok(spy.withArgs('embedItem', rt1).calledOnce, 'embedItem was called with rt1 as argument'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment