Skip to content

Instantly share code, notes, and snippets.

@searls
Forked from richball/DataSetControlView.coffee
Created February 22, 2012 13:08
Show Gist options
  • Save searls/1885097 to your computer and use it in GitHub Desktop.
Save searls/1885097 to your computer and use it in GitHub Desktop.
Trying to test selection event
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
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)
window.ContactUs = {
Views: {}
Notification: {
trigger: ->
datasetChanged: "What is this? A Value?"
}
}
class ContactUs.Views.SerializableView extends Backbone.View
@searls
Copy link
Author

searls commented Feb 22, 2012

Works on tryjasmine here:

http://tryjasmine.com/?gist=1885097

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment