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";
9 describe('to-node-step component', () => {
11 let fixture: ComponentFixture<ToNodeStepComponent>;
12 let connectionWizardServiceMock: Partial<ConnectionWizardService>;
17 connectionWizardServiceMock = {
18 // selectedMatch: new Match(null, null, true, '',''),
22 getOptionalRequirementsByInstanceUniqueId: jest.fn().mockReturnValue(5),
23 getOptionalCapabilitiesByInstanceUniqueId: jest.fn().mockReturnValue(10)
26 const configure: ConfigureFn = testBed => {
27 testBed.configureTestingModule({
28 declarations: [ToNodeStepComponent],
30 schemas: [NO_ERRORS_SCHEMA],
32 {provide: ConnectionWizardService, useValue: connectionWizardServiceMock}
37 configureTests(configure).then(testBed => {
38 fixture = testBed.createComponent(ToNodeStepComponent);
44 it('should match current snapshot', () => {
45 expect(fixture).toMatchSnapshot();
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({});
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({});