NodeInfo::getModel expects the instance-model
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / objectsToTree / models / vrf / vrf.model.info.spec.ts
1 import {ComponentInfoService} from "../../../component-info/component-info.service";
2 import {NgRedux} from "@angular-redux/store";
3 import {AppState} from "../../../../../shared/store/reducers";
4 import {getTestBed, TestBed} from "@angular/core/testing";
5 import {HttpClientTestingModule} from "@angular/common/http/testing";
6 import {MockNgRedux, NgReduxTestingModule} from "@angular-redux/store/testing";
7 import {DynamicInputsService} from "../../dynamicInputs.service";
8 import {SharedTreeService} from "../../shared.tree.service";
9 import {DuplicateService} from "../../../duplicate/duplicate.service";
10 import {AaiService} from "../../../../../shared/services/aaiService/aai.service";
11 import {HttpClient, HttpHandler} from "@angular/common/http";
12 import {FeatureFlagsService} from "../../../../../shared/services/featureFlag/feature-flags.service";
13 import {IframeService} from "../../../../../shared/utils/iframe.service";
14 import {VrfModelInfo} from "./vrf.model.info";
15 import {ComponentInfoType} from "../../../component-info/component-info-model";
16 import {ModelInformationItem} from "../../../../../shared/components/model-information/model-information.component";
17 import {VrfModel} from "../../../../../shared/models/vrfModel";
18 import {AvailableNodeIcons} from "../../../available-models-tree/available-models-tree.service";
19 import each from 'jest-each';
20 import {DialogService} from "ng2-bootstrap-modal";
21 import {NetworkStepService} from "./vrfModal/networkStep/network.step.service";
22 import {VpnStepService} from "./vrfModal/vpnStep/vpn.step.service";
23
24 describe('Vrf Model Info', () => {
25
26   let injector;
27   let _componentInfoService : ComponentInfoService;
28
29   let _store : NgRedux<AppState>;
30   let _sharedTreeService: SharedTreeService;
31   let _dialogService : DialogService;
32   let _iframeService : IframeService;
33   let _networkStepService : NetworkStepService;
34   let _vpnStepService : VpnStepService;
35   let _featureFlagsService : FeatureFlagsService;
36   let vrfModel: VrfModelInfo;
37
38   beforeEach(() => {
39     TestBed.configureTestingModule({
40       imports: [HttpClientTestingModule, NgReduxTestingModule],
41       providers: [
42         MockNgRedux,
43         DynamicInputsService,
44         SharedTreeService,
45         DuplicateService,
46         AaiService,
47         HttpClient,
48         HttpHandler,
49         FeatureFlagsService,
50         ComponentInfoService,
51         DialogService,
52         IframeService,
53         IframeService,
54         NetworkStepService,
55        VpnStepService]
56     }).compileComponents();
57
58     injector = getTestBed();
59     _sharedTreeService = injector.get(SharedTreeService);
60     _dialogService = injector.get(DialogService);
61     _iframeService = injector.get(IframeService);
62     _networkStepService = injector.get(NetworkStepService);
63     _featureFlagsService = injector.get(FeatureFlagsService);
64     _vpnStepService = injector.get(VpnStepService);
65     _store = injector.get(NgRedux);
66     _componentInfoService = injector.get(ComponentInfoService);
67
68     vrfModel = new VrfModelInfo(_store,_sharedTreeService, _dialogService, _iframeService, _featureFlagsService, _networkStepService, _vpnStepService);
69
70   });
71
72
73   test('vrfModel should be defined', () => {
74     expect(vrfModel).toBeDefined();
75   });
76
77   test('vrfModel should defined extra details', () => {
78     expect(vrfModel.name).toEqual('vrfs');
79     expect(vrfModel.type).toEqual('VRF');
80     expect(vrfModel.childNames).toEqual(['networks','vpns']);
81     expect(vrfModel.componentInfoType).toEqual(ComponentInfoType.VRF);
82   });
83
84   test('Info for vrf should be correct', () => {
85     const model = new VrfModel();
86     const instance = null;
87     let actualNetworkInfo = vrfModel.getInfo(model,instance);
88     let expectedNetworkInfo = [
89       ModelInformationItem.createInstance('Min instances', "1"),
90       ModelInformationItem.createInstance('Max instances', "1"),
91       ModelInformationItem.createInstance("Association", "L3-Network - VPN")
92     ];
93     expect(actualNetworkInfo).toEqual(expectedNetworkInfo);
94   });
95
96
97
98   test('getModel should return VRF model with min and max are equal to 1 (hard coded)', () => {
99     let model: VrfModel = vrfModel.getModel({
100         "uuid": "9cac02be-2489-4374-888d-2863b4511a59",
101         "invariantUuid": "b67a289b-1688-496d-86e8-1583c828be0a",
102         "properties": {
103           "ecomp_generated_naming": "false",
104           "type": "VRF-ENTRY",
105         },
106         "type": "Configuration"
107       }
108     );
109     expect(model.properties['type']).toEqual('VRF-ENTRY');
110     expect(model.min).toEqual(1);
111     expect(model.max).toEqual(1);
112   });
113
114   const showNodeIconsDataProvider = [
115     [false, new AvailableNodeIcons(true , false)],
116     [true, new AvailableNodeIcons(false , true)]
117   ];
118
119   each(showNodeIconsDataProvider).test('showNodeIcons should return value according reach limit of max',(existVRFs,expectedResult)=>{
120     const serviceId : string = 'servicedId';
121     const node = getNode();
122     let state = getMockState();
123     if(existVRFs) {
124       state.service.serviceInstance.servicedId.existingVRFCounterMap = {
125         'modelCustomizationId': 1
126       };
127     }
128     jest.spyOn(MockNgRedux.getInstance(), 'getState').mockReturnValue(state);
129     const result = vrfModel.showNodeIcons(<any>node, serviceId);
130     expect(result).toEqual(expectedResult);
131   });
132
133   function getNode() {
134     return {
135       data: {
136         id: 'vrfId',
137         name: 'VRF Entry Configuration 0',
138         modelCustomizationId: 'modelCustomizationId',
139         modelUniqueId: 'modelCustomizationId',
140         getModel: function () {
141           return {max: 1}
142         }
143       }
144     };
145   }
146
147   function getMockState(){
148     return {
149       global:{
150         "drawingBoardStatus": "CREATE"
151       },
152       service : {
153         serviceHierarchy : {
154           'servicedId' : {
155           }
156         },
157         serviceInstance : {
158           'servicedId' : {
159             'existingVRFCounterMap' : {},
160             'vrfs' : {
161               'vrfName' :{
162
163               }
164             }
165           }
166         }
167       }
168     };
169   }
170
171
172 })