Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / workspace / information-artifact / informational-artifact-page.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 import {NgxDatatableModule} from "@swimlane/ngx-datatable";
5 import {WorkspaceService} from "../workspace.service";
6 import {SdcUiServices} from "onap-ui-angular";
7 import {TopologyTemplateService} from "../../../services/component-services/topology-template.service";
8 import {Observable} from "rxjs/Observable";
9 import {ComponentMetadata} from "../../../../models/component-metadata";
10 import 'rxjs/add/observable/of';
11 import {NgxsModule, Store} from "@ngxs/store";
12 import {ArtifactsState} from "../../../store/states/artifacts.state";
13 import {InformationArtifactPageComponent} from "./information-artifact-page.component";
14 import { informationalArtifactsMock} from "../../../../../jest/mocks/artifacts-mock";
15 import {ArtifactsService} from "../../../components/forms/artifacts-form/artifacts.service";
16
17 describe('informational artifacts page', () => {
18
19     let fixture: ComponentFixture<InformationArtifactPageComponent>;
20     let topologyTemplateServiceMock: Partial<TopologyTemplateService>;
21     let workspaceServiceMock: Partial<WorkspaceService>;
22     let loaderServiceMock: Partial<SdcUiServices.LoaderService>;
23     let store: Store;
24
25     beforeEach(
26         async(() => {
27
28             topologyTemplateServiceMock = {
29                 getArtifactsByType: jest.fn().mockImplementation((componentType, id, artifactType) => Observable.of(informationalArtifactsMock))
30             };
31             workspaceServiceMock = {metadata: <ComponentMetadata>{uniqueId: 'service_unique_id', componentType: 'SERVICE'}}
32
33             loaderServiceMock = {
34                 activate : jest.fn(),
35                 deactivate: jest.fn()
36             }
37             const configure: ConfigureFn = testBed => {
38                 testBed.configureTestingModule({
39                     declarations: [InformationArtifactPageComponent],
40                     imports: [NgxDatatableModule, NgxsModule.forRoot([ArtifactsState])],
41                     schemas: [NO_ERRORS_SCHEMA],
42                     providers: [
43                         {provide: WorkspaceService, useValue: workspaceServiceMock},
44                         {provide: TopologyTemplateService, useValue: topologyTemplateServiceMock},
45                         {provide: SdcUiServices.LoaderService, useValue: loaderServiceMock },
46                         {provide: ArtifactsService, useValue: {}},
47                     ],
48                 });
49             };
50
51             configureTests(configure).then(testBed => {
52                 fixture = testBed.createComponent(InformationArtifactPageComponent);
53                 store = testBed.get(Store);
54             });
55         })
56     );
57
58     it('should match current snapshot of informational artifact pages component', () => {
59         expect(fixture).toMatchSnapshot();
60     });
61
62     it('should see exactly 3 informational artifacts and six buttons to add artifact by template', () => {
63         fixture.componentInstance.ngOnInit();
64         fixture.componentInstance.informationArtifacts$.subscribe((artifacts)=> {
65             expect(artifacts.length).toEqual(3);
66         })
67         fixture.componentInstance.informationArtifactsAsButtons$.subscribe((artifacts)=> {
68             expect(artifacts.length).toEqual(6);
69         })
70
71         store.selectOnce(state => state.artifacts.artifacts).subscribe(artifacts => {
72             expect(artifacts.length).toEqual(9);
73         });
74     })
75
76
77 });