aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/workspace/information-artifact/informational-artifact-page.spec.ts
blob: 10fd14739b679ef0be4ff41ae002fac7f3324615 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import {async, ComponentFixture, TestBed} from "@angular/core/testing";
import {NO_ERRORS_SCHEMA} from "@angular/core";
import {ConfigureFn, configureTests} from "../../../../../jest/test-config.helper";
import {NgxDatatableModule} from "@swimlane/ngx-datatable";
import {WorkspaceService} from "../workspace.service";
import {SdcUiServices} from "onap-ui-angular";
import {TopologyTemplateService} from "../../../services/component-services/topology-template.service";
import {Observable} from "rxjs/Observable";
import {ComponentMetadata} from "../../../../models/component-metadata";
import 'rxjs/add/observable/of';
import {NgxsModule, Store} from "@ngxs/store";
import {ArtifactsState} from "../../../store/states/artifacts.state";
import {InformationArtifactPageComponent} from "./information-artifact-page.component";
import { informationalArtifactsMock} from "../../../../../jest/mocks/artifacts-mock";
import {ArtifactsService} from "../../../components/forms/artifacts-form/artifacts.service";

describe('informational artifacts page', () => {

    let fixture: ComponentFixture<InformationArtifactPageComponent>;
    let topologyTemplateServiceMock: Partial<TopologyTemplateService>;
    let workspaceServiceMock: Partial<WorkspaceService>;
    let loaderServiceMock: Partial<SdcUiServices.LoaderService>;
    let store: Store;

    beforeEach(
        async(() => {

            topologyTemplateServiceMock = {
                getArtifactsByType: jest.fn().mockImplementation((componentType, id, artifactType) => Observable.of(informationalArtifactsMock))
            };
            workspaceServiceMock = {metadata: <ComponentMetadata>{uniqueId: 'service_unique_id', componentType: 'SERVICE'}}

            loaderServiceMock = {
                activate : jest.fn(),
                deactivate: jest.fn()
            }
            const configure: ConfigureFn = testBed => {
                testBed.configureTestingModule({
                    declarations: [InformationArtifactPageComponent],
                    imports: [NgxDatatableModule, NgxsModule.forRoot([ArtifactsState])],
                    schemas: [NO_ERRORS_SCHEMA],
                    providers: [
                        {provide: WorkspaceService, useValue: workspaceServiceMock},
                        {provide: TopologyTemplateService, useValue: topologyTemplateServiceMock},
                        {provide: SdcUiServices.LoaderService, useValue: loaderServiceMock },
                        {provide: ArtifactsService, useValue: {}},
                    ],
                });
            };

            configureTests(configure).then(testBed => {
                fixture = testBed.createComponent(InformationArtifactPageComponent);
                store = testBed.get(Store);
            });
        })
    );

    it('should match current snapshot of informational artifact pages component', () => {
        expect(fixture).toMatchSnapshot();
    });

    it('should see exactly 3 informational artifacts and six buttons to add artifact by template', () => {
        fixture.componentInstance.ngOnInit();
        fixture.componentInstance.informationArtifacts$.subscribe((artifacts)=> {
            expect(artifacts.length).toEqual(3);
        })
        fixture.componentInstance.informationArtifactsAsButtons$.subscribe((artifacts)=> {
            expect(artifacts.length).toEqual(6);
        })

        store.selectOnce(state => state.artifacts.artifacts).subscribe(artifacts => {
            expect(artifacts.length).toEqual(9);
        });
    })


});