Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / components / modals / onboarding-modal / onboarding-modal.component.spec.ts
1 import {async, ComponentFixture, TestBed} from "@angular/core/testing";
2 import { NO_ERRORS_SCHEMA} from "@angular/core";
3 import {ConfigureFn, configureTests} from "../../../../../jest/test-config.helper";
4
5 import {Observable} from "rxjs/Observable";
6 import {NgxDatatableModule} from "@swimlane/ngx-datatable";
7 import {SdcUiServices, SdcUiCommon} from "onap-ui-angular";
8 import 'rxjs/add/observable/of';
9 import {OnboardingService} from "../../../services/onboarding.service";
10 import {TranslateService} from "../../../shared/translator/translate.service";
11 import {CacheService} from "../../../services/cache.service";
12 import {FileUtilsService} from "../../../services/file-utils.service";
13 import {onboardingModalVSPMock, onboardingModalUniqueVSPMock, vspFromServerMock} from "../../../../../jest/mocks/onboarding-vsp.mock";
14 import {OnboardingModalComponent} from "./onboarding-modal.component";
15 import {TranslatePipe} from "../../../shared/translator/translate.pipe";
16
17 describe('onboarding modal component', () => {
18
19     let fixture: ComponentFixture<OnboardingModalComponent>;
20     let onboardingServiceMock: Partial<OnboardingService>;
21     let translateServiceMock: Partial<TranslateService>;
22     let cacheServiceMock: Partial<CacheService>;
23     let fileUtilsServiceMock: Partial<FileUtilsService>;
24     let popoverServiceMock: Partial<SdcUiServices.PopoverService>;
25     let loaderServiceMock: Partial<SdcUiServices.LoaderService>;
26
27     beforeEach(
28         async(() => {
29
30             onboardingServiceMock = {
31                 getOnboardingComponents: jest.fn().mockImplementation(()=>  Observable.of(onboardingModalUniqueVSPMock)),
32                 getComponentFromCsarUuid: jest.fn().mockImplementation(()=>  Observable.of(vspFromServerMock))
33             };
34
35             cacheServiceMock = {
36                 set: jest.fn()
37             };
38
39             loaderServiceMock = {
40                 activate: jest.fn(),
41                 deactivate: jest.fn()
42             }
43
44
45             const configure: ConfigureFn = testBed => {
46                 testBed.configureTestingModule({
47                     declarations: [OnboardingModalComponent, TranslatePipe],
48                     imports: [NgxDatatableModule],
49                     schemas: [NO_ERRORS_SCHEMA],
50                     providers: [
51                         { provide: OnboardingService, useValue: onboardingServiceMock },
52                         { provide: TranslateService, useValue: translateServiceMock },
53                         { provide: CacheService, useValue: cacheServiceMock },
54                         { provide: FileUtilsService, useValue: fileUtilsServiceMock },
55                         { provide: SdcUiServices.PopoverService, useValue: popoverServiceMock },
56                         { provide: SdcUiServices.LoaderService, useValue: loaderServiceMock }
57                     ],
58                 });
59             };
60             configureTests(configure).then(testBed => {
61                 fixture = testBed.createComponent(OnboardingModalComponent);
62             });
63         })
64     );
65
66     /*it('should match current snapshot of onboarding modal component', () => {
67         expect(fixture).toMatchSnapshot();
68     });*/
69
70     it('should see exactly 2 vsp in onboarding modal and call initOnboardingComponentsList', () => {
71         fixture.componentInstance.initOnboardingComponentsList();
72         expect(fixture.componentInstance.componentsMetadataList.length).toBe(2);
73     });
74
75     it('should see exactly 1 vsp in onboarding modal and call initOnboardingComponentsList', () => {
76         fixture.componentInstance.currentCsarUUID = "6348841e79a64871ba064ce340a968a4";
77         fixture.componentInstance.initOnboardingComponentsList();
78         expect(fixture.componentInstance.componentsMetadataList.length).toBe(1);
79     });
80
81     it('when get a list of vsp initMaxVersionOfItemsInList will return a list with unique items with the latest versions for each packageId', () => {
82         onboardingServiceMock.getOnboardingComponents = jest.fn().mockImplementation(() => Observable.of(onboardingModalVSPMock));
83         fixture.componentInstance.initOnboardingComponentsList();
84         expect(fixture.componentInstance.componentsMetadataList.length).toBe(2);
85     });
86
87     it('should filter out 1 vsp when searching and call updateFilter function', () => {
88         fixture.componentInstance.initOnboardingComponentsList();
89         let event = {
90             target : {
91                 value : 'test new vsp'
92             }
93         }
94
95         expect(fixture.componentInstance.componentsMetadataList.length).toBe(2);
96         fixture.componentInstance.updateFilter(event);
97         expect(fixture.componentInstance.componentsMetadataList.length).toBe(1);
98     });
99
100     it('When select the selected vsp the row details closed and call onSelectComponent function', () => {
101         fixture.componentInstance.initOnboardingComponentsList();
102         fixture.componentInstance.onSelectComponent({selected: []});
103         expect(fixture.componentInstance.selectedComponent).toEqual(undefined);
104         expect(fixture.componentInstance.componentFromServer).toEqual(undefined);
105     });
106
107     it('When select vsp a row with its details will be opened and call onSelectComponent function', () => {
108         fixture.componentInstance.initOnboardingComponentsList();
109         fixture.componentInstance.onSelectComponent({selected: onboardingModalVSPMock});
110         expect(fixture.componentInstance.selectedComponent).not.toEqual(null);
111         expect(fixture.componentInstance.componentFromServer).not.toEqual(undefined);
112         expect(fixture.componentInstance.isCsarComponentExists).toEqual(true);
113     });
114     it('When select new vsp a row with import and download buttons will be opened and call onSelectComponent function', () => {
115         fixture.componentInstance.initOnboardingComponentsList();
116         onboardingServiceMock.getComponentFromCsarUuid.mockImplementation(() => Observable.of(undefined));
117         fixture.componentInstance.onSelectComponent({selected: onboardingModalVSPMock});
118         expect(fixture.componentInstance.selectedComponent).not.toEqual(null);
119         expect(fixture.componentInstance.componentFromServer).toEqual(undefined);
120         expect(fixture.componentInstance.isCsarComponentExists).toEqual(false);
121     });
122 });