Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / workspace / disribution / distribution-component-table / distribution-component-table.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 { DistributionService } from '../distribution.service';
7 import { DistributionComponentTableComponent } from './distribution-component-table.component';
8
9 describe('DistributionComponentTableComponent', () => {
10   let fixture: ComponentFixture<DistributionComponentTableComponent>;
11   let distibutionServiceMock: Partial<DistributionService>;
12
13   const mockComponentsForDistribution = ['Consumer1', 'Consumer2'];
14
15   beforeEach(() => {
16
17     distibutionServiceMock = {
18       getComponentsByDistributionID: jest.fn().mockReturnValue(mockComponentsForDistribution),
19       getArtifactstByDistributionIDAndComponentsName: jest.fn(),
20       getArtifactsForDistributionIDAndComponentByStatus: jest.fn()
21     };
22
23     const configure: ConfigureFn = (testBed) => {
24       testBed.configureTestingModule({
25         declarations: [DistributionComponentTableComponent],
26         imports: [NgxDatatableModule],
27         schemas: [NO_ERRORS_SCHEMA],
28         providers: [
29           {provide: DistributionService, useValue: distibutionServiceMock},
30           {provide: SdcUiServices.ModalService, useValue: {}}
31         ],
32       });
33     };
34
35     configureTests(configure).then((testBed) => {
36       fixture = testBed.createComponent(DistributionComponentTableComponent);
37     });
38
39   });
40
41   it('Once the Distribution Component Table Component is created - components will keep the relevant components for a specific distributionID', async () => {
42     await fixture.componentInstance.ngOnInit();
43     expect(fixture.componentInstance.components.length).toBe(2);
44     expect(fixture.componentInstance.components[0]).toBe('Consumer1');
45     expect(fixture.componentInstance.components[1]).toBe('Consumer2');
46   });
47 });