Matteo Scandolo | d2044a4 | 2017-08-07 16:08:28 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | |
Matteo Scandolo | 8fabb0a | 2016-06-01 11:47:22 -0700 | [diff] [blame] | 19 | 'use strict'; |
| 20 | |
| 21 | describe('The Synchronizer Notification Panel', () => { |
| 22 | |
| 23 | var scope, element, isolatedScope, XosUserPrefs; |
| 24 | const xosNotification = { |
| 25 | notify: jasmine.createSpy('notify') |
| 26 | }; |
| 27 | |
| 28 | const failureEvent = { |
| 29 | name: 'test', |
| 30 | status: false |
| 31 | }; |
| 32 | |
| 33 | const successEvent = { |
| 34 | name: 'test', |
| 35 | status: true |
| 36 | }; |
| 37 | |
| 38 | beforeEach(module('xos.synchronizerNotifier', ($provide) => { |
| 39 | $provide.value('Diag', { |
| 40 | start: () => null |
| 41 | }); |
| 42 | |
| 43 | $provide.value('xosNotification', xosNotification); |
| 44 | })); |
| 45 | beforeEach(module('templates')); |
| 46 | |
| 47 | beforeEach(inject(function($compile, $rootScope, _XosUserPrefs_){ |
| 48 | |
| 49 | XosUserPrefs = _XosUserPrefs_; |
| 50 | scope = $rootScope.$new(); |
| 51 | element = angular.element('<sync-status></sync-status>'); |
| 52 | $compile(element)(scope); |
| 53 | scope.$digest(); |
| 54 | isolatedScope = element.isolateScope().vm; |
| 55 | })); |
| 56 | |
| 57 | describe('when an event is received', () => { |
| 58 | |
| 59 | beforeEach(() => { |
| 60 | xosNotification.notify.calls.reset() |
| 61 | }); |
| 62 | |
| 63 | describe('and notification have not been sent', () => { |
| 64 | |
| 65 | beforeEach(() => { |
| 66 | XosUserPrefs.setSynchronizerNotificationStatus('test', false); |
| 67 | scope.$emit('diag', failureEvent); |
| 68 | }); |
| 69 | |
| 70 | it('should trigger notification', () => { |
| 71 | expect(xosNotification.notify).toHaveBeenCalled(); |
| 72 | }); |
| 73 | |
| 74 | it('should update status in the scope', () => { |
| 75 | expect(isolatedScope.synchronizers.test).toEqual(failureEvent); |
| 76 | scope.$emit('diag', successEvent); |
| 77 | expect(isolatedScope.synchronizers.test).toEqual(successEvent); |
| 78 | }); |
| 79 | }); |
| 80 | |
| 81 | describe('and notification have been sent', () => { |
| 82 | |
| 83 | beforeEach(() => { |
| 84 | XosUserPrefs.setSynchronizerNotificationStatus('test', true); |
| 85 | scope.$emit('diag', failureEvent); |
| 86 | }); |
| 87 | |
| 88 | it('should not trigger multiple notification for the same synchronizer', () => { |
| 89 | expect(xosNotification.notify).not.toHaveBeenCalled(); |
| 90 | }); |
| 91 | }); |
| 92 | }); |
| 93 | |
| 94 | }); |