blob: c9f434e996326af20c013ec562d86646521770f6 [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import {getTestBed, TestBed} from '@angular/core/testing';
2import {
3 INPROGRESS,
4 InstantiationStatusComponentService,
5 PAUSE,
6 PENDING,
7 ServiceStatus,
8 STOPED,
9 SUCCESS_CIRCLE,
10 X_O
11} from './instantiationStatus.component.service';
12import {ServiceInfoModel} from '../shared/server/serviceInfo/serviceInfo.model';
13import { Observable } from 'rxjs/Rx';
14
15describe('Instantiation Status Service', () => {
16 let injector;
17 let service: InstantiationStatusComponentService;
18
19 beforeEach(() => {
20 TestBed.configureTestingModule({
21 imports: [],
22 providers: [InstantiationStatusComponentService]
23 });
24
25 injector = getTestBed();
26 service = injector.get(InstantiationStatusComponentService);
27 });
28
29 it('generateServiceInfoDataMapping should return mapping of arrays', (done: DoneFn) => {
30 let data : Array<ServiceInfoModel> = generateServiceInfoData();
31 let result = service.generateServiceInfoDataMapping(data);
32
33 expect(result['1']).toBeDefined();
34 expect(result['2']).toBeDefined();
35 expect(result['3']).toBeDefined();
36
37 expect(result['1'].length).toEqual(2);
38 expect(result['2'].length).toEqual(2);
39 expect(result['3'].length).toEqual(1);
40 done();
41 });
42
43 it('generateServiceInfoDataMapping if array is empty should return empty object', (done: DoneFn) => {
44 let result = service.generateServiceInfoDataMapping([]);
45
46 expect(result['1']).not.toBeDefined();
47 expect(result['2']).not.toBeDefined();
48 expect(result['3']).not.toBeDefined();
49 done();
50 });
51
52 it('convertObjectToArray', (done: DoneFn) => {
53
54 spyOn(service, 'convertObjectToArray').and.returnValue(
55 Observable.of([])
56 );
57
58 let data : Array<ServiceInfoModel> = generateServiceInfoData();
59 service.convertObjectToArray(data).subscribe((result) => {
60 expect(result).toBeDefined();
61 done();
62 });
63 });
64
65 it('getStatusTooltip should return status popover', (done: DoneFn) => {
66 let result : ServiceStatus = service.getStatus('pending');
67 expect(result.tooltip).toEqual('Pending: The service will automatically be sent for instantiation as soon as possible.');
68
69 result = service.getStatus('IN_PROGRESS');
70 expect(result.tooltip).toEqual('In-progress: the service is in process of instantiation.');
71
72 result = service.getStatus('PAUSED');
73 expect(result.tooltip).toEqual('Paused: Service has paused and waiting for your action.\n Select actions from the menu to the right.');
74
75 result = service.getStatus('FAILED');
76 expect(result.tooltip).toEqual('Failed: Service instantiation has failed, load the service to see the error returned.');
77
78 result = service.getStatus('COMPLETED');
79 expect(result.tooltip).toEqual('Completed successfully: Service is successfully instantiated.');
80
81 result = service.getStatus('STOPPED');
82 expect(result.tooltip).toEqual('Stopped: Due to previous failure, will not be instantiated.');
83 done();
84 });
85
86 it('getStatusTooltip should return correct icon per job status', (done: DoneFn) => {
87 let result : ServiceStatus = service.getStatus('pending');
88 expect(result.iconClassName).toEqual(PENDING);
89
90 result = service.getStatus('IN_PROGRESS');
91 expect(result.iconClassName).toEqual(INPROGRESS);
92
93 result = service.getStatus('PAUSED');
94 expect(result.iconClassName).toEqual(PAUSE);
95
96 result = service.getStatus('FAILED');
97 expect(result.iconClassName).toEqual(X_O);
98
99 result = service.getStatus('COMPLETED');
100 expect(result.iconClassName).toEqual(SUCCESS_CIRCLE);
101
102 result = service.getStatus('STOPPED');
103 expect(result.iconClassName).toEqual(STOPED);
104 done();
105 });
106
107
108 function generateServiceInfoData(){
109 return JSON.parse(JSON.stringify([
110 {
111 "created": 1519956533000,
112 "modified": 1521727738000,
113 "createdId": null,
114 "modifiedId": null,
115 "rowNum": null,
116 "auditUserId": null,
117 "auditTrail": null,
118 "jobId": "6748648484",
119 "userId": "2222",
120 "jobStatus": "FAILED",
121 "pause": false,
122 "owningEntityId": "1234",
123 "owningEntityName": null,
124 "project": null,
125 "aicZoneId": null,
126 "aicZoneName": null,
127 "tenantId": null,
128 "tenantName": null,
129 "regionId": null,
130 "regionName": null,
131 "serviceType": null,
132 "subscriberName": null,
133 "serviceInstanceId": "1",
134 "serviceInstanceName": null,
135 "serviceModelId": null,
136 "serviceModelName": null,
137 "serviceModelVersion": null,
138 "createdBulkDate": 1519956533000,
139 "statusModifiedDate": 1520042933000,
140 "templateId": "1",
141 "hidden": false
142 },
143 {
144 "created": 1519956533000,
145 "modified": 1521727738000,
146 "createdId": null,
147 "modifiedId": null,
148 "rowNum": null,
149 "auditUserId": null,
150 "auditTrail": null,
151 "jobId": "6748648484",
152 "userId": "2222",
153 "jobStatus": "FAILED",
154 "pause": false,
155 "owningEntityId": "1234",
156 "owningEntityName": null,
157 "project": null,
158 "aicZoneId": null,
159 "aicZoneName": null,
160 "tenantId": null,
161 "tenantName": null,
162 "regionId": null,
163 "regionName": null,
164 "serviceType": null,
165 "subscriberName": null,
166 "serviceInstanceId": "1",
167 "serviceInstanceName": null,
168 "serviceModelId": null,
169 "serviceModelName": null,
170 "serviceModelVersion": null,
171 "createdBulkDate": 1519956533000,
172 "statusModifiedDate": 1520042933000,
173 "templateId": "1",
174 "hidden": false
175 },
176 {
177 "created": 1519956533000,
178 "modified": 1521727738000,
179 "createdId": null,
180 "modifiedId": null,
181 "rowNum": null,
182 "auditUserId": null,
183 "auditTrail": null,
184 "jobId": "6748648484",
185 "userId": "2222",
186 "jobStatus": "FAILED",
187 "pause": false,
188 "owningEntityId": "1234",
189 "owningEntityName": null,
190 "project": null,
191 "aicZoneId": null,
192 "aicZoneName": null,
193 "tenantId": null,
194 "tenantName": null,
195 "regionId": null,
196 "regionName": null,
197 "serviceType": null,
198 "subscriberName": null,
199 "serviceInstanceId": "2",
200 "serviceInstanceName": null,
201 "serviceModelId": null,
202 "serviceModelName": null,
203 "serviceModelVersion": null,
204 "createdBulkDate": 1519956533000,
205 "statusModifiedDate": 1520042933000,
206 "templateId": "2",
207 "hidden": false
208 },
209 {
210 "created": 1519956533000,
211 "modified": 1521727738000,
212 "createdId": null,
213 "modifiedId": null,
214 "rowNum": null,
215 "auditUserId": null,
216 "auditTrail": null,
217 "jobId": "6748648484",
218 "userId": "2222",
219 "jobStatus": "FAILED",
220 "pause": false,
221 "owningEntityId": "1234",
222 "owningEntityName": null,
223 "project": null,
224 "aicZoneId": null,
225 "aicZoneName": null,
226 "tenantId": null,
227 "tenantName": null,
228 "regionId": null,
229 "regionName": null,
230 "serviceType": null,
231 "subscriberName": null,
232 "serviceInstanceId": "2",
233 "serviceInstanceName": null,
234 "serviceModelId": null,
235 "serviceModelName": null,
236 "serviceModelVersion": null,
237 "createdBulkDate": 1519956533000,
238 "statusModifiedDate": 1520042933000,
239 "templateId": "2",
240 "hidden": false
241 },
242 {
243 "created": 1519956533000,
244 "modified": 1521727738000,
245 "createdId": null,
246 "modifiedId": null,
247 "rowNum": null,
248 "auditUserId": null,
249 "auditTrail": null,
250 "jobId": "6748648484",
251 "userId": "2222",
252 "jobStatus": "FAILED",
253 "pause": false,
254 "owningEntityId": "1234",
255 "owningEntityName": null,
256 "project": null,
257 "aicZoneId": null,
258 "aicZoneName": null,
259 "tenantId": null,
260 "tenantName": null,
261 "regionId": null,
262 "regionName": null,
263 "serviceType": null,
264 "subscriberName": null,
265 "serviceInstanceId": "3",
266 "serviceInstanceName": null,
267 "serviceModelId": null,
268 "serviceModelName": null,
269 "serviceModelVersion": null,
270 "createdBulkDate": 1519956533000,
271 "statusModifiedDate": 1520042933000,
272 "templateId": "3",
273 "hidden": false
274 }
275 ]));
276 }
277
278});