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
|
import {async, ComponentFixture, TestBed} from "@angular/core/testing";
import {NO_ERRORS_SCHEMA} from "@angular/core";
import {ToNodeStepComponent} from "./to-node-step.component";
import {ConnectionWizardService} from "../connection-wizard.service";
import {ConfigureFn, configureTests} from "../../../../../../../jest/test-config.helper";
import {Match} from "../../../../../../models/graph/match-relation";
describe('to-node-step component', () => {
let fixture: ComponentFixture<ToNodeStepComponent>;
let connectionWizardServiceMock: Partial<ConnectionWizardService>;
beforeEach(
async(() => {
connectionWizardServiceMock = {
// selectedMatch: new Match(null, null, true, '',''),
selectedMatch: {
isFromTo: false
},
getOptionalRequirementsByInstanceUniqueId: jest.fn().mockReturnValue(5),
getOptionalCapabilitiesByInstanceUniqueId: jest.fn().mockReturnValue(10)
}
const configure: ConfigureFn = testBed => {
testBed.configureTestingModule({
declarations: [ToNodeStepComponent],
imports: [],
schemas: [NO_ERRORS_SCHEMA],
providers: [
{provide: ConnectionWizardService, useValue: connectionWizardServiceMock}
],
});
};
configureTests(configure).then(testBed => {
fixture = testBed.createComponent(ToNodeStepComponent);
});
})
);
it('should match current snapshot', () => {
expect(fixture).toMatchSnapshot();
});
it('should test the ngOnInit with isFromTo = false', () => {
const component = TestBed.createComponent(ToNodeStepComponent);
let service = TestBed.get(ConnectionWizardService);
service.selectedMatch.isFromTo = false;
component.componentInstance.ngOnInit();
expect(component.componentInstance.displayRequirementsOrCapabilities).toEqual("Requirement");
expect(connectionWizardServiceMock.getOptionalRequirementsByInstanceUniqueId).toHaveBeenCalledWith(false, connectionWizardServiceMock.selectedMatch.capability);
expect(component.componentInstance.optionalRequirementsMap).toEqual(5);
expect(component.componentInstance.optionalCapabilitiesMap).toEqual({});
});
it('should test the ngOnInit with isFromTo = true', () => {
const component = TestBed.createComponent(ToNodeStepComponent);
let service = TestBed.get(ConnectionWizardService);
service.selectedMatch.isFromTo = true;
component.componentInstance.ngOnInit();
expect(component.componentInstance.displayRequirementsOrCapabilities).toEqual("Capability");
expect(connectionWizardServiceMock.getOptionalCapabilitiesByInstanceUniqueId).toHaveBeenCalledWith(true, connectionWizardServiceMock.selectedMatch.requirement);
expect(component.componentInstance.optionalCapabilitiesMap).toEqual(10);
expect(component.componentInstance.optionalRequirementsMap).toEqual({});
});
});
|