blob: bcf6753b960b9c5ec6cdbc92b71ff2f67b21c5b5 [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',()=>{
88 jest.spyOn(store, 'getState').mockReturnValue({
89 service: {
90 serviceInstance : {
91 'serviceInstanceId' : {
92 validationCounter : 1
93 }
94 }
95 }
96 });
97 let result = service.deployShouldBeDisabled("serviceInstanceId");
98 expect(result).toBeTruthy();
99 });
100
101 test('deployShouldBeDisabled with validationCounter is 0 and not dirty',()=>{
102 jest.spyOn(store, 'getState').mockReturnValue({
103 service: {
104 serviceInstance : {
105 'serviceInstanceId' : {
106 validationCounter : 0,
107 isDirty : false
108 }
109 }
110 }
111 });
112 let result = service.deployShouldBeDisabled("serviceInstanceId");
113 expect(result).toBeFalsy();
114 });
115
116 test('deployShouldBeDisabled with validationCounter is 0 and dirty',()=>{
117 jest.spyOn(store, 'getState').mockReturnValue({
118 service: {
119 serviceInstance : {
120 'serviceInstanceId' : {
121 validationCounter : 0,
122 action : 'None',
123 isDirty : true
124 }
125 }
126 }
127 });
128 let result = service.deployShouldBeDisabled("serviceInstanceId");
129 expect(result).not.toBeTruthy();
130 });
131
132 test('deployShouldBeDisabled with validationCounter is 0 and not and action is None and dirty',()=>{
133 jest.spyOn(store, 'getState').mockReturnValue({
134 service: {
135 serviceInstance : {
136 'serviceInstanceId' : {
137 validationCounter : 0,
138 action : ServiceInstanceActions.None,
139 isDirty : true
140 }
141 }
142 }
143 });
144 let result = service.deployShouldBeDisabled("serviceInstanceId");
145 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',()=>{
160 expect(service.getButtonText("VIEW")).toEqual('EDIT');
161 expect(service.getButtonText("RETRY")).toEqual('REDEPLOY');
162
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) => {
172 jest.spyOn(store, 'getState').mockReturnValue({
173 service: {
174 serviceInstance : {
175 'serviceInstanceId' : {
176 action : action
177 }
178 }
179 }
180 });
181 expect(service.showEditService(mode, 'serviceInstanceId')).toBe(enabled);
182
183 });
184});