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";
15 class MockAppStore<T>{
20 "serviceInstanceId" : {
29 describe('Generate path to old View/Edit ', () => {
31 let service: DrawingBoardHeaderService;
32 let httpMock: HttpTestingController;
33 let store : NgRedux<AppState>;
35 beforeAll(done => (async () => {
36 TestBed.configureTestingModule({
37 imports: [HttpClientTestingModule, NgReduxTestingModule],
39 DrawingBoardHeaderService,
40 DefaultDataGeneratorService,
44 provide: ActivatedRoute,
48 'subscriberId' : 'subscriberId',
49 'subscriberName' : 'subscriberName',
50 'serviceType' : 'serviceType',
51 'serviceInstanceId' : 'serviceInstanceId'
57 await TestBed.compileComponents();
59 injector = getTestBed();
60 service = injector.get(DrawingBoardHeaderService);
61 httpMock = injector.get(HttpTestingController);
62 store = injector.get(NgRedux);
64 })().then(done).catch(done.fail));
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],
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>{
80 'serviceInstanceId' : {
87 let result = service.showEditService(mode,'serviceInstanceId' );
88 expect (result).toBe(expected);
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);
98 test('should call update action for Delete',()=>{
100 jest.spyOn(store, 'dispatch');
101 service.deleteService("serviceInstanceId", true);
102 expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", ServiceInstanceActions.Delete));
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));
111 test('deployShouldBeDisabled with validationCounter greater then 0',()=>{
112 jest.spyOn(store, 'getState').mockReturnValue(<any>{
115 'serviceInstanceId' : {
116 validationCounter : 1
121 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
122 expect(result).toBeTruthy();
125 test('deployShouldBeDisabled with validationCounter is 0 and not dirty',()=>{
126 jest.spyOn(store, 'getState').mockReturnValue(<any>{
129 'serviceInstanceId' : {
130 validationCounter : 0,
136 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
137 expect(result).toBeFalsy();
140 test('deployShouldBeDisabled with validationCounter is 0 and dirty',()=>{
141 jest.spyOn(store, 'getState').mockReturnValue(<any>{
144 'serviceInstanceId' : {
145 validationCounter : 0,
152 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
153 expect(result).not.toBeTruthy();
156 test('deployShouldBeDisabled with validationCounter is 0 and not and action is None and dirty',()=>{
157 jest.spyOn(store, 'getState').mockReturnValue(<any>{
160 'serviceInstanceId' : {
161 validationCounter : 0,
162 action : ServiceInstanceActions.None,
168 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
169 expect(result).not.toBeTruthy();
173 test('getModeButton',()=>{
174 let result : string = service.getModeButton("EDIT");
175 expect(result).toEqual('UPDATE');
177 result = service.getModeButton("");
178 expect(result).toEqual('DEPLOY');
180 result = service.getModeButton("RETRY_EDIT");
181 expect(result).toEqual('REDEPLOY');
183 test('getButtonText',()=>{
184 expect(service.getButtonText(DrawingBoardModes.VIEW)).toEqual('EDIT');
185 expect(service.getButtonText(DrawingBoardModes.RETRY)).toEqual('REDEPLOY');
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>{
199 'serviceInstanceId' : {
205 expect(service.showEditService(mode, 'serviceInstanceId')).toBe(enabled);
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]
218 each(showResumeServiceDataProvider).test('showResumeService when %s', (description, flagResumeMacroService,instantiationType, subscriptionServiceType, orchStatus, shouldShowResumeService) => {
219 jest.spyOn(store, 'getState').mockReturnValue(<any>{
222 'FLAG_1908_RESUME_MACRO_SERVICE': flagResumeMacroService
229 'instantiationType': instantiationType
231 'subscriptionServiceType':subscriptionServiceType,
232 'orchStatus': orchStatus
237 expect(service.showResumeService('serviceModelId')).toBe(shouldShowResumeService);
242 const toggleResumeServiceDataProvider = [
243 [ServiceInstanceActions.None, true],
244 [ServiceInstanceActions.Resume, false]
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));