Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / composition / graph / connection-wizard / to-node-step / to-node-step.component.spec.ts
1 import {async, ComponentFixture, TestBed} from "@angular/core/testing";
2 import {NO_ERRORS_SCHEMA} from "@angular/core";
3 import {ToNodeStepComponent} from "./to-node-step.component";
4 import {ConnectionWizardService} from "../connection-wizard.service";
5 import {ConfigureFn, configureTests} from "../../../../../../../jest/test-config.helper";
6 import {Match} from "../../../../../../models/graph/match-relation";
7
8
9 describe('to-node-step component', () => {
10
11     let fixture: ComponentFixture<ToNodeStepComponent>;
12     let connectionWizardServiceMock: Partial<ConnectionWizardService>;
13
14     beforeEach(
15         async(() => {
16
17             connectionWizardServiceMock = {
18                 // selectedMatch: new Match(null, null, true, '',''),
19                 selectedMatch: {
20                     isFromTo: false
21                 },
22                 getOptionalRequirementsByInstanceUniqueId: jest.fn().mockReturnValue(5),
23                 getOptionalCapabilitiesByInstanceUniqueId: jest.fn().mockReturnValue(10)
24             }
25
26             const configure: ConfigureFn = testBed => {
27                 testBed.configureTestingModule({
28                     declarations: [ToNodeStepComponent],
29                     imports: [],
30                     schemas: [NO_ERRORS_SCHEMA],
31                     providers: [
32                         {provide: ConnectionWizardService, useValue: connectionWizardServiceMock}
33                     ],
34                 });
35             };
36
37             configureTests(configure).then(testBed => {
38                 fixture = testBed.createComponent(ToNodeStepComponent);
39             });
40         })
41     );
42
43
44     it('should match current snapshot', () => {
45         expect(fixture).toMatchSnapshot();
46     });
47
48     it('should test the ngOnInit with isFromTo = false', () => {
49         const component = TestBed.createComponent(ToNodeStepComponent);
50         let service = TestBed.get(ConnectionWizardService);
51         service.selectedMatch.isFromTo = false;
52         component.componentInstance.ngOnInit();
53         expect(component.componentInstance.displayRequirementsOrCapabilities).toEqual("Requirement");
54         expect(connectionWizardServiceMock.getOptionalRequirementsByInstanceUniqueId).toHaveBeenCalledWith(false, connectionWizardServiceMock.selectedMatch.capability);
55         expect(component.componentInstance.optionalRequirementsMap).toEqual(5);
56         expect(component.componentInstance.optionalCapabilitiesMap).toEqual({});
57     });
58
59
60     it('should test the ngOnInit with isFromTo = true', () => {
61         const component = TestBed.createComponent(ToNodeStepComponent);
62         let service = TestBed.get(ConnectionWizardService);
63         service.selectedMatch.isFromTo = true;
64         component.componentInstance.ngOnInit();
65         expect(component.componentInstance.displayRequirementsOrCapabilities).toEqual("Capability");
66         expect(connectionWizardServiceMock.getOptionalCapabilitiesByInstanceUniqueId).toHaveBeenCalledWith(true, connectionWizardServiceMock.selectedMatch.requirement);
67         expect(component.componentInstance.optionalCapabilitiesMap).toEqual(10);
68         expect(component.componentInstance.optionalRequirementsMap).toEqual({});
69     });
70
71 });