Commit fedfe862 by David Baumgold

Add tests for click events on views

parent 070d24cf
......@@ -23,6 +23,7 @@ describe "CMS.Models.SystemFeedback", ->
expect(@model.get("shown")).toEqual(false)
expect(spy).toHaveBeenCalled()
describe "CMS.Models.WarningMessage", ->
beforeEach ->
@model = new CMS.Models.WarningMessage()
......@@ -43,4 +44,3 @@ describe "CMS.Models.ConfirmationMessage", ->
it "should have the correct type", ->
expect(@model.get("type")).toEqual("confirmation")
......@@ -50,3 +50,28 @@ describe "CMS.Views.SystemFeedback", ->
@model.hide()
# expect($("body")).not.toHaveClass("prompt-is-shown")
describe "SystemFeedback click events", ->
beforeEach ->
@model = new CMS.Models.WarningMessage(
title: "Unsaved",
message: "Your content is currently unsaved.",
actions:
primary:
text: "Save",
click: jasmine.createSpy('primaryClick')
secondary: [{
text: "Revert",
click: jasmine.createSpy('secondaryClick')
}]
)
@view = new CMS.Views.Alert({model: @model})
it "should trigger the primary event on a primary click", ->
@view.primaryClick()
expect(@model.get('actions').primary.click).toHaveBeenCalled()
it "should trigger the secondary event on a secondary click", ->
@view.secondaryClick()
expect(@model.get('actions').secondary[0].click).toHaveBeenCalled()
......@@ -38,7 +38,12 @@ CMS.Views.SystemFeedback = Backbone.View.extend({
var secondaryList = actions.secondary;
if(!secondaryList) { return; }
// which secondary action was clicked?
var i = _.indexOf(this.$(".action-secondary"), e.target);
var i;
if(e && e.target) {
i = _.indexOf(this.$(".action-secondary"), e.target);
} else {
i = 0;
}
var secondary = this.model.get("actions").secondary[i];
if(secondary.click) {
secondary.click.call(this.model);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment