blob: 28ab96e4f2c82071bf8ec42795575772a3284933 [file] [log] [blame]
Matteo Scandolo7629cc42017-03-13 14:12:15 -07001import * as angular from 'angular';
2import 'angular-mocks';
3import 'angular-ui-router';
4import {IXosServiceGraphExtender, XosServiceGraphExtender} from './graph.extender';
5
6let service: IXosServiceGraphExtender, registerSpy;
7
8const reducer = (graph) => {
9 return graph;
10};
11
12describe('The XosServiceGraphExtender service', () => {
13
14 beforeEach(() => {
15 angular.module('xosServiceGraphExtender', [])
16 .service('XosServiceGraphExtender', XosServiceGraphExtender);
17
18 angular.mock.module('xosServiceGraphExtender');
19 });
20
21 beforeEach(angular.mock.inject((
22 XosServiceGraphExtender: IXosServiceGraphExtender,
23 ) => {
24 service = XosServiceGraphExtender;
25
26 registerSpy = spyOn(service, 'register').and.callThrough();
27 }));
28
29 it('should register a reducer for the coarse service graph', () => {
30 service.register('coarse', 'testCoarse', reducer);
31 expect(registerSpy).toHaveBeenCalled();
32 const coarseReducers = service.getCoarse();
33 expect(coarseReducers).toHaveLength(1);
34 expect(coarseReducers[0].name).toEqual('testCoarse');
35 expect(typeof coarseReducers[0].reducer).toEqual('function');
36 });
37
38 it('should register a reducer for the fine-grained service graph', () => {
39 service.register('finegrained', 'testFinegrained', reducer);
40 expect(registerSpy).toHaveBeenCalled();
41 const coarseReducers = service.getFinegrained();
42 expect(coarseReducers).toHaveLength(1);
43 expect(coarseReducers[0].name).toEqual('testFinegrained');
44 expect(typeof coarseReducers[0].reducer).toEqual('function');
45 });
46
47});