Matteo Scandolo | 4e87023 | 2017-01-30 13:43:05 -0800 | [diff] [blame] | 1 | import * as angular from 'angular'; |
| 2 | import 'angular-mocks'; |
| 3 | import 'angular-resource'; |
| 4 | import {Subject} from 'rxjs'; |
| 5 | import {XosOnboarder, IXosOnboarder} from './onboard.service'; |
| 6 | import {IWSEventService} from '../../datasources/websocket/global'; |
| 7 | |
| 8 | let service, $ocLazyLoad; |
| 9 | |
| 10 | const subject = new Subject(); |
| 11 | |
| 12 | const MockWs: IWSEventService = { |
| 13 | list() { |
| 14 | return subject.asObservable(); |
| 15 | } |
| 16 | }; |
| 17 | |
| 18 | const MockPromise = { |
| 19 | then: (cb) => { |
| 20 | cb('done'); |
| 21 | return MockPromise; |
| 22 | }, |
| 23 | catch: (cb) => { |
| 24 | cb('err'); |
| 25 | return MockPromise; |
| 26 | } |
| 27 | }; |
| 28 | |
| 29 | const MockLoad = { |
| 30 | load: () => { |
| 31 | return MockPromise; |
| 32 | } |
| 33 | }; |
| 34 | |
| 35 | describe('The XosOnboarder service', () => { |
| 36 | |
| 37 | beforeEach(() => { |
| 38 | |
| 39 | angular |
| 40 | .module('XosOnboarder', []) |
| 41 | .value('WebSocket', MockWs) |
| 42 | .value('$ocLazyLoad', MockLoad) |
| 43 | .service('XosOnboarder', XosOnboarder); |
| 44 | |
| 45 | angular.mock.module('XosOnboarder'); |
| 46 | }); |
| 47 | |
| 48 | beforeEach(angular.mock.inject(( |
| 49 | XosOnboarder: IXosOnboarder, |
| 50 | _$ocLazyLoad_: any |
| 51 | ) => { |
| 52 | $ocLazyLoad = _$ocLazyLoad_; |
| 53 | spyOn($ocLazyLoad, 'load').and.callThrough(); |
| 54 | service = XosOnboarder; |
| 55 | })); |
| 56 | |
| 57 | describe('when receive an event', () => { |
| 58 | it('should use $ocLazyLoad to add modules to the app', () => { |
| 59 | subject.next({ |
| 60 | msg: { |
| 61 | app: 'sample', |
| 62 | files: ['vendor.js', 'app.js'] |
| 63 | } |
| 64 | }); |
| 65 | expect($ocLazyLoad.load).toHaveBeenCalledWith('vendor.js'); |
| 66 | expect($ocLazyLoad.load).toHaveBeenCalledWith('app.js'); |
| 67 | }); |
| 68 | }); |
| 69 | }); |