Add JavaScript for mobile alerts

This commit is contained in:
Steffen van Bergerem 2016-09-30 16:34:30 +02:00 committed by Dennis Schubert
parent a80806ca58
commit 0c995eb629
No known key found for this signature in database
GPG key ID: 5A0304BEA7966D7E
2 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1,19 @@
(function() {
Diaspora.Mobile.Alert = {
_flash: function(message, type) {
var html = "<div class='alert alert-" + type + " alert-dismissible fade in' role='alert'>" +
"<button type='button' class='close' data-dismiss='alert' aria-label='" +
Diaspora.I18n.t("header.close") +
"'>" +
"<span aria-hidden='true'><i class='entypo-cross'></i></span>" +
"</button>" +
message +
"</div>";
$("#flash-messages").append(html);
},
success: function(message) { this._flash(message, "success"); },
error: function(message) { this._flash(message, "danger"); }
};
})();

View file

@ -0,0 +1,29 @@
describe("Diaspora.Mobile.Alert", function() {
describe("_flash", function() {
beforeEach(function() {
spec.content().html("<div id='flash-messages'></div>");
});
it("appends an alert to the #flash-messages div", function() {
Diaspora.Mobile.Alert._flash("Oh snap! You got an error!", "error-class");
expect($("#flash-messages .alert")).toHaveClass("alert-error-class");
expect($("#flash-messages .alert").text()).toBe("Oh snap! You got an error!");
});
});
describe("success", function() {
it("calls _flash", function() {
spyOn(Diaspora.Mobile.Alert, "_flash");
Diaspora.Mobile.Alert.success("Awesome!");
expect(Diaspora.Mobile.Alert._flash).toHaveBeenCalledWith("Awesome!", "success");
});
});
describe("error", function() {
it("calls _flash", function() {
spyOn(Diaspora.Mobile.Alert, "_flash");
Diaspora.Mobile.Alert.error("Oh noez!");
expect(Diaspora.Mobile.Alert._flash).toHaveBeenCalledWith("Oh noez!", "danger");
});
});
});