parent
c547e66eb6
commit
00ce187b07
2 changed files with 17 additions and 19 deletions
|
|
@ -11,12 +11,8 @@ app.collections.Notifications = Backbone.Collection.extend({
|
||||||
timeout: 300000, // 5 minutes
|
timeout: 300000, // 5 minutes
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.pollNotifications();
|
this.fetch();
|
||||||
|
|
||||||
setTimeout(function() {
|
|
||||||
setInterval(this.pollNotifications.bind(this), this.timeout);
|
setInterval(this.pollNotifications.bind(this), this.timeout);
|
||||||
}.bind(this), this.timeout);
|
|
||||||
|
|
||||||
Diaspora.BrowserNotification.requestPermission();
|
Diaspora.BrowserNotification.requestPermission();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
describe("app.collections.Notifications", function() {
|
describe("app.collections.Notifications", function() {
|
||||||
describe("initialize", function() {
|
describe("initialize", function() {
|
||||||
it("calls pollNotifications", function() {
|
it("calls fetch", function() {
|
||||||
spyOn(app.collections.Notifications.prototype, "pollNotifications");
|
spyOn(app.collections.Notifications.prototype, "fetch");
|
||||||
new app.collections.Notifications();
|
new app.collections.Notifications();
|
||||||
expect(app.collections.Notifications.prototype.pollNotifications).toHaveBeenCalled();
|
expect(app.collections.Notifications.prototype.fetch).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls Diaspora.BrowserNotification.requestPermission", function() {
|
it("calls Diaspora.BrowserNotification.requestPermission", function() {
|
||||||
|
|
@ -23,6 +23,16 @@ describe("app.collections.Notifications", function() {
|
||||||
expect(target.unreadCount).toBe(0);
|
expect(target.unreadCount).toBe(0);
|
||||||
expect(target.unreadCountByType).toEqual({});
|
expect(target.unreadCountByType).toEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("repeatedly calls pollNotifications", function() {
|
||||||
|
spyOn(app.collections.Notifications.prototype, "pollNotifications").and.callThrough();
|
||||||
|
var collection = new app.collections.Notifications();
|
||||||
|
expect(app.collections.Notifications.prototype.pollNotifications).not.toHaveBeenCalled();
|
||||||
|
jasmine.clock().tick(collection.timeout);
|
||||||
|
expect(app.collections.Notifications.prototype.pollNotifications).toHaveBeenCalledTimes(1);
|
||||||
|
jasmine.clock().tick(collection.timeout);
|
||||||
|
expect(app.collections.Notifications.prototype.pollNotifications).toHaveBeenCalledTimes(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("pollNotifications", function() {
|
describe("pollNotifications", function() {
|
||||||
|
|
@ -31,9 +41,9 @@ describe("app.collections.Notifications", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("calls fetch", function() {
|
it("calls fetch", function() {
|
||||||
spyOn(app.collections.Notifications.prototype, "fetch");
|
spyOn(this.target, "fetch");
|
||||||
this.target.pollNotifications();
|
this.target.pollNotifications();
|
||||||
expect(app.collections.Notifications.prototype.fetch).toHaveBeenCalled();
|
expect(this.target.fetch).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("doesn't call Diaspora.BrowserNotification.spawnNotification when there are no new notifications", function() {
|
it("doesn't call Diaspora.BrowserNotification.spawnNotification when there are no new notifications", function() {
|
||||||
|
|
@ -52,14 +62,6 @@ describe("app.collections.Notifications", function() {
|
||||||
this.target.trigger("finishedLoading");
|
this.target.trigger("finishedLoading");
|
||||||
expect(Diaspora.BrowserNotification.spawnNotification).toHaveBeenCalled();
|
expect(Diaspora.BrowserNotification.spawnNotification).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("refreshes after timeout", function() {
|
|
||||||
spyOn(app.collections.Notifications.prototype, "pollNotifications").and.callThrough();
|
|
||||||
this.target.pollNotifications();
|
|
||||||
expect(app.collections.Notifications.prototype.pollNotifications).toHaveBeenCalledTimes(1);
|
|
||||||
jasmine.clock().tick(2 * this.target.timeout);
|
|
||||||
expect(app.collections.Notifications.prototype.pollNotifications).toHaveBeenCalledTimes(2);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("fetch", function() {
|
describe("fetch", function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue