|
// 'Arch' is my custom namespace |
|
|
|
describe("Showing an error", function() { |
|
|
|
var errorText = "Something incredibly untoward has happened."; |
|
|
|
it("updates the element classes", function() { |
|
loadFixtures("flash.html"); |
|
Arch.Flash.showError(errorText); |
|
expect($("#flash-msg .user-msg-detail")).toHaveClass("error"); |
|
expect($("#flash-msg .user-msg-detail")).not.toHaveClass("notice"); |
|
}); |
|
|
|
it("sets the text of the flash element", function() { |
|
loadFixtures("flash.html"); |
|
Arch.Flash.showError(errorText); |
|
expect($("#flash-msg .user-msg-detail span")).toHaveText("Something incredibly untoward has happened."); |
|
}); |
|
|
|
it("sets the text of the flash element", function() { |
|
loadFixtures("flash.html"); |
|
Arch.Flash.showError(errorText); |
|
expect($("#flash-msg .user-msg-detail span")).toHaveText("Something incredibly untoward has happened."); |
|
}); |
|
|
|
it("doesn't fade the message automatically", function(){ |
|
spyOn(Arch.Flash, "_fadeOut"); |
|
loadFixtures("flash.html"); |
|
Arch.Flash.showError(errorText); |
|
expect(Arch.Flash._fadeOut).not.toHaveBeenCalled(); |
|
}); |
|
|
|
it("does nothing if no message is passed", function() { |
|
loadFixtures("flash.html"); |
|
Arch.Flash.showError(""); |
|
expect($("#flash-msg .user-msg-detail")).not.toHaveClass("error"); |
|
expect($("#flash-msg .user-msg-detail")).not.toHaveClass("notice"); |
|
}); |
|
|
|
}); |
|
|
|
describe("Showing a notice", function(){ |
|
|
|
var noticeText = "Something nice has happened!"; |
|
|
|
it("updates the element classes", function() { |
|
loadFixtures("flash.html"); |
|
Arch.Flash.showNotice(noticeText); |
|
expect($("#flash-msg .user-msg-detail")).toHaveClass("notice"); |
|
expect($("#flash-msg .user-msg-detail")).not.toHaveClass("error"); |
|
}); |
|
|
|
it("sets the text of the flash element", function() { |
|
loadFixtures("flash.html"); |
|
Arch.Flash.showNotice(noticeText); |
|
expect($("#flash-msg .user-msg-detail span")).toHaveText("Something nice has happened!"); |
|
}); |
|
|
|
it("fades the message automatically", function(){ |
|
spyOn(Arch.Flash, "_fadeOut"); |
|
loadFixtures("flash.html"); |
|
Arch.Flash.showNotice(noticeText); |
|
expect(Arch.Flash._fadeOut).toHaveBeenCalled(); |
|
}); |
|
|
|
it("does nothing if no message is passed", function() { |
|
spyOn(Arch.Flash, "_fadeOut"); |
|
loadFixtures("flash.html"); |
|
Arch.Flash.showNotice(""); |
|
expect($("#flash-msg .user-msg-detail")).not.toHaveClass("error"); |
|
expect($("#flash-msg .user-msg-detail")).not.toHaveClass("notice"); |
|
expect(Arch.Flash._fadeOut).not.toHaveBeenCalled(); |
|
}); |
|
|
|
it("does nothing if there is already an error", function() { |
|
spyOn(Arch.Flash, "_fadeOut"); |
|
loadFixtures("flash.html"); |
|
Arch.Flash.showError("oh noes"); |
|
Arch.Flash.showNotice("oh yeah"); |
|
expect($("#flash-msg .user-msg-detail")).toHaveClass("error"); |
|
expect($("#flash-msg .user-msg-detail")).not.toHaveClass("notice"); |
|
expect(Arch.Flash._fadeOut).not.toHaveBeenCalled(); |
|
expect($("#flash-msg .user-msg-detail span")).toHaveText("oh noes"); |
|
}); |
|
}); |