1 import { NO_ERRORS_SCHEMA } from '@angular/core';
2 import { async, ComponentFixture, TestBed } from '@angular/core/testing';
3 import { Capability, Match } from 'app/models';
4 import { ConfigureFn, configureTests } from '../../../../../../../jest/test-config.helper';
5 import { Requirement } from '../../../../../../models/requirement';
6 import { ConnectionWizardService } from '../connection-wizard.service';
7 import { FromNodeStepComponent } from './from-node-step.component';
9 describe('from-node-step component', () => {
11 let fixture: ComponentFixture<FromNodeStepComponent>;
12 let connectionWizardServiceMockWithoutSelectedMatch: Partial<ConnectionWizardService>;
13 let connectionWizardServiceMockWithSelectedMatch: Partial<ConnectionWizardService>;
15 const connectionWizardServiceMockSelectedMatchWithRequirements = {requirement: 'val'};
17 connectionWizardServiceMockWithoutSelectedMatch = {
18 getOptionalRequirementsByInstanceUniqueId: jest.fn().mockReturnValue(5),
19 getOptionalCapabilitiesByInstanceUniqueId: jest.fn().mockReturnValue(10),
21 connectRelationModel: {
24 uniqueId : 'testUniqueID'
30 connectionWizardServiceMockWithSelectedMatch = {
31 selectedMatch: connectionWizardServiceMockSelectedMatchWithRequirements,
32 getOptionalRequirementsByInstanceUniqueId: jest.fn().mockReturnValue(5),
33 getOptionalCapabilitiesByInstanceUniqueId: jest.fn().mockReturnValue(10)
36 let expectedConnectionWizardServiceMock = connectionWizardServiceMockWithoutSelectedMatch;
40 const configure: ConfigureFn = testBed => {
41 testBed.configureTestingModule({
42 declarations: [FromNodeStepComponent],
44 schemas: [NO_ERRORS_SCHEMA],
46 {provide: ConnectionWizardService, useValue: expectedConnectionWizardServiceMock}
51 configureTests(configure).then(testBed => {
52 fixture = testBed.createComponent(FromNodeStepComponent);
58 it('should match current snapshot', () => {
59 expect(fixture).toMatchSnapshot();
62 it('preventBack return true - always', () => {
63 fixture.componentInstance.ngOnInit();
64 const result = fixture.componentInstance.preventBack();
65 expect(result).toEqual(true);
68 it('preventNext return true since selectedMatch does not exist in connectionWizardServiceMock', () => {
69 fixture.componentInstance.ngOnInit();
70 const result = fixture.componentInstance.preventNext();
71 expect(result).toEqual(true);
74 it('preventNext return false since to selectedMatch or selectedMatch.capability & selectedMatch.requirement does exist in connectionWizardServiceMock', () => {
75 fixture.componentInstance.connectWizardService = connectionWizardServiceMockWithSelectedMatch;
76 fixture.componentInstance.ngOnInit();
77 const result = fixture.componentInstance.preventNext();
78 expect(result).toEqual(false);
81 it('updateSelectedReqOrCap is called with instance of requirement, the selectMatch will be set to an Instance of Match of type Requirement', () => {
82 const requirement = new Requirement();
83 fixture.componentInstance.updateSelectedReqOrCap(requirement);
84 const expectedSelectedMatch = fixture.componentInstance.connectWizardService.selectedMatch;
86 expect(expectedSelectedMatch).toBeInstanceOf(Match);
87 expect(expectedSelectedMatch.capability).toBe(null);
88 expect(expectedSelectedMatch.fromNode).toBe('testUniqueID');
89 expect(expectedSelectedMatch.isFromTo).toBe(true);
90 expect(expectedSelectedMatch.toNode).toBe(null);
91 expect(expectedSelectedMatch.requirement).toBeInstanceOf(Requirement);
94 it('updateSelectedReqOrCap is called with instance of capability, the selectMatch will be set to an Instance of Match of type Capability', () => {
95 const capability = new Capability();
96 fixture.componentInstance.updateSelectedReqOrCap(capability);
97 const expectedSelectedMatch = fixture.componentInstance.connectWizardService.selectedMatch;
99 expect(expectedSelectedMatch).toBeInstanceOf(Match);
100 expect(expectedSelectedMatch.requirement).toBe(null);
101 expect(expectedSelectedMatch.fromNode).toBe(null);
102 expect(expectedSelectedMatch.isFromTo).toBe(false);
103 expect(expectedSelectedMatch.toNode).toBe('testUniqueID');
104 expect(expectedSelectedMatch.capability).toBeInstanceOf(Capability);
107 it('updateSelectedReqOrCap is called with null, the selectMatch will be set to null', () => {
108 fixture.componentInstance.updateSelectedReqOrCap(null);
109 const expectedSelectedMatch = fixture.componentInstance.connectWizardService.selectedMatch;
111 expect(expectedSelectedMatch).toBe(null);