Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / workspace / disribution / distribution.component.spec.ts
1 import { NO_ERRORS_SCHEMA } from '@angular/core';
2 import { ComponentFixture } from '@angular/core/testing';
3 import { NgxDatatableModule } from '@swimlane/ngx-datatable';
4 import { SdcUiServices } from 'onap-ui-angular';
5 import { ConfigureFn, configureTests } from '../../../../../jest/test-config.helper';
6 import { ComponentMetadata } from '../../../../models/component-metadata';
7 import { AuthenticationService } from '../../../services/authentication.service';
8 import { WorkspaceService } from '../workspace.service';
9 import { DistributionComponent } from './distribution.component';
10 import { DistributionService } from './distribution.service';
11 import {EventListenerService} from "../../../../services/event-listener-service";
12
13 describe('DistributionComponent', () => {
14   let fixture: ComponentFixture<DistributionComponent>;
15   let distibutionServiceMock: Partial<DistributionService>;
16   let workspaceServiceMock: Partial<WorkspaceService>;
17   let loaderServiceMock: Partial<SdcUiServices.LoaderService>;
18   let authenticationServiceMock: Partial <AuthenticationService>;
19   let eventListenerService: Partial <EventListenerService>;
20
21   const mockDistributionListFromService = [
22     {
23       deployementStatus: 'Distributed',
24       distributionID: '1',
25       timestamp: '2019-07-21 08:37:02.834 UTC',
26       userId: 'Aretha Franklin(op0001)'
27     }, {
28       deployementStatus: 'Distributed',
29       distributionID: '2',
30       timestamp: '2019-07-21 09:37:02.834 UTC',
31       userId: 'Aretha Franklin(op0001)'
32     }];
33
34   beforeEach(() => {
35
36     distibutionServiceMock = {
37       initDistributionsList: jest.fn(),
38       getDistributionList: jest.fn().mockReturnValue(mockDistributionListFromService),
39       initDistributionsStatusForDistributionID: jest.fn()
40     };
41
42     const componentMetadata = new ComponentMetadata();
43     componentMetadata.uuid = '111';
44
45     workspaceServiceMock = {
46       metadata : componentMetadata
47     };
48
49     authenticationServiceMock = {
50       getLoggedinUser: jest.fn().mockReturnValue({role: 'designer'})
51     };
52
53     eventListenerService = {
54       registerObserverCallback: jest.fn(),
55       unRegisterObserver: jest.fn()
56     }
57
58     loaderServiceMock = {
59       activate: jest.fn(),
60       deactivate: jest.fn()
61     };
62
63     const configure: ConfigureFn = (testBed) => {
64       testBed.configureTestingModule({
65         declarations: [DistributionComponent],
66         imports: [NgxDatatableModule],
67         schemas: [NO_ERRORS_SCHEMA],
68         providers: [
69           {provide: DistributionService, useValue: distibutionServiceMock},
70           {provide: WorkspaceService, useValue: workspaceServiceMock},
71           {provide: SdcUiServices.LoaderService, useValue: loaderServiceMock},
72           {provide: AuthenticationService, useValue: authenticationServiceMock},
73           {provide: EventListenerService, useValue: eventListenerService}
74         ],
75       });
76     };
77
78     configureTests(configure).then((testBed) => {
79       fixture = testBed.createComponent(DistributionComponent);
80     });
81
82   });
83
84   it('Once the Distribution Component is created - distributionsResponseFromServer save all the distributions from the Service', async () => {
85     fixture.componentInstance.componentUuid = 'componentUid';
86     fixture.componentInstance.rowDistributionID = null;
87     fixture.componentInstance.isModal = false;
88
89     await fixture.componentInstance.ngOnInit();
90     expect(fixture.componentInstance.distributions.length).toBe(2);
91   });
92 });