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({
91 'serviceInstanceId' : {
97 let result = service.deployShouldBeDisabled("serviceInstanceId");
98 expect(result).toBeTruthy();
101 test('deployShouldBeDisabled with validationCounter is 0 and not dirty',()=>{
102 jest.spyOn(store, 'getState').mockReturnValue({
105 'serviceInstanceId' : {
106 validationCounter : 0,
112 let result = service.deployShouldBeDisabled("serviceInstanceId");
113 expect(result).toBeFalsy();
116 test('deployShouldBeDisabled with validationCounter is 0 and dirty',()=>{
117 jest.spyOn(store, 'getState').mockReturnValue({
120 'serviceInstanceId' : {
121 validationCounter : 0,
128 let result = service.deployShouldBeDisabled("serviceInstanceId");
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({
136 'serviceInstanceId' : {
137 validationCounter : 0,
138 action : ServiceInstanceActions.None,
144 let result = service.deployShouldBeDisabled("serviceInstanceId");
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("VIEW")).toEqual('EDIT');
161 expect(service.getButtonText("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({
175 'serviceInstanceId' : {
181 expect(service.showEditService(mode, 'serviceInstanceId')).toBe(enabled);