Templates: verify it's possible to add a vfModule to a loaded template
[vid.git] / vid-webpack-master / cypress / integration / iFrames / instantiation-templates.e2e.ts
1 import * as _ from "lodash";
2 import {PropertyPath} from "lodash";
3
4 describe('Drawing Board: Instantiation Templates', function () {
5
6   describe('Instantiation templates ', () => {
7
8     beforeEach(() => {
9       cy.clearSessionStorage();
10       cy.setTestApiParamToGR();
11       cy.initAAIMock();
12       cy.initGetAAISubDetails();
13       cy.initVidMock();
14       cy.initDrawingBoardUserPermission();
15       cy.login();
16
17       mockAsyncBulkResponse();
18     });
19
20     afterEach(() => {
21       cy.screenshot();
22     });
23
24     describe('Load Page and Deploy', () => {
25
26       it(`Given a stored template - when click "deploy" - then a coherent request should be sent upon deploy`,  () => {
27
28         loadDrawingBoardWithRecreateMode();
29
30         // Then...
31         cy.getElementByDataTestsId("node-vProbe_NC_VNF 0").should('be.visible');
32         assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd();
33       });
34
35       it('Given a stored template - when "edit" vnf and vfmodules are opened - then template’s details are visible as expected and deploy without changes', () => {
36
37         loadDrawingBoardWithRecreateMode();
38
39         // Then...
40         editNode("node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0")
41         .getElementByDataTestsId("instanceName").should('have.value', 'hvf6arlba007')
42         .getElementByDataTestsId("productFamily").should('contain', 'Emanuel')
43         .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1')
44         .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6')
45         .getElementByDataTestsId("lineOfBusiness").should('contain', 'zzz1')
46         .getElementByDataTestsId("rollback").should('contain', 'Rollback')
47         .checkPlatformValue('xxx1')
48          .getElementByDataTestsId("cancelButton").click();
49
50         editNode("node-c5b26cc1-a66f-4b69-aa23-6abc7c647c88-vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0")
51         .getElementByDataTestsId("instanceName").should('have.value', 'hvf6arlba007_lba_Base_01')
52         .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6')
53         .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1')
54         .getElementByDataTestsId("rollback").should('contain', 'Rollback')
55         .getElementByDataTestsId("cancelButton").click();
56
57         editNode("node-c09e4530-8fd8-418f-9483-2f57ce927b05-vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1")
58         .getElementByDataTestsId("instanceName").should('have.value', 'my_hvf6arlba007_lba_dj_01')
59         .getElementByDataTestsId("volumeGroupName").should('have.value', 'my_special_hvf6arlba007_lba_dj_01_vol')
60         .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6')
61         .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1')
62         .getElementByDataTestsId("rollback").should('contain', 'Rollback')
63         .getElementByDataTestsId("sdncPreLoad").should('have.value', 'on')
64         .getElementByDataTestsId("cancelButton").click();
65
66         assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd();
67         });
68
69       it(`Given a stored template - when "edit" service is opened - then template’s details are visible as expected`,  function ()  {
70
71         loadDrawingBoardWithRecreateMode();
72
73         cy.openServiceContextMenu()
74         .getElementByDataTestsId("context-menu-header-edit-item").click()
75         .getElementByDataTestsId("instanceName").should('have.value', 'vProbe_NC_Service_DG_new_SI')
76         .getElementByDataTestsId("subscriberName").should('contain', 'SILVIA ROBBINS')
77         .getElementByDataTestsId("serviceType").should('contain', 'TYLER SILVIA')
78         .getElementByDataTestsId("owningEntity").should('contain', 'WayneHolland')
79         .getElementByDataTestsId("project").should('contain', 'WATKINS')
80         .getElementByDataTestsId("rollback").should('contain', 'Rollback');
81
82       });
83
84       it.skip(`Given a stored template - add one VfModule, edit it's details, and deploy - deploy is added with the vfModule details`, () => {
85         // Test is disabled, as an issue currently prevents from clicking the [+] button.
86
87         loadDrawingBoardWithRecreateMode();
88
89         let newVfModuleName = "new.vfmodule.name";
90         let module1ModelId = "VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1";
91         let module1CustomizationId = `vprobe_nc_vnf0..${module1ModelId}`;
92
93         // Click target VNF on right tree
94         cy.getElementByDataTestsId('node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0').click();
95
96         // Click [+] vfModule on left tree
97         cy.drawingBoardPressAddButtonByElementName(`node-${module1CustomizationId}`)
98           .click({force: true});
99
100         editNode(`node-c09e4530-8fd8-418f-9483-2f57ce927b05-${module1CustomizationId}`, 1);
101           cy.clearInput("instanceName");
102           cy.typeToInput("instanceName", newVfModuleName);
103           cy.selectDropdownOptionByText('lcpRegion', 'hvf6');
104           cy.selectDropdownOptionByText('tenant', 'DN5242-Nov21-T1');
105           cy.getElementByDataTestsId('form-set').click();
106
107         // Then...
108         cy.getReduxState().then((state) => {
109           let vnfPath = [
110             "vnfs", "vProbe_NC_VNF 0"
111           ];
112
113           let vfModules_1Path = [
114             ...vnfPath, "vfModules", module1CustomizationId,
115           ];
116
117           let serviceInstanceElementOnRedux = state.service.serviceInstance[serviceModelId];
118           let latestVfModule_1Path = findPathOfLatestVfModule(serviceInstanceElementOnRedux, vfModules_1Path);
119
120           // This is a funny merge, as values are already there, but that way ensures
121           // the values that selected are really deployed, while limiting the cost of
122           // maintenance, by taking other vfModule's fields as granted.
123           let latestVfModule_1ExpectedValue = _.merge(
124             _.get(serviceInstanceElementOnRedux, latestVfModule_1Path),
125             {
126               instanceName: newVfModuleName,
127               volumeGroupName: `${newVfModuleName}_vol`,
128               lcpCloudRegionId: "hvf6",
129               tenantId: "4914ab0ab3a743e58f0eefdacc1dde77",
130             }
131           );
132
133           assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd([
134             {path: ["existingNames", newVfModuleName], value: ""},
135             {path: ["existingNames", `${newVfModuleName}_vol`], value: ""},
136             {path: latestVfModule_1Path, value: latestVfModule_1ExpectedValue},
137             {path: ["validationCounter"], value: null},  // side-effect
138           ]);
139         });
140
141       });
142
143       [
144         {desc: "with changes", modifySomeValues: true},
145         {desc: "without changes", modifySomeValues: false},
146       ].forEach((testCase) => {
147
148         it(`Given a stored template - edit service vnf and vfmodule ${testCase.desc} - deploy request should be ${testCase.desc}`, function () {
149
150           loadDrawingBoardWithRecreateMode();
151
152           //edit service
153           cy.openServiceContextMenu();
154           cy.getElementByDataTestsId("context-menu-header-edit-item").click();
155           if (testCase.modifySomeValues) {
156             cy.clearInput("instanceName");
157             cy.typeToInput("instanceName", "different.instance.name");
158           }
159           cy.getElementByDataTestsId('form-set').click();
160
161           // edit vnf
162           editNode("node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0");
163           if (testCase.modifySomeValues) {
164             cy.selectPlatformValue('platform');
165             cy.selectDropdownOptionByText("tenant", "CESAR-100-D-spjg61909");
166           }
167           cy.getElementByDataTestsId('form-set').click();
168
169           //edit vf module
170           editNode("node-c5b26cc1-a66f-4b69-aa23-6abc7c647c88-vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0");
171           if (testCase.modifySomeValues) {
172             cy.getElementByDataTestsId('sdncPreLoad').click();
173           }
174           cy.getElementByDataTestsId('form-set').click();
175
176           // Then...
177           let vnfPath = [
178             "vnfs", "vProbe_NC_VNF 0"
179           ];
180           let vfModule_0Path = [
181             ...vnfPath, "vfModules",
182             "vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0",
183             "vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0ahubg",
184           ];
185
186           assertThatBodyFromDeployRequestEqualsToFile(testCase.modifySomeValues ? [
187             {path: ["instanceName"], value: "different.instance.name"},
188             {path: ["existingNames", "vprobe_nc_service_dg_new_si"], value: undefined},
189             {path: ["existingNames", "different.instance.name"], value: ""},
190
191             {path: [...vnfPath, "platformName"], value: "xxx1,platform"},
192             {path: [...vnfPath, "tenantId"], value: "f2f3830e4c984d45bcd00e1a04158a79"},
193
194             {path: [...vfModule_0Path, "sdncPreLoad"], value: true},
195           ] : []);
196         })
197
198       });
199
200     });
201   });
202 });
203
204 const serviceModelId = '6cfeeb18-c2b0-49df-987a-da47493c8e38';
205
206 function loadDrawingBoardWithRecreateMode() {
207   const templateUuid = "46390edd-7100-46b2-9f18-419bd24fb60b";
208
209   const drawingBoardAction = `RECREATE`;
210   const templateTopologyEndpoint = "templateTopology";
211   cy.route(`**/rest/models/services/${serviceModelId}`,
212     'fixture:../support/jsonBuilders/mocks/jsons/instantiationTemplates/templates__service_model.json')
213   .as('serviceModel');
214
215   cy.route(`**/instantiationTemplates/${templateTopologyEndpoint}/${templateUuid}`,
216     'fixture:../../../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json')
217   .as('templateTopology');
218
219   // When...
220
221   cy.openIframe(`app/ui/#/servicePlanning/${drawingBoardAction}` +
222     `?jobId=${templateUuid}` +
223     `&serviceModelId=${serviceModelId}`);
224
225   cy.wait('@serviceModel');
226   cy.wait('@templateTopology');
227 }
228
229 function editNode(dataTestId: string, index ?: number) {
230   return cy.drawingBoardTreeOpenContextMenuByElementDataTestId(dataTestId, index)
231     .drawingBoardTreeClickOnContextMenuOptionByName('Edit')
232 }
233
234 function assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd(deviationFromExpected: { path: PropertyPath, value: any }[] = []) {
235   cy.getDrawingBoardDeployBtn().click();
236   cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
237     cy.readFile('../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json').then((expectedResult) => {
238       convertRollbackOnFailureValueFromStringToBoolean(expectedResult);
239
240       let xhrBodyWithoutIsDirtyField = removeIsDirtyFieldFromXhrRequestBody(xhr);
241       setDeviationInExpected(expectedResult, deviationFromExpected);
242       cy.deepCompare(xhrBodyWithoutIsDirtyField, expectedResult);
243     });
244   });
245 }
246
247
248 function assertThatBodyFromDeployRequestEqualsToFile(deviationFromExpected: { path: PropertyPath, value: any }[] = []) {
249   cy.getDrawingBoardDeployBtn().click();
250   cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
251
252     cy.readFile('../vid-automation/src/test/resources/asyncInstantiation/templates__instance_from_template__set_without_modify1.json').then((expectedResult) => {
253       setDeviationInExpected(expectedResult, deviationFromExpected);
254       cy.deepCompare(xhr.request.body, expectedResult);
255     });
256
257   });
258 }
259
260 function setDeviationInExpected(expectedResult: any, deviations: { path: PropertyPath; value: any }[]) {
261   for (const deviation of deviations) {
262     _.set(expectedResult, deviation.path, deviation.value);
263   }
264 }
265
266 function findPathOfLatestVfModule(serviceInstanceElementFromRedux: any, vfModulesContainerPath: string[]) {
267   let latestVfModuleRandomlySelectedKey: string = _.last(_.keys(
268     _.get(serviceInstanceElementFromRedux, vfModulesContainerPath)
269   )) as string;
270
271   return [...vfModulesContainerPath, latestVfModuleRandomlySelectedKey];
272 }
273
274   //We use this function because the deployService() on drawing-board-header.component class
275   // changes rollbackOnFailure value from string type to boolean.
276   function convertRollbackOnFailureValueFromStringToBoolean(expectedResult: any) {
277     expectedResult.rollbackOnFailure = Boolean(expectedResult.rollbackOnFailure);
278   }
279
280 function removeIsDirtyFieldFromXhrRequestBody(xhr : any) {
281   let xhrTempBody = JSON.parse(JSON.stringify(xhr.request.body));
282   delete xhrTempBody.isDirty;
283   return xhrTempBody;
284 }
285
286   function mockAsyncBulkResponse() {
287     cy.server().route({
288       url: Cypress.config('baseUrl') + '/asyncInstantiation/bulk',
289       method: 'POST',
290       status: 200,
291       response: "[]",
292     }).as("expectedPostAsyncInstantiation");
293   }