7e28b2a658828c63248b1999813d128327cd194b
[vid.git] /
1 import {getTestBed, TestBed} from '@angular/core/testing';
2 import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
3 import {DefaultDataGeneratorService} from "../../../shared/services/defaultDataServiceGenerator/default.data.generator.service";
4 import {MockNgRedux, NgReduxTestingModule} from "@angular-redux/store/testing";
5 import {DrawingBoardHeaderService} from "./drawing-board-header.service";
6 import {ActivatedRoute} from '@angular/router';
7 import {ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions";
8 import {AppState} from "../../../shared/store/reducers";
9 import {NgRedux} from "@angular-redux/store";
10 import {addServiceAction} from "../../../shared/storeUtil/utils/service/service.actions";
11 import {ErrorMsgService} from "../../../shared/components/error-msg/error-msg.service";
12 import {DrawingBoardModes} from "../drawing-board.modes";
13 import each from "jest-each";
14
15 class MockAppStore<T>{
16   getState()  {
17     return {
18       service : {
19         serviceInstance : {
20           "serviceInstanceId" : {
21             action: 'None'
22           }
23         }
24       }
25     }
26   }
27 }
28
29 describe('Generate path to old View/Edit ', () => {
30   let injector;
31   let service: DrawingBoardHeaderService;
32   let httpMock: HttpTestingController;
33   let store :  NgRedux<AppState>;
34
35   beforeAll(done => (async () => {
36     TestBed.configureTestingModule({
37       imports: [HttpClientTestingModule, NgReduxTestingModule],
38       providers: [
39         DrawingBoardHeaderService,
40         DefaultDataGeneratorService,
41         MockNgRedux,
42         ErrorMsgService,
43         {
44           provide: ActivatedRoute,
45           useValue: {
46             snapshot : {
47               queryParams:{
48                 'subscriberId' : 'subscriberId',
49                 'subscriberName' : 'subscriberName',
50                 'serviceType' : 'serviceType',
51                 'serviceInstanceId' : 'serviceInstanceId'
52               }
53             }
54           },
55         }]
56     });
57     await TestBed.compileComponents();
58
59     injector = getTestBed();
60     service = injector.get(DrawingBoardHeaderService);
61     httpMock = injector.get(HttpTestingController);
62     store = injector.get(NgRedux);
63
64   })().then(done).catch(done.fail));
65
66   each([
67     ['', DrawingBoardModes.RECREATE, true],
68     ['', DrawingBoardModes.CREATE, true],
69     ['Create', DrawingBoardModes.EDIT, true],
70     ['Create', DrawingBoardModes.RETRY_EDIT, true],
71     ['Create', DrawingBoardModes.VIEW, false],
72     ['Create', DrawingBoardModes.OLD_VIEW_EDIT, false],
73
74
75   ]).
76   test('should show edit button in correct Drawing Board Mode state', (action: string, mode: DrawingBoardModes, expected: boolean) => {
77     jest.spyOn(store, 'getState').mockReturnValue(<any>{
78       service: {
79         serviceInstance : {
80           'serviceInstanceId' : {
81             action: action
82           }
83         }
84       }
85     });
86
87   let result = service.showEditService(mode,'serviceInstanceId' );
88     expect (result).toBe(expected);
89   });
90
91   test('should generate url to old view/edit ', () => {
92     const query: string = 'subscriberId=subscriberId&subscriberName=subscriberName&serviceType=serviceType&serviceInstanceId=serviceInstanceId';
93     const path =  '../../serviceModels.htm#/instantiate?' + query;
94     let result = service.generateOldViewEditPath();
95    expect(result).toEqual(path);
96   });
97
98   test('should call update action for Delete',()=>{
99
100     jest.spyOn(store, 'dispatch');
101     service.deleteService("serviceInstanceId", true);
102     expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", ServiceInstanceActions.Delete));
103   });
104
105   test('should call update action for undo delete',()=>{
106     jest.spyOn(store, 'dispatch');
107     service.deleteService("serviceInstanceId", false);
108     expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", ServiceInstanceActions.None));
109   });
110
111   test('deployShouldBeDisabled with validationCounter greater then 0',()=>{
112     jest.spyOn(store, 'getState').mockReturnValue(<any>{
113       service: {
114         serviceInstance : {
115           'serviceInstanceId' : {
116             validationCounter : 1
117           }
118         }
119       }
120     });
121     let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
122     expect(result).toBeTruthy();
123   });
124
125   test('deployShouldBeDisabled with validationCounter is 0 and not dirty',()=>{
126     jest.spyOn(store, 'getState').mockReturnValue(<any>{
127       service: {
128         serviceInstance : {
129           'serviceInstanceId' : {
130             validationCounter : 0,
131             isDirty : false
132           }
133         }
134       }
135     });
136     let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
137     expect(result).toBeFalsy();
138   });
139
140   test('deployShouldBeDisabled with validationCounter is 0 and dirty',()=>{
141     jest.spyOn(store, 'getState').mockReturnValue(<any>{
142       service: {
143         serviceInstance : {
144           'serviceInstanceId' : {
145             validationCounter : 0,
146             action : 'None',
147             isDirty : true
148           }
149         }
150       }
151     });
152     let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
153     expect(result).not.toBeTruthy();
154   });
155
156   test('deployShouldBeDisabled with validationCounter is 0 and not and action is None and dirty',()=>{
157     jest.spyOn(store, 'getState').mockReturnValue(<any>{
158       service: {
159         serviceInstance : {
160           'serviceInstanceId' : {
161             validationCounter : 0,
162             action : ServiceInstanceActions.None,
163             isDirty : true
164           }
165         }
166       }
167     });
168     let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
169     expect(result).not.toBeTruthy();
170   });
171
172
173   test('getModeButton',()=>{
174     let result : string = service.getModeButton("EDIT");
175     expect(result).toEqual('UPDATE');
176
177     result  = service.getModeButton("");
178     expect(result).toEqual('DEPLOY');
179
180     result  = service.getModeButton("RETRY_EDIT");
181     expect(result).toEqual('REDEPLOY');
182   });
183   test('getButtonText',()=>{
184     expect(service.getButtonText(DrawingBoardModes.VIEW)).toEqual('EDIT');
185     expect(service.getButtonText(DrawingBoardModes.RETRY)).toEqual('REDEPLOY');
186
187   });
188   const showEditServiceDataProvider = [
189     ['Create action CREATE mode', DrawingBoardModes.CREATE ,ServiceInstanceActions.Create, true],
190     ['Create action RETRY_EDIT mode',DrawingBoardModes.RETRY_EDIT,  ServiceInstanceActions.Create,  true],
191     ['Create action EDIT mode',DrawingBoardModes.EDIT, ServiceInstanceActions.Create,  true],
192     ['Create action RETRY mode',DrawingBoardModes.RETRY, ServiceInstanceActions.Create,  false],
193     ['None action EDIT mode',DrawingBoardModes.EDIT,  ServiceInstanceActions.None, false],
194     ['None action RETRY_EDIT mode', DrawingBoardModes.RETRY_EDIT, ServiceInstanceActions.None, false]];
195   each(showEditServiceDataProvider).test('showEditService service with %s', (description, mode, action, enabled) => {
196     jest.spyOn(store, 'getState').mockReturnValue(<any>{
197       service: {
198         serviceInstance : {
199           'serviceInstanceId' : {
200             action : action
201           }
202         }
203       }
204     });
205     expect(service.showEditService(mode, 'serviceInstanceId')).toBe(enabled);
206
207   });
208
209   const showResumeServiceDataProvider = [
210     ['all conditions of resume- should show resume',true, 'MACRO', 'VPE', 'AssiGNed', true],
211     ['flag is disabled- should not show resume ',false, 'MACRO', 'VPE', 'AssiGNed', false],
212     ['transport service (PNF)- should not show resume', true, 'Macro', 'transport', 'Assigned', false],
213     ['instantiationType is a-la-carte- should not show resume', true, 'ALaCarte', 'VPE', 'Assigned', false],
214     ['orchestration Status is not assigned- should not show resume', true, 'Macro', 'VPE', 'Created', false],
215     ['orchestration Status is Inventoried - should show resume', true, 'Macro', 'VPE', 'iNventOriEd', true]
216   ];
217
218   each(showResumeServiceDataProvider).test('showResumeService when %s', (description, flagResumeMacroService,instantiationType, subscriptionServiceType, orchStatus, shouldShowResumeService) => {
219     jest.spyOn(store, 'getState').mockReturnValue(<any>{
220       global: {
221         flags:{
222           'FLAG_1908_RESUME_MACRO_SERVICE': flagResumeMacroService
223         }
224       },
225       service: {
226         serviceInstance : {
227           'serviceModelId' : {
228             'vidNotions': {
229               'instantiationType': instantiationType
230             },
231             'subscriptionServiceType':subscriptionServiceType,
232             'orchStatus': orchStatus
233           }
234         }
235       }
236     });
237     expect(service.showResumeService('serviceModelId')).toBe(shouldShowResumeService);
238
239   });
240
241
242   const toggleResumeServiceDataProvider = [
243     [ServiceInstanceActions.None, true],
244     [ServiceInstanceActions.Resume, false]
245   ];
246
247   each(toggleResumeServiceDataProvider).test('toggleResumeService - should call %s for resume/ undo Resume',(serviceAction, isResume)=>{
248     jest.spyOn(store, 'dispatch');
249     service.toggleResumeService("serviceInstanceId", isResume);
250     expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", serviceAction));
251   });
252
253 });