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 { DistributionComponentArtifactTableComponent } from './distribution-component-artifact-table.component';
9 describe('DistributionComponentArtifactTableComponent', () => {
10 let fixture: ComponentFixture<DistributionComponentArtifactTableComponent>;
11 let distibutionServiceMock: Partial<DistributionService>;
13 const mockArtifactsForDistributionAndComponentName = [
17 {timeStamp: '7/25/2019 12:48AM', status: 'DEPLOY_OK'},
18 {timeStamp: '7/25/2019 12:48AM', status: 'DOWNLOAD_OK'},
19 {timeStamp: '7/25/2019 12:48AM', status: 'NOTIFIED'}
26 {timeStamp: '7/26/2019 12:48AM', status: 'STATUS_TO_DISPLAY'},
27 {timeStamp: '7/25/2019 12:48AM', status: 'DOWNLOAD_OK'},
28 {timeStamp: '7/25/2019 12:48AM', status: 'NOTIFIED'}
33 name: 'ArtifactWithNoStatuses',
40 distibutionServiceMock = {
41 getArtifactstByDistributionIDAndComponentsName: jest.fn().mockReturnValue(mockArtifactsForDistributionAndComponentName),
44 const configure: ConfigureFn = (testBed) => {
45 testBed.configureTestingModule({
46 declarations: [DistributionComponentArtifactTableComponent],
47 imports: [NgxDatatableModule],
48 schemas: [NO_ERRORS_SCHEMA],
50 {provide: DistributionService, useValue: distibutionServiceMock}
55 configureTests(configure).then((testBed) => {
56 fixture = testBed.createComponent(DistributionComponentArtifactTableComponent);
61 it('Get Latest Artifact (status and timeStamp) - So the Component Table will display the last time stamp of the notification', async () => {
62 await fixture.componentInstance.ngOnInit();
63 expect(fixture.componentInstance.getLatestArtifact('Artifact2')).toEqual({status: 'STATUS_TO_DISPLAY', timeStamp: '7/26/2019 12:48AM'});
64 expect(fixture.componentInstance.getLatestArtifact('ArtifactWithNoStatuses')).toEqual(null);
67 it('Once the Distribution Component Artifact Table Component is created - artifacts will keep the relevant artifacts for a specific distributionID and Component Name', async () => {
68 await fixture.componentInstance.ngOnInit();
69 // tslint:disable:no-string-literal
70 expect(fixture.componentInstance.artifacts.length).toBe(3);
71 expect(fixture.componentInstance.artifacts[0].name).toBe('Artifact1');
72 expect(fixture.componentInstance.artifacts[0].url).toBe('URL1');
73 expect(fixture.componentInstance.artifacts[0].statuses.length).toBe(3);
75 expect(fixture.componentInstance.artifacts[1].name).toBe('Artifact2');
78 it('Once the Distribution Component Artifact Table Component is created for Modal- artifacts will keep the relevant artifacts for a ' +
79 'specific distributionID and Component Name filtered by Status', async () => {
80 fixture.componentInstance.statusFilter = 'DOWNLOAD_OK';
81 await fixture.componentInstance.ngOnInit();
82 expect(fixture.componentInstance.artifacts.length).toBe(3);
83 expect(fixture.componentInstance.artifacts[0].name).toBe('Artifact1');
84 expect(fixture.componentInstance.artifacts[0].url).toBe('URL1');
86 expect(fixture.componentInstance.artifacts[0].statuses.length).toBe(1);
87 expect(fixture.componentInstance.artifacts[0].statuses[0]).toEqual({status: 'DOWNLOAD_OK', timeStamp: '7/25/2019 12:48AM'});