Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / composition / graph / connection-wizard / from-node-step / from-node-step.component.spec.ts
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';
8
9 describe('from-node-step component', () => {
10
11     let fixture: ComponentFixture<FromNodeStepComponent>;
12     let connectionWizardServiceMockWithoutSelectedMatch: Partial<ConnectionWizardService>;
13     let connectionWizardServiceMockWithSelectedMatch: Partial<ConnectionWizardService>;
14
15     const connectionWizardServiceMockSelectedMatchWithRequirements = {requirement: 'val'};
16
17     connectionWizardServiceMockWithoutSelectedMatch = {
18         getOptionalRequirementsByInstanceUniqueId: jest.fn().mockReturnValue(5),
19         getOptionalCapabilitiesByInstanceUniqueId: jest.fn().mockReturnValue(10),
20
21         connectRelationModel: {
22             fromNode: {
23                 componentInstance: {
24                     uniqueId : 'testUniqueID'
25                 }
26             }
27         }
28     };
29
30     connectionWizardServiceMockWithSelectedMatch = {
31         selectedMatch: connectionWizardServiceMockSelectedMatchWithRequirements,
32         getOptionalRequirementsByInstanceUniqueId: jest.fn().mockReturnValue(5),
33         getOptionalCapabilitiesByInstanceUniqueId: jest.fn().mockReturnValue(10)
34     };
35
36     let expectedConnectionWizardServiceMock = connectionWizardServiceMockWithoutSelectedMatch;
37
38     beforeEach(
39         async(() => {
40             const configure: ConfigureFn = testBed => {
41                 testBed.configureTestingModule({
42                     declarations: [FromNodeStepComponent],
43                     imports: [],
44                     schemas: [NO_ERRORS_SCHEMA],
45                     providers: [
46                         {provide: ConnectionWizardService, useValue: expectedConnectionWizardServiceMock}
47                     ],
48                 });
49             };
50
51             configureTests(configure).then(testBed => {
52                 fixture = testBed.createComponent(FromNodeStepComponent);
53             });
54         })
55     );
56
57
58     it('should match current snapshot', () => {
59         expect(fixture).toMatchSnapshot();
60     });
61
62     it('preventBack return true - always', () => {
63         fixture.componentInstance.ngOnInit();
64         const result = fixture.componentInstance.preventBack();
65         expect(result).toEqual(true);
66     });
67
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);
72     });
73
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);
79     });
80
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;
85
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);
92     });
93
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;
98
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);
105     });
106
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;
110
111         expect(expectedSelectedMatch).toBe(null);
112     });
113
114 });