notification-manager-spec.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. const NotificationManager = require('../src/notification-manager');
  2. describe('NotificationManager', () => {
  3. let manager;
  4. beforeEach(() => {
  5. manager = new NotificationManager();
  6. });
  7. describe('the atom global', () =>
  8. it('has a notifications instance', () => {
  9. expect(atom.notifications instanceof NotificationManager).toBe(true);
  10. }));
  11. describe('adding events', () => {
  12. let addSpy;
  13. beforeEach(() => {
  14. addSpy = jasmine.createSpy();
  15. manager.onDidAddNotification(addSpy);
  16. });
  17. it('emits an event when a notification has been added', () => {
  18. manager.add('error', 'Some error!', { icon: 'someIcon' });
  19. expect(addSpy).toHaveBeenCalled();
  20. const notification = addSpy.mostRecentCall.args[0];
  21. expect(notification.getType()).toBe('error');
  22. expect(notification.getMessage()).toBe('Some error!');
  23. expect(notification.getIcon()).toBe('someIcon');
  24. });
  25. it('emits a fatal error when ::addFatalError has been called', () => {
  26. manager.addFatalError('Some error!', { icon: 'someIcon' });
  27. expect(addSpy).toHaveBeenCalled();
  28. const notification = addSpy.mostRecentCall.args[0];
  29. expect(notification.getType()).toBe('fatal');
  30. });
  31. it('emits an error when ::addError has been called', () => {
  32. manager.addError('Some error!', { icon: 'someIcon' });
  33. expect(addSpy).toHaveBeenCalled();
  34. const notification = addSpy.mostRecentCall.args[0];
  35. expect(notification.getType()).toBe('error');
  36. });
  37. it('emits a warning notification when ::addWarning has been called', () => {
  38. manager.addWarning('Something!', { icon: 'someIcon' });
  39. expect(addSpy).toHaveBeenCalled();
  40. const notification = addSpy.mostRecentCall.args[0];
  41. expect(notification.getType()).toBe('warning');
  42. });
  43. it('emits an info notification when ::addInfo has been called', () => {
  44. manager.addInfo('Something!', { icon: 'someIcon' });
  45. expect(addSpy).toHaveBeenCalled();
  46. const notification = addSpy.mostRecentCall.args[0];
  47. expect(notification.getType()).toBe('info');
  48. });
  49. it('emits a success notification when ::addSuccess has been called', () => {
  50. manager.addSuccess('Something!', { icon: 'someIcon' });
  51. expect(addSpy).toHaveBeenCalled();
  52. const notification = addSpy.mostRecentCall.args[0];
  53. expect(notification.getType()).toBe('success');
  54. });
  55. });
  56. describe('clearing notifications', () => {
  57. it('clears the notifications when ::clear has been called', () => {
  58. manager.addSuccess('success');
  59. expect(manager.getNotifications().length).toBe(1);
  60. manager.clear();
  61. expect(manager.getNotifications().length).toBe(0);
  62. });
  63. describe('adding events', () => {
  64. let clearSpy;
  65. beforeEach(() => {
  66. clearSpy = jasmine.createSpy();
  67. manager.onDidClearNotifications(clearSpy);
  68. });
  69. it('emits an event when the notifications have been cleared', () => {
  70. manager.clear();
  71. expect(clearSpy).toHaveBeenCalled();
  72. });
  73. });
  74. });
  75. });