Matteo Scandolo | 9b6d11f | 2016-06-01 11:47:22 -0700 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | |
| 3 | describe('The Synchronizer Notification Panel', () => { |
| 4 | |
| 5 | var scope, element, isolatedScope, XosUserPrefs; |
| 6 | const xosNotification = { |
| 7 | notify: jasmine.createSpy('notify') |
| 8 | }; |
| 9 | |
| 10 | const failureEvent = { |
| 11 | name: 'test', |
| 12 | status: false |
| 13 | }; |
| 14 | |
| 15 | const successEvent = { |
| 16 | name: 'test', |
| 17 | status: true |
| 18 | }; |
| 19 | |
| 20 | beforeEach(module('xos.synchronizerNotifier', ($provide) => { |
| 21 | $provide.value('Diag', { |
| 22 | start: () => null |
| 23 | }); |
| 24 | |
| 25 | $provide.value('xosNotification', xosNotification); |
| 26 | })); |
| 27 | beforeEach(module('templates')); |
| 28 | |
| 29 | beforeEach(inject(function($compile, $rootScope, _XosUserPrefs_){ |
| 30 | |
| 31 | XosUserPrefs = _XosUserPrefs_; |
| 32 | scope = $rootScope.$new(); |
| 33 | element = angular.element('<sync-status></sync-status>'); |
| 34 | $compile(element)(scope); |
| 35 | scope.$digest(); |
| 36 | isolatedScope = element.isolateScope().vm; |
| 37 | })); |
| 38 | |
| 39 | describe('when an event is received', () => { |
| 40 | |
| 41 | beforeEach(() => { |
| 42 | xosNotification.notify.calls.reset() |
| 43 | }); |
| 44 | |
| 45 | describe('and notification have not been sent', () => { |
| 46 | |
| 47 | beforeEach(() => { |
| 48 | XosUserPrefs.setSynchronizerNotificationStatus('test', false); |
| 49 | scope.$emit('diag', failureEvent); |
| 50 | }); |
| 51 | |
| 52 | it('should trigger notification', () => { |
| 53 | expect(xosNotification.notify).toHaveBeenCalled(); |
| 54 | }); |
| 55 | |
| 56 | it('should update status in the scope', () => { |
| 57 | expect(isolatedScope.synchronizers.test).toEqual(failureEvent); |
| 58 | scope.$emit('diag', successEvent); |
| 59 | expect(isolatedScope.synchronizers.test).toEqual(successEvent); |
| 60 | }); |
| 61 | }); |
| 62 | |
| 63 | describe('and notification have been sent', () => { |
| 64 | |
| 65 | beforeEach(() => { |
| 66 | XosUserPrefs.setSynchronizerNotificationStatus('test', true); |
| 67 | scope.$emit('diag', failureEvent); |
| 68 | }); |
| 69 | |
| 70 | it('should not trigger multiple notification for the same synchronizer', () => { |
| 71 | expect(xosNotification.notify).not.toHaveBeenCalled(); |
| 72 | }); |
| 73 | }); |
| 74 | }); |
| 75 | |
| 76 | }); |