Add tests for click events on views
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user