diaspora/spec/javascripts/app/views/notification_dropdown_view_spec.js
Steffen van Bergerem abe7ef3d18 Update existing notifications in dropdown on fetch
When fetching notifications this merges existing notifications and changes
their appearance in the dropdown if the html or the unread status changed.

This doesn't update all notifications in the dropdown but only those that are
returned by the server.

Related to #7247.
2017-01-13 02:47:37 +01:00

113 lines
4.4 KiB
JavaScript

describe("app.views.NotificationDropdown", function() {
beforeEach(function() {
spec.loadFixture("notifications");
gon.appConfig = {settings: {podname: "MyPod"}};
this.header = new app.views.Header();
$("header").prepend(this.header.el);
loginAs({guid: "foo"});
this.header.render();
this.collection = new app.collections.Notifications();
this.view = new app.views.NotificationDropdown({el: "#notification-dropdown", collection: this.collection});
});
describe("bindCollectionEvents", function() {
beforeEach(function() {
this.view.collection.off("pushFront");
this.view.collection.off("pushBack");
this.view.collection.off("finishedLoading");
this.view.collection.off("change:note_html");
spyOn(this.view, "onPushFront");
spyOn(this.view, "onPushBack");
spyOn(this.view, "finishLoading");
spyOn(this.view, "onNotificationChange");
});
it("binds collection events", function() {
this.view.bindCollectionEvents();
this.collection.trigger("pushFront");
this.collection.trigger("pushBack");
this.collection.trigger("finishedLoading");
this.collection.trigger("change:note_html");
expect(this.view.onPushFront).toHaveBeenCalled();
expect(this.view.onPushBack).toHaveBeenCalled();
expect(this.view.finishLoading).toHaveBeenCalled();
expect(this.view.onNotificationChange).toHaveBeenCalled();
});
});
describe("showDropdown", function() {
it("Calls updateScrollbar", function() {
spyOn(this.view, "updateScrollbar");
this.view.showDropdown();
expect(this.view.updateScrollbar).toHaveBeenCalled();
});
it("Changes CSS", function() {
expect($("#notification-dropdown")).not.toHaveClass("dropdown-open");
this.view.showDropdown();
expect($("#notification-dropdown")).toHaveClass("dropdown-open");
});
it("Calls collection#fetch", function() {
spyOn(this.collection, "fetch");
this.view.showDropdown();
expect(this.collection.fetch).toHaveBeenCalled();
});
});
describe("dropdownScroll", function() {
it("Calls collection#fetchMore if it is at the bottom", function() {
this.view.isBottom = function() { return true; };
spyOn(this.collection, "fetchMore");
this.view.dropdownScroll();
expect(this.collection.fetchMore).toHaveBeenCalled();
});
it("Doesn't call collection#fetchMore if it is not at the bottom", function() {
this.view.isBottom = function() { return false; };
spyOn(this.collection, "fetchMore");
this.view.dropdownScroll();
expect(this.collection.fetchMore).not.toHaveBeenCalled();
});
});
describe("updateScrollbar", function() {
it("Initializes perfectScrollbar", function() {
this.view.perfectScrollbarInitialized = false;
spyOn($.fn, "perfectScrollbar");
this.view.updateScrollbar();
expect($.fn.perfectScrollbar).toHaveBeenCalledWith();
expect($.fn.perfectScrollbar.calls.mostRecent().object).toEqual(this.view.dropdownNotifications);
expect(this.view.perfectScrollbarInitialized).toBeTruthy();
});
it("Updates perfectScrollbar", function() {
this.view.perfectScrollbarInitialized = true;
this.view.dropdownNotifications.perfectScrollbar();
spyOn($.fn, "perfectScrollbar");
this.view.updateScrollbar();
expect($.fn.perfectScrollbar).toHaveBeenCalledWith("update");
expect($.fn.perfectScrollbar.calls.mostRecent().object).toEqual(this.view.dropdownNotifications);
expect(this.view.perfectScrollbarInitialized).toBeTruthy();
});
});
describe("destroyScrollbar", function() {
it("destroys perfectScrollbar", function() {
this.view.perfectScrollbarInitialized = true;
this.view.dropdownNotifications.perfectScrollbar();
spyOn($.fn, "perfectScrollbar");
this.view.destroyScrollbar();
expect($.fn.perfectScrollbar).toHaveBeenCalledWith("destroy");
expect($.fn.perfectScrollbar.calls.mostRecent().object).toEqual(this.view.dropdownNotifications);
expect(this.view.perfectScrollbarInitialized).toBeFalsy();
});
it("doesn't destroy perfectScrollbar if it isn't initialized", function() {
this.view.perfectScrollbarInitialized = false;
spyOn($.fn, "perfectScrollbar");
this.view.destroyScrollbar();
expect($.fn.perfectScrollbar).not.toHaveBeenCalled();
});
});
});