UI support for service update via tosca template import
[sdc.git] / catalog-ui / src / app / ng2 / pages / workspace / tosca-artifacts / tosca-artifact-page.spec.ts
1 import {async, ComponentFixture, TestBed} from "@angular/core/testing";
2 import {NO_ERRORS_SCHEMA} from "@angular/core";
3 import {ToscaArtifactPageComponent} from "./tosca-artifact-page.component";
4 import {ConfigureFn, configureTests} from "../../../../../jest/test-config.helper";
5 import {NgxDatatableModule} from "@swimlane/ngx-datatable";
6 import {WorkspaceService} from "../workspace.service";
7 import {SdcUiServices} from "onap-ui-angular";
8 import {TopologyTemplateService} from "../../../services/component-services/topology-template.service";
9 import {Observable} from "rxjs/Observable";
10 import {ComponentMetadata} from "../../../../models/component-metadata";
11 import 'rxjs/add/observable/of';
12 import {NgxsModule, Store} from "@ngxs/store";
13 import {ArtifactsState} from "../../../store/states/artifacts.state";
14 import {toscaArtifactMock} from "../../../../../jest/mocks/artifacts-mock";
15 import { ComponentServiceNg2 } from "app/ng2/services/component-services/component.service";
16
17 describe('tosca artifacts page', () => {
18
19     let fixture: ComponentFixture<ToscaArtifactPageComponent>;
20     let topologyTemplateServiceMock: Partial<TopologyTemplateService>;
21     let workspaceServiceMock: Partial<WorkspaceService>;
22     let store: Store;
23     let notificationMock: Partial<any>;
24
25
26     beforeEach(
27         async(() => {
28
29             topologyTemplateServiceMock = {
30                 getArtifactsByType: jest.fn().mockImplementation((componentType, id, artifactType) => Observable.of(toscaArtifactMock))
31             };
32             workspaceServiceMock = {metadata: <ComponentMetadata>{uniqueId: 'service_unique_id', componentType: 'SERVICE'}}
33
34             const configure: ConfigureFn = testBed => {
35                 testBed.configureTestingModule({
36                     declarations: [ToscaArtifactPageComponent],
37                     imports: [NgxDatatableModule, NgxsModule.forRoot([ArtifactsState])],
38                     schemas: [NO_ERRORS_SCHEMA],
39                     providers: [
40                         {provide: WorkspaceService, useValue: workspaceServiceMock},
41                         {provide: TopologyTemplateService, useValue: topologyTemplateServiceMock},
42                         {provide: ComponentServiceNg2, useValue: {}},
43                         {provide: "Notification", useValue: notificationMock }
44                     ],
45                 });
46             };
47
48             configureTests(configure).then(testBed => {
49                 fixture = testBed.createComponent(ToscaArtifactPageComponent);
50                 store = testBed.get(Store);
51             });
52         })
53     );
54
55     it('should match current snapshot of tosca artifact pages component', () => {
56         expect(fixture).toMatchSnapshot();
57     });
58
59     it('should see exactly 2 tosca artifacts', () => {
60         fixture.componentInstance.ngOnInit();
61         fixture.componentInstance.toscaArtifacts$.subscribe((artifacts)=> {
62             expect(artifacts.length).toEqual(2);
63         })
64         store.selectOnce(state => state.artifacts.toscaArtifacts).subscribe(artifacts => {
65             expect(artifacts.length).toEqual(9);
66         });
67     })
68
69 });