blob: f9373c955e4862c86c46ba2ff98cc07dbead7201 [file] [log] [blame]
Matteo Scandolo4e870232017-01-30 13:43:05 -08001import * as angular from 'angular';
2import 'angular-mocks';
3import 'angular-resource';
4import {Subject} from 'rxjs';
5import {XosOnboarder, IXosOnboarder} from './onboard.service';
6import {IWSEventService} from '../../datasources/websocket/global';
7
8let service, $ocLazyLoad;
9
10const subject = new Subject();
11
12const MockWs: IWSEventService = {
13 list() {
14 return subject.asObservable();
15 }
16};
17
18const MockPromise = {
19 then: (cb) => {
20 cb('done');
21 return MockPromise;
22 },
23 catch: (cb) => {
24 cb('err');
25 return MockPromise;
26 }
27};
28
29const MockLoad = {
30 load: () => {
31 return MockPromise;
32 }
33};
34
35describe('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});