Matteo Scandolo | 7629cc4 | 2017-03-13 14:12:15 -0700 | [diff] [blame] | 1 | import * as angular from 'angular'; |
| 2 | import 'angular-mocks'; |
| 3 | import 'angular-ui-router'; |
| 4 | import {IXosServiceGraphExtender, XosServiceGraphExtender} from './graph.extender'; |
| 5 | |
| 6 | let service: IXosServiceGraphExtender, registerSpy; |
| 7 | |
| 8 | const reducer = (graph) => { |
| 9 | return graph; |
| 10 | }; |
| 11 | |
| 12 | describe('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 | }); |