blob: 02237cc63b56728bacf7ff0e7ac97a3c66aef1e4 [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
Matteo Scandolo47860fe2017-02-02 12:05:55 -08008let service, $ocLazyLoad, $timeout;
Matteo Scandolo4e870232017-01-30 13:43:05 -08009
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
Matteo Scandolo47860fe2017-02-02 12:05:55 -080035const MockModelStore = {
36 query: () => {
Matteo Scandolo11b4a632017-02-09 10:28:41 -080037 return subject.asObservable();
Matteo Scandolo47860fe2017-02-02 12:05:55 -080038 }
39};
40
Matteo Scandolo4e870232017-01-30 13:43:05 -080041describe('The XosOnboarder service', () => {
42
43 beforeEach(() => {
44
45 angular
46 .module('XosOnboarder', [])
47 .value('WebSocket', MockWs)
48 .value('$ocLazyLoad', MockLoad)
Matteo Scandolo1aee1982017-02-17 08:33:23 -080049 .value('XosModelStore', MockModelStore)
Matteo Scandolo4e870232017-01-30 13:43:05 -080050 .service('XosOnboarder', XosOnboarder);
51
52 angular.mock.module('XosOnboarder');
53 });
54
55 beforeEach(angular.mock.inject((
56 XosOnboarder: IXosOnboarder,
Matteo Scandolo47860fe2017-02-02 12:05:55 -080057 _$ocLazyLoad_: any,
58 _$timeout_: ng.ITimeoutService
Matteo Scandolo4e870232017-01-30 13:43:05 -080059 ) => {
60 $ocLazyLoad = _$ocLazyLoad_;
61 spyOn($ocLazyLoad, 'load').and.callThrough();
62 service = XosOnboarder;
Matteo Scandolo47860fe2017-02-02 12:05:55 -080063 $timeout = _$timeout_;
Matteo Scandolo9b460042017-04-14 16:24:45 -070064
65 // start the service
66 service.onboard();
Matteo Scandolo4e870232017-01-30 13:43:05 -080067 }));
68
69 describe('when receive an event', () => {
70 it('should use $ocLazyLoad to add modules to the app', () => {
Matteo Scandolo11b4a632017-02-09 10:28:41 -080071 subject.next([
72 {
73 files: 'vendor.js,app.js',
74 name: 'sample app'
Matteo Scandolo4e870232017-01-30 13:43:05 -080075 }
Matteo Scandolo11b4a632017-02-09 10:28:41 -080076 ]);
Matteo Scandolo4e870232017-01-30 13:43:05 -080077 expect($ocLazyLoad.load).toHaveBeenCalledWith('vendor.js');
78 expect($ocLazyLoad.load).toHaveBeenCalledWith('app.js');
79 });
80 });
81});