Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / workspace / disribution / distribution-component-table / distribution-component-artifact-table / distribution-component-artifact-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 { DistributionComponentArtifactTableComponent } from './distribution-component-artifact-table.component';
8
9 describe('DistributionComponentArtifactTableComponent', () => {
10   let fixture: ComponentFixture<DistributionComponentArtifactTableComponent>;
11   let distibutionServiceMock: Partial<DistributionService>;
12
13   const mockArtifactsForDistributionAndComponentName = [
14       {
15         name: 'Artifact1',
16         statuses: [
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'}
20         ],
21         url: 'URL1',
22       },
23       {
24         name: 'Artifact2',
25         statuses: [
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'}
29         ],
30         url: 'URL2',
31       },
32       {
33         name: 'ArtifactWithNoStatuses',
34         url: 'URL2',
35       }
36     ];
37
38   beforeEach(() => {
39
40     distibutionServiceMock = {
41       getArtifactstByDistributionIDAndComponentsName: jest.fn().mockReturnValue(mockArtifactsForDistributionAndComponentName),
42     };
43
44     const configure: ConfigureFn = (testBed) => {
45       testBed.configureTestingModule({
46         declarations: [DistributionComponentArtifactTableComponent],
47         imports: [NgxDatatableModule],
48         schemas: [NO_ERRORS_SCHEMA],
49         providers: [
50           {provide: DistributionService, useValue: distibutionServiceMock}
51         ],
52       });
53     };
54
55     configureTests(configure).then((testBed) => {
56       fixture = testBed.createComponent(DistributionComponentArtifactTableComponent);
57     });
58
59   });
60
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);
65   });
66
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);
74
75     expect(fixture.componentInstance.artifacts[1].name).toBe('Artifact2');
76   });
77
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');
85
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'});
88
89   });
90 });