blob: 76fc28a9e528bae4021fc423978c7ecf9b891a4a [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {getTestBed, TestBed} from '@angular/core/testing';
2import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
3import {DefaultDataGeneratorService} from "../../../shared/services/defaultDataServiceGenerator/default.data.generator.service";
4import {MockNgRedux, NgReduxTestingModule} from "@angular-redux/store/testing";
5import {DrawingBoardHeaderService} from "./drawing-board-header.service";
6import {ActivatedRoute} from '@angular/router';
7import {ServiceInstanceActions} from "../../../shared/models/serviceInstanceActions";
8import {AppState} from "../../../shared/store/reducers";
9import {NgRedux} from "@angular-redux/store";
10import {addServiceAction} from "../../../shared/storeUtil/utils/service/service.actions";
11import {ErrorMsgService} from "../../../shared/components/error-msg/error-msg.service";
12import {DrawingBoardModes} from "../drawing-board.modes";
13import each from "jest-each";
14
15class MockAppStore<T>{
16 getState() {
17 return {
18 service : {
19 serviceInstance : {
20 "serviceInstanceId" : {
21 action: 'None'
22 }
23 }
24 }
25 }
26 }
27}
28
29describe('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
67 test('should generate url to old view/edit ', () => {
68 const query: string = 'subscriberId=subscriberId&subscriberName=subscriberName&serviceType=serviceType&serviceInstanceId=serviceInstanceId';
69 const path = '../../serviceModels.htm#/instantiate?' + query;
70 let result = service.generateOldViewEditPath();
71 expect(result).toEqual(path);
72 });
73
74 test('should call update action for Delete',()=>{
75
76 jest.spyOn(store, 'dispatch');
77 service.deleteService("serviceInstanceId", true);
78 expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", ServiceInstanceActions.Delete));
79 });
80
81 test('should call update action for undo delete',()=>{
82 jest.spyOn(store, 'dispatch');
83 service.deleteService("serviceInstanceId", false);
84 expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", ServiceInstanceActions.None));
85 });
86
87 test('deployShouldBeDisabled with validationCounter greater then 0',()=>{
Ittay Sternf7926712019-07-07 19:23:03 +030088 jest.spyOn(store, 'getState').mockReturnValue(<any>{
Ittay Stern6f900cc2018-08-29 17:01:32 +030089 service: {
90 serviceInstance : {
91 'serviceInstanceId' : {
92 validationCounter : 1
93 }
94 }
95 }
96 });
Ittay Sternf7926712019-07-07 19:23:03 +030097 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
Ittay Stern6f900cc2018-08-29 17:01:32 +030098 expect(result).toBeTruthy();
99 });
100
101 test('deployShouldBeDisabled with validationCounter is 0 and not dirty',()=>{
Ittay Sternf7926712019-07-07 19:23:03 +0300102 jest.spyOn(store, 'getState').mockReturnValue(<any>{
Ittay Stern6f900cc2018-08-29 17:01:32 +0300103 service: {
104 serviceInstance : {
105 'serviceInstanceId' : {
106 validationCounter : 0,
107 isDirty : false
108 }
109 }
110 }
111 });
Ittay Sternf7926712019-07-07 19:23:03 +0300112 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
Ittay Stern6f900cc2018-08-29 17:01:32 +0300113 expect(result).toBeFalsy();
114 });
115
116 test('deployShouldBeDisabled with validationCounter is 0 and dirty',()=>{
Ittay Sternf7926712019-07-07 19:23:03 +0300117 jest.spyOn(store, 'getState').mockReturnValue(<any>{
Ittay Stern6f900cc2018-08-29 17:01:32 +0300118 service: {
119 serviceInstance : {
120 'serviceInstanceId' : {
121 validationCounter : 0,
122 action : 'None',
123 isDirty : true
124 }
125 }
126 }
127 });
Ittay Sternf7926712019-07-07 19:23:03 +0300128 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
Ittay Stern6f900cc2018-08-29 17:01:32 +0300129 expect(result).not.toBeTruthy();
130 });
131
132 test('deployShouldBeDisabled with validationCounter is 0 and not and action is None and dirty',()=>{
Ittay Sternf7926712019-07-07 19:23:03 +0300133 jest.spyOn(store, 'getState').mockReturnValue(<any>{
Ittay Stern6f900cc2018-08-29 17:01:32 +0300134 service: {
135 serviceInstance : {
136 'serviceInstanceId' : {
137 validationCounter : 0,
138 action : ServiceInstanceActions.None,
139 isDirty : true
140 }
141 }
142 }
143 });
Ittay Sternf7926712019-07-07 19:23:03 +0300144 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
Ittay Stern6f900cc2018-08-29 17:01:32 +0300145 expect(result).not.toBeTruthy();
146 });
147
148
149 test('getModeButton',()=>{
150 let result : string = service.getModeButton("EDIT");
151 expect(result).toEqual('UPDATE');
152
153 result = service.getModeButton("");
154 expect(result).toEqual('DEPLOY');
155
156 result = service.getModeButton("RETRY_EDIT");
157 expect(result).toEqual('REDEPLOY');
158 });
159 test('getButtonText',()=>{
Ittay Sternf7926712019-07-07 19:23:03 +0300160 expect(service.getButtonText(DrawingBoardModes.VIEW)).toEqual('EDIT');
161 expect(service.getButtonText(DrawingBoardModes.RETRY)).toEqual('REDEPLOY');
Ittay Stern6f900cc2018-08-29 17:01:32 +0300162
163 });
164 const showEditServiceDataProvider = [
165 ['Create action CREATE mode', DrawingBoardModes.CREATE ,ServiceInstanceActions.Create, true],
166 ['Create action RETRY_EDIT mode',DrawingBoardModes.RETRY_EDIT, ServiceInstanceActions.Create, true],
167 ['Create action EDIT mode',DrawingBoardModes.EDIT, ServiceInstanceActions.Create, true],
168 ['Create action RETRY mode',DrawingBoardModes.RETRY, ServiceInstanceActions.Create, false],
169 ['None action EDIT mode',DrawingBoardModes.EDIT, ServiceInstanceActions.None, false],
170 ['None action RETRY_EDIT mode', DrawingBoardModes.RETRY_EDIT, ServiceInstanceActions.None, false]];
171 each(showEditServiceDataProvider).test('showEditService service with %s', (description, mode, action, enabled) => {
Ittay Sternf7926712019-07-07 19:23:03 +0300172 jest.spyOn(store, 'getState').mockReturnValue(<any>{
Ittay Stern6f900cc2018-08-29 17:01:32 +0300173 service: {
174 serviceInstance : {
175 'serviceInstanceId' : {
176 action : action
177 }
178 }
179 }
180 });
181 expect(service.showEditService(mode, 'serviceInstanceId')).toBe(enabled);
182
183 });
Ittay Sternf7926712019-07-07 19:23:03 +0300184
185 const showResumeServiceDataProvider = [
186 ['all conditions of resume- should show resume',true, 'MACRO', 'VPE', 'AssiGNed', true],
187 ['flag is disabled- should not show resume ',false, 'MACRO', 'VPE', 'AssiGNed', false],
188 ['transport service (PNF)- should not show resume', true, 'Macro', 'transport', 'Assigned', false],
189 ['instantiationType is a-la-carte- should not show resume', true, 'ALaCarte', 'VPE', 'Assigned', false],
190 ['orchestration Status is not assigned- should not show resume', true, 'Macro', 'VPE', 'Created', false],
191 ['orchestration Status is Inventoried - should show resume', true, 'Macro', 'VPE', 'iNventOriEd', true]
192 ];
193
194 each(showResumeServiceDataProvider).test('showResumeService when %s', (description, flagResumeMacroService,instantiationType, subscriptionServiceType, orchStatus, shouldShowResumeService) => {
195 jest.spyOn(store, 'getState').mockReturnValue(<any>{
196 global: {
197 flags:{
198 'FLAG_1908_RESUME_MACRO_SERVICE': flagResumeMacroService
199 }
200 },
201 service: {
202 serviceInstance : {
203 'serviceModelId' : {
204 'vidNotions': {
205 'instantiationType': instantiationType
206 },
207 'subscriptionServiceType':subscriptionServiceType,
208 'orchStatus': orchStatus
209 }
210 }
211 }
212 });
213 expect(service.showResumeService('serviceModelId')).toBe(shouldShowResumeService);
214
215 });
216
217
218 const toggleResumeServiceDataProvider = [
219 [ServiceInstanceActions.None, true],
220 [ServiceInstanceActions.Resume, false]
221 ];
222
223 each(toggleResumeServiceDataProvider).test('toggleResumeService - should call %s for resume/ undo Resume',(serviceAction, isResume)=>{
224 jest.spyOn(store, 'dispatch');
225 service.toggleResumeService("serviceInstanceId", isResume);
226 expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", serviceAction));
227 });
228
Ittay Stern6f900cc2018-08-29 17:01:32 +0300229});