diff --git a/spec/notification-manager-spec.js b/spec/notification-manager-spec.js index 3f6a20b67..3a8544d4e 100644 --- a/spec/notification-manager-spec.js +++ b/spec/notification-manager-spec.js @@ -66,4 +66,27 @@ describe('NotificationManager', () => { expect(notification.getType()).toBe('success') }) }) + + describe('clearing notifications', () => { + it('clears the notifications when ::clear has been called', () => { + manager.addSuccess('success') + expect(manager.getNotifications().length).toBe(1) + manager.clear() + expect(manager.getNotifications().length).toBe(0) + }) + + describe('adding events', () => { + let clearSpy + + beforeEach(() => { + clearSpy = jasmine.createSpy() + manager.onDidClearNotifications(clearSpy) + }) + + it('emits an event when the notifications have been cleared', () => { + manager.clear() + expect(clearSpy).toHaveBeenCalled() + }) + }) + }) }) diff --git a/src/notification-manager.js b/src/notification-manager.js index df5e5fb42..a0ae139d3 100644 --- a/src/notification-manager.js +++ b/src/notification-manager.js @@ -27,6 +27,15 @@ class NotificationManager { return this.emitter.on('did-add-notification', callback) } + // Public: Invoke the given callback after the notifications have been cleared. + // + // * `callback` {Function} to be called after the notifications are cleared. + // + // Returns a {Disposable} on which `.dispose()` can be called to unsubscribe. + onDidClearNotifications (callback) { + return this.emitter.on('did-clear-notifications', callback) + } + /* Section: Adding Notifications */ @@ -200,7 +209,9 @@ class NotificationManager { Section: Managing Notifications */ + // Public: Clear all the notifications. clear () { this.notifications = [] + this.emitter.emit('did-clear-notifications') } }