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 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);
74 test('should call update action for Delete',()=>{
76 jest.spyOn(store, 'dispatch');
77 service.deleteService("serviceInstanceId", true);
78 expect(store.dispatch).toHaveBeenCalledWith(addServiceAction("serviceInstanceId", ServiceInstanceActions.Delete));
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));
87 test('deployShouldBeDisabled with validationCounter greater then 0',()=>{
88 jest.spyOn(store, 'getState').mockReturnValue(<any>{
91 'serviceInstanceId' : {
97 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
98 expect(result).toBeTruthy();
101 test('deployShouldBeDisabled with validationCounter is 0 and not dirty',()=>{
102 jest.spyOn(store, 'getState').mockReturnValue(<any>{
105 'serviceInstanceId' : {
106 validationCounter : 0,
112 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
113 expect(result).toBeFalsy();
116 test('deployShouldBeDisabled with validationCounter is 0 and dirty',()=>{
117 jest.spyOn(store, 'getState').mockReturnValue(<any>{
120 'serviceInstanceId' : {
121 validationCounter : 0,
128 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
129 expect(result).not.toBeTruthy();
132 test('deployShouldBeDisabled with validationCounter is 0 and not and action is None and dirty',()=>{
133 jest.spyOn(store, 'getState').mockReturnValue(<any>{
136 'serviceInstanceId' : {
137 validationCounter : 0,
138 action : ServiceInstanceActions.None,
144 let result = service.deployShouldBeDisabled("serviceInstanceId", DrawingBoardModes.RETRY_EDIT);
145 expect(result).not.toBeTruthy();
149 test('getModeButton',()=>{
150 let result : string = service.getModeButton("EDIT");
151 expect(result).toEqual('UPDATE');
153 result = service.getModeButton("");
154 expect(result).toEqual('DEPLOY');
156 result = service.getModeButton("RETRY_EDIT");
157 expect(result).toEqual('REDEPLOY');
159 test('getButtonText',()=>{
160 expect(service.getButtonText(DrawingBoardModes.VIEW)).toEqual('EDIT');
161 expect(service.getButtonText(DrawingBoardModes.RETRY)).toEqual('REDEPLOY');
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) => {
172 jest.spyOn(store, 'getState').mockReturnValue(<any>{
175 'serviceInstanceId' : {
181 expect(service.showEditService(mode, 'serviceInstanceId')).toBe(enabled);
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]
194 each(showResumeServiceDataProvider).test('showResumeService when %s', (description, flagResumeMacroService,instantiationType, subscriptionServiceType, orchStatus, shouldShowResumeService) => {
195 jest.spyOn(store, 'getState').mockReturnValue(<any>{
198 'FLAG_1908_RESUME_MACRO_SERVICE': flagResumeMacroService
205 'instantiationType': instantiationType
207 'subscriptionServiceType':subscriptionServiceType,
208 'orchStatus': orchStatus
213 expect(service.showResumeService('serviceModelId')).toBe(shouldShowResumeService);
218 const toggleResumeServiceDataProvider = [
219 [ServiceInstanceActions.None, true],
220 [ServiceInstanceActions.Resume, false]
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));