1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
|
import { async, ComponentFixture, TestBed } from "@angular/core/testing";
import {ConfigureFn, configureTests} from "../../../../jest/test-config.helper";
import {NO_ERRORS_SCHEMA} from "@angular/core";
import { CacheService} from "../../../../app/services-ng2";
import {CatalogComponent} from "./catalog.component";
import { SdcUiServices } from "onap-ui-angular";
import { SdcConfigToken } from "../../config/sdc-config.config";
import { SdcMenuToken} from "../../config/sdc-menu.config";
import { ResourceNamePipe } from "../../pipes/resource-name.pipe";
import { CatalogService } from "../../services/catalog.service";
import {TranslatePipe} from "../../shared/translator/translate.pipe";
import {TranslateService} from "../../shared/translator/translate.service";
import {Observable} from "rxjs";
import {LoaderService} from "onap-ui-angular/dist/loader/loader.service";
import {categoriesElements} from "../../../../jest/mocks/categories.mock";
import {sdcMenu} from "../../../../jest/mocks/sdc-menu.mock";
import {IEntityFilterObject} from "../../pipes/entity-filter.pipe";
describe('catalog component', () => {
let fixture: ComponentFixture<CatalogComponent>;
//Data variables
let catalogSelectorItemsMock;
let checkListModelMock;
let filterParamsMock;
let checkboxesFilterMock;
let checkboxesFilterKeysMock;
//Service variables
let stateServiceMock;
let cacheServiceMock: Partial<CacheService>;
let loaderServiceMock: Partial<LoaderService>;
let catalogServiceMock: Partial<CatalogService>;
beforeEach(
async(() => {
console.info = jest.fn();
catalogSelectorItemsMock = [
{
value: 0,
title: 'Active Items',
header: 'Active'
},
{
value: 1,
title: 'Archive',
header: 'Archived'
}
];
checkListModelMock = {
checkboxes: [
{label: "VF", disabled: false, isChecked: false, testId: "checkbox-vf", value: "Resource.VF"},
{label: "VFC", disabled: false, isChecked: false, testId: "checkbox-vfc", value: "Resource.VFC",
subLevelChecklist: {checkboxes:[{label: "VFD", disabled: false, isChecked: false, testId: "checkbox-vfd", value: "Resource.VFD"}],
selectedValues: ["Resource.VFD"]}
},
{label: "CR", disabled: false, isChecked: false, testId: "checkbox-cr", value: "Resource.CR",
subLevelChecklist: { checkboxes:[{label: "VF", disabled: false, isChecked: false, testId: "checkbox-vf", value: "Resource.VF"}],
selectedValues: []}
}],
selectedValues: ["Resource.VF"]
}
filterParamsMock = {
active: true,
categories: ["resourceNewCategory.allotted resource.allotted resource", "resourceNewCategory.allotted resource.contrail route", "resourceNewCategory.application l4+.application server"],
components: ["Resource.VF", "Resource.VFC"],
order: ["lastUpdateDate", true],
statuses: ["inDesign"],
models: ["test"],
term: "Vf"
}
checkboxesFilterMock = {
selectedCategoriesModel: ["serviceNewCategory.network l4+", "resourceNewCategory.allotted resource.allotted resource"],
selectedComponentTypes: ["Resource.VF", "Resource.VFC"],
selectedResourceSubTypes: ["VF", "VFC"],
selectedStatuses: ["NOT_CERTIFIED_CHECKOUT", "NOT_CERTIFIED_CHECKIN"],
selectedModels: ["test"]
};
checkboxesFilterKeysMock = {
categories:{_main: ["serviceNewCategory.network l4+"]},
componentTypes: { Resource: ["Resource.VF", "Resource.VFC"], _main: ["Resource.VFC"]},
statuses: {_main: ["inDesign"]},
models: {_main: ["test"]}
}
stateServiceMock = {
go: jest.fn(),
current: jest.fn()
};
cacheServiceMock = {
get: jest.fn().mockImplementation(()=> categoriesElements),
set: jest.fn(),
contains: jest.fn().mockImplementation(()=> true)
};
loaderServiceMock = {
activate: jest.fn(),
deactivate: jest.fn()
};
catalogServiceMock = {
//TODO create mock function of archive
getCatalog: jest.fn().mockImplementation(()=> Observable.of(categoriesElements)),
getArchiveCatalog: jest.fn().mockImplementation(()=> Observable.of(categoriesElements))
};
const configure: ConfigureFn = testBed => {
testBed.configureTestingModule({
declarations: [CatalogComponent, TranslatePipe],
imports: [],
schemas: [NO_ERRORS_SCHEMA],
providers: [
{provide: SdcConfigToken, useValue: {}},
{provide: SdcMenuToken, useValue: sdcMenu},
{provide: "$state", useValue: stateServiceMock },
{provide: CacheService, useValue: cacheServiceMock },
{provide: CatalogService, useValue: catalogServiceMock },
{provide: ResourceNamePipe, useValue: {}},
{provide: SdcUiServices.LoaderService, useValue: loaderServiceMock },
{provide: TranslateService, useValue: {}}
],
});
};
configureTests(configure).then(testBed => {
fixture = testBed.createComponent(CatalogComponent);
});
})
);
it('should match current snapshot of catalog component', () => {
expect(fixture).toMatchSnapshot();
});
it ('should call on catalog component onInit' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.initGui = jest.fn();
component.componentInstance.initLeftSwitch = jest.fn();
component.componentInstance.initScopeMembers = jest.fn();
component.componentInstance.loadFilterParams = jest.fn();
component.componentInstance.initCatalogData = jest.fn();
component.componentInstance.ngOnInit();
expect(component.componentInstance.initGui).toHaveBeenCalled();
expect(component.componentInstance.initLeftSwitch).toHaveBeenCalled();
expect(component.componentInstance.initScopeMembers).toHaveBeenCalled();
expect(component.componentInstance.loadFilterParams).toHaveBeenCalled();
expect(component.componentInstance.initCatalogData).toHaveBeenCalled();
});
it ('should call on catalog component initLeftSwitch' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.initLeftSwitch();
expect(component.componentInstance.showCatalogSelector).toEqual(false);
expect(component.componentInstance.catalogSelectorItems).toEqual(catalogSelectorItemsMock);
expect(component.componentInstance.selectedCatalogItem).toEqual(catalogSelectorItemsMock[0]);
});
it ('should call on catalog component initCatalogData and selectedCatalogItem is archive ' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.getArchiveCatalogItems = jest.fn();
component.componentInstance.selectedCatalogItem = catalogSelectorItemsMock[1];
component.componentInstance.initCatalogData();
expect(component.componentInstance.getArchiveCatalogItems).toHaveBeenCalled();
});
it ('should call on catalog component initCatalogData and selectedCatalogItem is active ' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.getActiveCatalogItems = jest.fn();
component.componentInstance.selectedCatalogItem = catalogSelectorItemsMock[0];
component.componentInstance.initCatalogData();
expect(component.componentInstance.getActiveCatalogItems).toHaveBeenCalled();
});
it ('should call on catalog component initScopeMembers' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.makeSortedCategories = jest.fn().mockImplementation(()=> categoriesElements);
component.componentInstance.initCategoriesMap = jest.fn();
component.componentInstance.initCheckboxesFilter = jest.fn();
component.componentInstance.initCheckboxesFilterKeys = jest.fn();
component.componentInstance.buildCheckboxLists = jest.fn();
component.componentInstance.initScopeMembers();
expect(component.componentInstance.numberOfItemToDisplay).toEqual(0);
expect(component.componentInstance.categories).toEqual(categoriesElements);
expect(component.componentInstance.confStatus).toEqual(component.componentInstance.sdcMenu.statuses);
expect(component.componentInstance.expandedSection).toEqual( ["type", "category", "status", "model"]);
expect(component.componentInstance.catalogItems).toEqual([]);
expect(component.componentInstance.search).toEqual({FilterTerm: ""});
expect(component.componentInstance.initCategoriesMap).toHaveBeenCalled();
expect(component.componentInstance.initCheckboxesFilter).toHaveBeenCalled();
expect(component.componentInstance.initCheckboxesFilterKeys).toHaveBeenCalled();
expect(component.componentInstance.buildCheckboxLists).toHaveBeenCalled();
expect(component.componentInstance.version).toEqual(categoriesElements);
expect(component.componentInstance.sortBy).toEqual('lastUpdateDate');
expect(component.componentInstance.reverse).toEqual(true);
});
it ('should call on catalog component buildCheckboxLists ' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.buildChecklistModelForTypes = jest.fn();
component.componentInstance.buildChecklistModelForCategories = jest.fn();
component.componentInstance.buildChecklistModelForStatuses = jest.fn();
component.componentInstance.buildChecklistModelForModels = jest.fn();
component.componentInstance.buildCheckboxLists();
expect(component.componentInstance.buildChecklistModelForTypes).toHaveBeenCalled();
expect(component.componentInstance.buildChecklistModelForCategories).toHaveBeenCalled();
expect(component.componentInstance.buildChecklistModelForStatuses).toHaveBeenCalled();
expect(component.componentInstance.buildChecklistModelForModels).toHaveBeenCalled();
});
it ('should call on catalog component getTestIdForCheckboxByText ' , () => {
const component = TestBed.createComponent(CatalogComponent);
let testId = component.componentInstance.getTestIdForCheckboxByText("catalog filter");
expect(testId).toEqual("checkbox-catalogfilter");
});
it ('should call on catalog component selectLeftSwitchItem with active catalog' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.selectedCatalogItem = catalogSelectorItemsMock[1];
component.componentInstance.getActiveCatalogItems = jest.fn();
component.componentInstance.changeFilterParams = jest.fn();
component.componentInstance.selectLeftSwitchItem(catalogSelectorItemsMock[0]);
expect(component.componentInstance.getActiveCatalogItems).toBeCalledWith(true);
expect(component.componentInstance.changeFilterParams).toBeCalledWith({"active": true});
});
it ('should call on catalog component selectLeftSwitchItem with archive catalog' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.selectedCatalogItem = catalogSelectorItemsMock[0];
component.componentInstance.getArchiveCatalogItems = jest.fn();
component.componentInstance.changeFilterParams = jest.fn();
component.componentInstance.selectLeftSwitchItem(catalogSelectorItemsMock[1]);
expect(component.componentInstance.getArchiveCatalogItems).toBeCalledWith(true);
expect(component.componentInstance.changeFilterParams).toBeCalledWith({"active": false});
});
it ('should call on catalog component buildChecklistModelForTypes' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.checkboxesFilterKeys = checkboxesFilterKeysMock;
component.componentInstance.buildChecklistModelForTypes();
expect(component.componentInstance.componentTypes).toEqual({ Resource: ['VF', 'VFC', 'CR', 'PNF', 'CP', 'VL'],
Service: null, 'TOSCA Type': ["Data Type"]})
expect(component.componentInstance.typesChecklistModel.checkboxes.length).toEqual(3);
});
it ('should call on catalog component buildChecklistModelForCategories' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.checkboxesFilterKeys = checkboxesFilterKeysMock;
component.componentInstance.categories = categoriesElements;
component.componentInstance.buildChecklistModelForCategories();
expect(component.componentInstance.categoriesChecklistModel.checkboxes).not.toEqual(null);
});
it ('should call on catalog component buildChecklistModelForStatuses' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.checkboxesFilterKeys = checkboxesFilterKeysMock;
component.componentInstance.categories = categoriesElements;
component.componentInstance.confStatus = sdcMenu.statuses;
component.componentInstance.buildChecklistModelForStatuses();
expect(component.componentInstance.statusChecklistModel.checkboxes.length).toEqual(3);
});
it ('should call on catalog component initCheckboxesFilter' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.initCheckboxesFilter();
expect(component.componentInstance.checkboxesFilter.selectedComponentTypes).toEqual([]);
expect(component.componentInstance.checkboxesFilter.selectedResourceSubTypes).toEqual([]);
expect(component.componentInstance.checkboxesFilter.selectedModels).toEqual([]);
expect(component.componentInstance.checkboxesFilter.selectedStatuses).toEqual([]);
});
it ('should call on catalog component initCheckboxesFilterKeys' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.initCheckboxesFilterKeys();
expect(component.componentInstance.checkboxesFilterKeys.componentTypes).toEqual({ _main: [] });
expect(component.componentInstance.checkboxesFilterKeys.categories).toEqual({ _main: [] });
expect(component.componentInstance.checkboxesFilterKeys.statuses).toEqual({ _main: [] });
expect(component.componentInstance.checkboxesFilterKeys.models).toEqual({ _main: [] });
});
it ('should call on catalog component initCategoriesMap' , () => {
const component = TestBed.createComponent(CatalogComponent);
const categoriesMap = component.componentInstance.initCategoriesMap(categoriesElements);
expect(categoriesMap["resourceNewCategory.allotted resource.allotted resource"].parent.name).toEqual("Allotted Resource");
expect(categoriesMap["resourceNewCategory.generic"].category.uniqueId).toEqual("resourceNewCategory.generic");
expect(categoriesMap["serviceNewCategory.voip call control"].category.name).toEqual("VoIP Call Control");
});
it ('should call on catalog component selectLeftSwitchItem with active and selectedCatalogItem equal to archived' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.getActiveCatalogItems = jest.fn();
component.componentInstance.changeFilterParams = jest.fn();
component.componentInstance.selectedCatalogItem = catalogSelectorItemsMock[1]
component.componentInstance.selectLeftSwitchItem(catalogSelectorItemsMock[0]);
expect(component.componentInstance.getActiveCatalogItems).toHaveBeenCalledWith(true);
expect(component.componentInstance.changeFilterParams).toHaveBeenCalledWith({active: true})
});
it ('should call on catalog component selectLeftSwitchItem with archived and selectedCatalogItem equal to active' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.getArchiveCatalogItems = jest.fn();
component.componentInstance.changeFilterParams = jest.fn();
component.componentInstance.selectedCatalogItem = catalogSelectorItemsMock[0]
component.componentInstance.selectLeftSwitchItem(catalogSelectorItemsMock[1]);
expect(component.componentInstance.getArchiveCatalogItems).toBeCalledWith(true);
expect(component.componentInstance.changeFilterParams).toHaveBeenCalledWith({active: false})
});
it ('should call on catalog component sectionClick with section contains in expandedSection' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.expandedSection = ["type", "category", "status"];
component.componentInstance.sectionClick("type");
expect(component.componentInstance.expandedSection).toEqual(["category", "status"])
});
it ('should call on catalog component sectionClick with section not contains in expandedSection' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.expandedSection = ["type", "category", "status"];
component.componentInstance.sectionClick("newItem");
expect(component.componentInstance.expandedSection).toEqual(["type", "category", "status", "newItem"])
});
it ('should call on catalog component makeFilterParamsFromCheckboxes with selected values' , () => {
const component = TestBed.createComponent(CatalogComponent);
expect(component.componentInstance.makeFilterParamsFromCheckboxes(checkListModelMock)).toEqual(["Resource.VF", "Resource.VFD"])
});
it ('should call on catalog component order with resourceName value' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.changeFilterParams = jest.fn();
component.componentInstance.filterParams = filterParamsMock
component.componentInstance.order("resourceName");
expect(component.componentInstance.changeFilterParams).toHaveBeenCalledWith( {"order": ["resourceName", false]})
});
it ('should call on catalog component goToComponent' , () => {
const component = TestBed.createComponent(CatalogComponent);
const componentMock = { uniqueId: "d3e80fed-12f6-4f29-aeb1-771050e5db72", componentType: "RESOURCE"}
component.componentInstance.goToComponent(componentMock);
expect(stateServiceMock.go).toHaveBeenCalledWith('workspace.general', {id: componentMock.uniqueId, type: componentMock.componentType.toLowerCase()})
});
it ('should call on catalog component getNumOfElements for active catalog' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.selectedCatalogItem = catalogSelectorItemsMock[0]
expect(component.componentInstance.getNumOfElements(3)).toEqual("3 <b>Active</b> Elements found")
});
it ('should call on catalog component raiseNumberOfElementToDisplay with empty catalogFilteredItems' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.catalogFilteredItems = []
component.componentInstance.raiseNumberOfElementToDisplay();
expect(component.componentInstance.numberOfItemToDisplay).toEqual(0);
expect(component.componentInstance.catalogFilteredSlicedItems).toEqual([]);
});
it ('should call on catalog component raiseNumberOfElementToDisplay with full catalogFilteredItems' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.catalogFilteredItems = [1 , 2 , 3, 4, 5, 6]
component.componentInstance.numberOfItemToDisplay = 2;
component.componentInstance.raiseNumberOfElementToDisplay();
expect(component.componentInstance.numberOfItemToDisplay).toEqual(6);
expect(component.componentInstance.catalogFilteredSlicedItems).toEqual([1 , 2 , 3, 4, 5, 6]);
});
it ('should call on catalog component componentShouldReload return false' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.isDefaultFilter = jest.fn().mockImplementation(() => false);
cacheServiceMock.get.mockImplementation(()=> "mockConstructor");
let componentShouldReload = component.componentInstance.componentShouldReload();
expect(component.componentInstance.cacheService.get()).toEqual(component.componentInstance.$state.current.name);
expect(component.componentInstance.cacheService.contains()).toEqual(true);
expect(component.componentInstance.isDefaultFilter).toHaveBeenCalled();
expect(componentShouldReload).toEqual(false);
});
it ('should call on catalog component componentShouldReload return true' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.isDefaultFilter = jest.fn();
let componentShouldReload = component.componentInstance.componentShouldReload();
expect(component.componentInstance.cacheService.get()).not.toEqual(component.componentInstance.$state.current.name);
expect(component.componentInstance.cacheService.contains()).toEqual(true);
expect(componentShouldReload).toEqual(true);
});
it ('should call on catalog component getActiveCatalogItems with true' , () => {
const component = TestBed.createComponent(CatalogComponent);
let resp = component.componentInstance.cacheService.get();
component.componentInstance.updateCatalogItems = jest.fn().mockImplementation((resp) => {});
component.componentInstance.getActiveCatalogItems(true);
expect(component.componentInstance.loaderService.activate).toHaveBeenCalled();
expect(component.componentInstance.updateCatalogItems).toHaveBeenCalledWith(resp);
expect(component.componentInstance.loaderService.deactivate).toHaveBeenCalled();
expect(component.componentInstance.cacheService.set).toHaveBeenCalledWith('breadcrumbsComponentsState', "mockConstructor");
expect(component.componentInstance.cacheService.set).toHaveBeenCalledWith('breadcrumbsComponents', categoriesElements);
expect(component.componentInstance.catalogService.getCatalog).toHaveBeenCalled();
});
it ('should call on catalog component getActiveCatalogItems with false' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.componentShouldReload = jest.fn();
component.componentInstance.updateCatalogItems = jest.fn().mockImplementation((resp) => {});
component.componentInstance.getActiveCatalogItems(false);
expect(component.componentInstance.componentShouldReload).toHaveBeenCalled();
let resp = component.componentInstance.cacheService.get();
expect(component.componentInstance.updateCatalogItems).toHaveBeenCalledWith(resp);
});
it ('should call on catalog component getActiveCatalogItems with true observable return error' , () => {
const component = TestBed.createComponent(CatalogComponent);
catalogServiceMock.getCatalog.mockImplementation(()=> Observable.throwError('error'));
component.componentInstance.getActiveCatalogItems(true);
expect(component.componentInstance.loaderService.activate).toHaveBeenCalled();
expect(console.info).toHaveBeenCalledWith('Failed to load catalog CatalogViewModel::getActiveCatalogItems');
expect(component.componentInstance.loaderService.deactivate).toHaveBeenCalled();
expect(component.componentInstance.catalogService.getCatalog).toHaveBeenCalled();
});
it ('should call on catalog component getArchiveCatalogItems with true' , () => {
const component = TestBed.createComponent(CatalogComponent);
const resp = component.componentInstance.cacheService.get();
component.componentInstance.updateCatalogItems = jest.fn().mockImplementation((resp) => {});
component.componentInstance.getArchiveCatalogItems(true);
expect(component.componentInstance.loaderService.activate).toHaveBeenCalled();
expect(component.componentInstance.catalogService.getArchiveCatalog).toHaveBeenCalled();
expect(component.componentInstance.cacheService.set).toHaveBeenCalledWith('archiveComponents', categoriesElements);
expect(component.componentInstance.loaderService.deactivate).toHaveBeenCalled();
expect(component.componentInstance.updateCatalogItems).toHaveBeenCalledWith(resp)
});
it ('should call on catalog component getArchiveCatalogItems with false' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.updateCatalogItems = jest.fn().mockImplementation((resp) => Observable.of());
component.componentInstance.getArchiveCatalogItems(false);
expect(component.componentInstance.cacheService.contains).toHaveBeenCalled();
expect(component.componentInstance.cacheService.get).toHaveBeenCalled();
let resp = component.componentInstance.cacheService.get();
expect(component.componentInstance.updateCatalogItems).toHaveBeenCalledWith(resp);
});
it ('should call on catalog component getArchiveCatalogItems with true observable return error' , () => {
const component = TestBed.createComponent(CatalogComponent);
catalogServiceMock.getArchiveCatalog.mockImplementation(()=> Observable.throwError('error'));
component.componentInstance.getArchiveCatalogItems(true);
expect(component.componentInstance.loaderService.activate).toHaveBeenCalled();
expect(component.componentInstance.catalogService.getArchiveCatalog).toHaveBeenCalled();
expect(component.componentInstance.loaderService.deactivate).toHaveBeenCalled();
expect(console.info).toHaveBeenCalledWith('Failed to load catalog CatalogViewModel::getArchiveCatalogItems');
});
it ('should call on catalog component updateCatalogItems' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.filterCatalogItems = jest.fn();
component.componentInstance.addFilterTermToComponent = jest.fn();
component.componentInstance.updateCatalogItems([1, 2, 3]);
expect(component.componentInstance.catalogItems).toEqual([1, 2, 3]);
expect(component.componentInstance.addFilterTermToComponent).toHaveBeenCalled();
expect(component.componentInstance.filterCatalogItems).toHaveBeenCalled();
});
it ('should call on catalog component applyFilterParamsToView' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.initCheckboxesFilter = jest.fn();
component.componentInstance.filterCatalogCategories = jest.fn();
component.componentInstance.applyFilterParamsComponents = jest.fn();
component.componentInstance.applyFilterParamsCategories = jest.fn();
component.componentInstance.applyFilterParamsStatuses = jest.fn();
component.componentInstance.applyFilterParamsModels = jest.fn();
component.componentInstance.applyFilterParamsOrder = jest.fn();
component.componentInstance.applyFilterParamsTerm = jest.fn();
component.componentInstance.filterCatalogItems = jest.fn();
component.componentInstance.applyFilterParamsToView(filterParamsMock);
expect(component.componentInstance.initCheckboxesFilter).toHaveBeenCalled();
expect(component.componentInstance.filterCatalogCategories).toHaveBeenCalled();
expect(component.componentInstance.applyFilterParamsComponents).toHaveBeenCalledWith(filterParamsMock);
expect(component.componentInstance.applyFilterParamsCategories).toHaveBeenCalledWith(filterParamsMock);
expect(component.componentInstance.applyFilterParamsStatuses).toHaveBeenCalledWith(filterParamsMock);
expect(component.componentInstance.applyFilterParamsOrder).toHaveBeenCalledWith(filterParamsMock);
expect(component.componentInstance.applyFilterParamsTerm).toHaveBeenCalledWith(filterParamsMock);
expect(component.componentInstance.filterCatalogItems).toHaveBeenCalled();
});
it ('should call on catalog component filterCatalogCategories' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.makeFilteredCategories = jest.fn();
component.componentInstance.buildChecklistModelForCategories = jest.fn();
component.componentInstance.categories = categoriesElements;
component.componentInstance.checkboxesFilter = {selectedComponentTypes: ["firstType", "secondType"]};
component.componentInstance.filterCatalogCategories();
expect(component.componentInstance.makeFilteredCategories).toHaveBeenCalledWith(categoriesElements, ["firstType", "secondType"]);
expect(component.componentInstance.buildChecklistModelForCategories).toHaveBeenCalled();
});
it ('should call on catalog component filterCatalogItems' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.makeFilteredItems = jest.fn().mockImplementation(() => [1,2,3]);
component.componentInstance.raiseNumberOfElementToDisplay = jest.fn();
component.componentInstance.catalogItems = ["firstComponent", "secondComponent"];
component.componentInstance.checkboxesFilter = {};
component.componentInstance.search = {};
component.componentInstance.sortBy = "";
component.componentInstance.reverse = true;
component.componentInstance.numberOfItemToDisplay = 2;
// component.componentInstance.catalogFilteredItems = component.componentInstance.makeFilteredItems();
component.componentInstance.filterCatalogItems();
expect(component.componentInstance.makeFilteredItems).toHaveBeenCalledWith(["firstComponent", "secondComponent"], {}, {}, "",true);
expect(component.componentInstance.raiseNumberOfElementToDisplay);
expect(component.componentInstance.catalogFilteredSlicedItems).toEqual([1,2]);
});
it ('should call on catalog component applyFilterParamsToCheckboxes' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.applyFilterParamsToCheckboxes(checkListModelMock, ["Resource.CR", "Resource.VFD", "Resource.VF"]);
expect(checkListModelMock.selectedValues).toEqual(["Resource.VF","Resource.CR"]);
expect(checkListModelMock.checkboxes[1].subLevelChecklist.selectedValues).toEqual(["Resource.VFD"]);
expect(checkListModelMock.checkboxes[2].subLevelChecklist.selectedValues).toEqual(["Resource.VF"])
});
it ('should call on catalog component applyFilterParamsComponents and filterParams.active equal true' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.applyFilterParamsToCheckboxes = jest.fn();
component.componentInstance.checkboxesFilterKeys = checkboxesFilterKeysMock;
component.componentInstance.checkboxesFilter = checkboxesFilterMock;
component.componentInstance.catalogSelectorItems = catalogSelectorItemsMock;
component.componentInstance.typesChecklistModel = checkListModelMock;
component.componentInstance.applyFilterParamsComponents(filterParamsMock);
expect(component.componentInstance.applyFilterParamsToCheckboxes).toHaveBeenCalledWith(checkListModelMock, filterParamsMock.components);
expect(component.componentInstance.checkboxesFilter.selectedComponentTypes).toEqual(["Resource.VFC"]);
expect(component.componentInstance.checkboxesFilter.selectedResourceSubTypes).toEqual(["VF", "VFC"]);
expect(component.componentInstance.selectedCatalogItem).toEqual(catalogSelectorItemsMock[0]);
});
it ('should call on catalog component applyFilterParamsComponents and filterParams.active equal false' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.applyFilterParamsToCheckboxes = jest.fn();
filterParamsMock.active = false;
component.componentInstance.checkboxesFilterKeys = checkboxesFilterKeysMock;
component.componentInstance.checkboxesFilter = checkboxesFilterMock;
component.componentInstance.catalogSelectorItems = catalogSelectorItemsMock;
component.componentInstance.typesChecklistModel = checkListModelMock;
component.componentInstance.applyFilterParamsComponents(filterParamsMock);
expect(component.componentInstance.applyFilterParamsToCheckboxes).toHaveBeenCalledWith(checkListModelMock, filterParamsMock.components);
expect(component.componentInstance.checkboxesFilter.selectedComponentTypes).toEqual(["Resource.VFC"]);
expect(component.componentInstance.checkboxesFilter.selectedResourceSubTypes).toEqual(["VF", "VFC"]);
expect(component.componentInstance.selectedCatalogItem).toEqual(catalogSelectorItemsMock[1]);
});
it ('should call on catalog component applyFilterParamsCategories' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.applyFilterParamsToCheckboxes = jest.fn();
component.componentInstance.categoriesChecklistModel = checkListModelMock;
component.componentInstance.checkboxesFilterKeys = checkboxesFilterKeysMock;
component.componentInstance.checkboxesFilter = checkboxesFilterMock;
component.componentInstance.applyFilterParamsCategories(filterParamsMock);
expect(component.componentInstance.applyFilterParamsToCheckboxes).toHaveBeenCalledWith(checkListModelMock, filterParamsMock.categories);
expect(component.componentInstance.checkboxesFilter.selectedCategoriesModel).toEqual(["serviceNewCategory.network l4+"]);
});
it ('should call on catalog component applyFilterParamsStatuses' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.applyFilterParamsToCheckboxes = jest.fn();
component.componentInstance.statusChecklistModel = checkListModelMock;
component.componentInstance.checkboxesFilterKeys = checkboxesFilterKeysMock;
component.componentInstance.checkboxesFilter = checkboxesFilterMock;
component.componentInstance.confStatus = sdcMenu.statuses;
component.componentInstance.applyFilterParamsStatuses(filterParamsMock);
expect(component.componentInstance.applyFilterParamsToCheckboxes).toHaveBeenCalledWith(checkListModelMock, filterParamsMock.statuses);
expect(component.componentInstance.checkboxesFilter.selectedStatuses).toEqual(["NOT_CERTIFIED_CHECKOUT", "NOT_CERTIFIED_CHECKIN"]);
});
it ('should call on catalog component applyFilterParamsOrder' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.applyFilterParamsOrder(filterParamsMock);
expect(component.componentInstance.sortBy).toEqual("lastUpdateDate");
expect(component.componentInstance.reverse).toEqual( true);
});
it ('should call on catalog component applyFilterParamsTerm' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.applyFilterParamsTerm(filterParamsMock);
expect(component.componentInstance.search.filterTerm).toEqual("Vf");
});
// it ('should call on catalog component loadFilterParams' , () => {
// const component = TestBed.createComponent(CatalogComponent);
// component.componentInstance.$state = {params: {}};
// component.componentInstance.loadFilterParams();
// });
it ('should call on catalog component changeFilterParams' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.applyFilterParamsToView = jest.fn();
component.componentInstance.filterParams = { active: true, categories: [], components: [], order: ["lastUpdateDate", true], statuses: [], term: ""};
component.componentInstance.$state.go = jest.fn().mockImplementation(() => Promise.resolve({ json: () => [] }));
const newParams = {"filter.active": true, "filter.categories": "resourceNewCategory.allotted resource.allotted resource,resourceNewCategory.allotted resource.contrail route,resourceNewCategory.application l4+.application server", "filter.components": "Resource.VF,Resource.VFC", "filter.models": "test", "filter.order": "-lastUpdateDate", "filter.statuses": "inDesign", "filter.term": "Vf"}
component.componentInstance.changeFilterParams(filterParamsMock);
expect(component.componentInstance.filterParams).toEqual(filterParamsMock);
expect(component.componentInstance.$state.go).toHaveBeenCalledWith('.',newParams, {location: 'replace', notify: false});
expect(component.componentInstance.applyFilterParamsToView).toHaveBeenCalledWith(filterParamsMock);
});
it ('should call on catalog component changeFilterParams and rebuild equal true' , () => {
const component = TestBed.createComponent(CatalogComponent);
component.componentInstance.applyFilterParamsToView = jest.fn();
component.componentInstance.makeFilterParamsFromCheckboxes = jest.fn();
component.componentInstance.buildCheckboxLists = jest.fn();
component.componentInstance.filterParams = { active: true, categories: [], components: [], order: ["lastUpdateDate", true], statuses: [], term: ""};
component.componentInstance.$state.go = jest.fn().mockImplementation(() => Promise.resolve({ json: () => [] }));
const newParams = {"filter.active": true, "filter.categories": "resourceNewCategory.allotted resource.allotted resource,resourceNewCategory.allotted resource.contrail route,resourceNewCategory.application l4+.application server", "filter.components": "Resource.VF,Resource.VFC", "filter.models": "test", "filter.order": "-lastUpdateDate", "filter.statuses": "inDesign", "filter.term": "Vf"}
component.componentInstance.typesChecklistModel = checkListModelMock;
component.componentInstance.categoriesChecklistModel = checkListModelMock;
component.componentInstance.statusChecklistModel = checkListModelMock;
component.componentInstance.changeFilterParams(filterParamsMock, true);
expect(component.componentInstance.filterParams).toEqual(filterParamsMock);
expect(component.componentInstance.$state.go).toHaveBeenCalledWith('.',newParams, {location: 'replace', notify: false});
//expect(component.componentInstance.makeFilterParamsFromCheckboxes).toHaveBeenCalledWith(component.componentInstance.typesChecklistModel);
//expect(component.componentInstance.buildCheckboxLists).toHaveBeenCalled();
expect(component.componentInstance.applyFilterParamsToView).toHaveBeenCalledWith(filterParamsMock);
});
it ('should call on catalog component makeFilteredCategories' , () => {
const component = TestBed.createComponent(CatalogComponent);
const categoryMock = [{"name":"Network L1-3","normalizedName":"network l1-3","uniqueId":"serviceNewCategory.network l1-3","icons":["network_l_1-3"],"subcategories":null,"version":null,"ownerId":null,"empty":false,"type":null}];
cacheServiceMock.get.mockImplementation(()=> categoryMock);
const resp = component.componentInstance.makeFilteredCategories(categoriesElements, checkboxesFilterMock.selectedComponentTypes);
expect(component.componentInstance.cacheService.get).toHaveBeenCalledWith("resourceCategories");
expect(resp).toEqual(categoryMock);
});
it ('should call on catalog component makeFilteredCategories return unique elements' , () => {
const component = TestBed.createComponent(CatalogComponent);
const categoryMock = [{"name":"Network L1-3","normalizedName":"network l1-3","uniqueId":"serviceNewCategory.network l1-3","icons":["network_l_1-3"],"subcategories":null,"version":null,"ownerId":null,"empty":false,"type":null},
{"name":"Network L1-3","normalizedName":"network l1-3","uniqueId":"serviceNewCategory.network l1-3","icons":["network_l_1-3"],"subcategories":null,"version":null,"ownerId":null,"empty":false,"type":null},
{"name":"Network Service","normalizedName":"network service","uniqueId":"serviceNewCategory.network service","icons":["network_l_1-3"],"subcategories":null,"version":null,"ownerId":null,"empty":false,"type":null}];
const categoryUniqueMock = [{"name":"Network L1-3","normalizedName":"network l1-3","uniqueId":"serviceNewCategory.network l1-3","icons":["network_l_1-3"],"subcategories":null,"version":null,"ownerId":null,"empty":false,"type":null},
{"name":"Network Service","normalizedName":"network service","uniqueId":"serviceNewCategory.network service","icons":["network_l_1-3"],"subcategories":null,"version":null,"ownerId":null,"empty":false,"type":null}];
cacheServiceMock.get.mockImplementation(()=> categoryMock);
checkboxesFilterMock.selectedComponentTypes = ["SERVICE", "Resource.VF"];
const resp = component.componentInstance.makeFilteredCategories(categoriesElements, checkboxesFilterMock.selectedComponentTypes);
expect(component.componentInstance.cacheService.get).toHaveBeenCalledWith("resourceCategories");
expect(resp).toEqual(categoryUniqueMock);
});
});
|