-
-
Save searls/1885097 to your computer and use it in GitHub Desktop.
Trying to test selection event
This file contains hidden or 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
class ContactUs.Views.DataSetControlView extends ContactUs.Views.SerializableView | |
template: "performance/data-set-control" | |
id: 'dataset-select' | |
events: | |
'change': "optionSelected" | |
initialize: -> | |
@collection.bind "reset", => @render() | |
serialize: -> | |
options: @collection.toJSON() | |
optionSelected: (event) -> | |
value = $("option:selected", $(event.currentTarget)).val(); | |
ContactUs.Notification.trigger ContactUs.Notification.datasetChanged, value |
This file contains hidden or 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
describe "ContactUs.Views.DataSetControlView", -> | |
Given -> @collection = new Backbone.Collection | |
Given -> @subject = new ContactUs.Views.DataSetControlView | |
collection: @collection | |
Then -> @subject.template == "performance/data-set-control" | |
Then -> @subject.id == "dataset-select" | |
describe "model binding", -> | |
Given -> spyOn(@subject, 'render') | |
When -> @collection.reset() | |
Then -> expect(@subject.render).toHaveBeenCalled() | |
describe "#serialize", -> | |
Given -> @collection.add { a : "FOO!"} | |
When -> @result = @subject.serialize() | |
Then -> expect(@result).toEqual | |
options : [ a : 'FOO!'] | |
describe "#optionSelected", -> | |
VALUE = 'blerg' | |
Given -> spyOn(ContactUs.Notification, 'trigger') | |
Given -> @$select = @subject.$el.affix("select#dataset-select option[value=#{VALUE}]+option[value=foo]") | |
Given -> @e = currentTarget: @$select[0] | |
When -> @subject.optionSelected(@e) | |
Then -> expect(ContactUs.Notification.trigger).toHaveBeenCalledWith(ContactUs.Notification.datasetChanged, VALUE) |
This file contains hidden or 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
window.ContactUs = { | |
Views: {} | |
Notification: { | |
trigger: -> | |
datasetChanged: "What is this? A Value?" | |
} | |
} | |
class ContactUs.Views.SerializableView extends Backbone.View |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works on tryjasmine here:
http://tryjasmine.com/?gist=1885097