1 import * as _ from "lodash";
2 import {PropertyPath} from "lodash";
4 describe('Drawing Board: Instantiation Templates', function () {
6 describe('Instantiation templates ', () => {
9 cy.clearSessionStorage();
10 cy.setTestApiParamToGR();
12 cy.initGetAAISubDetails();
14 cy.initDrawingBoardUserPermission();
17 mockAsyncBulkResponse();
24 describe('Load Page and Deploy', () => {
26 it(`Given a stored template - when click "deploy" - then a coherent request should be sent upon deploy`, () => {
28 loadDrawingBoardWithRecreateMode();
31 cy.getElementByDataTestsId("node-vProbe_NC_VNF 0").should('be.visible');
32 assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd();
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', () => {
37 loadDrawingBoardWithRecreateMode();
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();
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();
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();
66 assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd();
69 it(`Given a stored template - when "edit" service is opened - then template’s details are visible as expected`, function () {
71 loadDrawingBoardWithRecreateMode();
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');
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.
87 loadDrawingBoardWithRecreateMode();
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}`;
93 // Click target VNF on right tree
94 cy.getElementByDataTestsId('node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0').click();
96 // Click [+] vfModule on left tree
97 cy.drawingBoardPressAddButtonByElementName(`node-${module1CustomizationId}`)
98 .click({force: true});
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();
108 cy.getReduxState().then((state) => {
110 "vnfs", "vProbe_NC_VNF 0"
113 let vfModules_1Path = [
114 ...vnfPath, "vfModules", module1CustomizationId,
117 let serviceInstanceElementOnRedux = state.service.serviceInstance[serviceModelId];
118 let latestVfModule_1Path = findPathOfLatestVfModule(serviceInstanceElementOnRedux, vfModules_1Path);
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),
126 instanceName: newVfModuleName,
127 volumeGroupName: `${newVfModuleName}_vol`,
128 lcpCloudRegionId: "hvf6",
129 tenantId: "4914ab0ab3a743e58f0eefdacc1dde77",
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
144 {desc: "with changes", modifySomeValues: true},
145 {desc: "without changes", modifySomeValues: false},
146 ].forEach((testCase) => {
148 it(`Given a stored template - edit service vnf and vfmodule ${testCase.desc} - deploy request should be ${testCase.desc}`, function () {
150 loadDrawingBoardWithRecreateMode();
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");
159 cy.getElementByDataTestsId('form-set').click();
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");
167 cy.getElementByDataTestsId('form-set').click();
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();
174 cy.getElementByDataTestsId('form-set').click();
178 "vnfs", "vProbe_NC_VNF 0"
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",
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: ""},
191 {path: [...vnfPath, "platformName"], value: "xxx1,platform"},
192 {path: [...vnfPath, "tenantId"], value: "f2f3830e4c984d45bcd00e1a04158a79"},
194 {path: [...vfModule_0Path, "sdncPreLoad"], value: true},
204 const serviceModelId = '6cfeeb18-c2b0-49df-987a-da47493c8e38';
206 function loadDrawingBoardWithRecreateMode() {
207 const templateUuid = "46390edd-7100-46b2-9f18-419bd24fb60b";
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')
215 cy.route(`**/instantiationTemplates/${templateTopologyEndpoint}/${templateUuid}`,
216 'fixture:../../../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json')
217 .as('templateTopology');
221 cy.openIframe(`app/ui/#/servicePlanning/${drawingBoardAction}` +
222 `?jobId=${templateUuid}` +
223 `&serviceModelId=${serviceModelId}`);
225 cy.wait('@serviceModel');
226 cy.wait('@templateTopology');
229 function editNode(dataTestId: string, index ?: number) {
230 return cy.drawingBoardTreeOpenContextMenuByElementDataTestId(dataTestId, index)
231 .drawingBoardTreeClickOnContextMenuOptionByName('Edit')
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);
240 let xhrBodyWithoutIsDirtyField = removeIsDirtyFieldFromXhrRequestBody(xhr);
241 setDeviationInExpected(expectedResult, deviationFromExpected);
242 cy.deepCompare(xhrBodyWithoutIsDirtyField, expectedResult);
248 function assertThatBodyFromDeployRequestEqualsToFile(deviationFromExpected: { path: PropertyPath, value: any }[] = []) {
249 cy.getDrawingBoardDeployBtn().click();
250 cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
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);
260 function setDeviationInExpected(expectedResult: any, deviations: { path: PropertyPath; value: any }[]) {
261 for (const deviation of deviations) {
262 _.set(expectedResult, deviation.path, deviation.value);
266 function findPathOfLatestVfModule(serviceInstanceElementFromRedux: any, vfModulesContainerPath: string[]) {
267 let latestVfModuleRandomlySelectedKey: string = _.last(_.keys(
268 _.get(serviceInstanceElementFromRedux, vfModulesContainerPath)
271 return [...vfModulesContainerPath, latestVfModuleRandomlySelectedKey];
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);
280 function removeIsDirtyFieldFromXhrRequestBody(xhr : any) {
281 let xhrTempBody = JSON.parse(JSON.stringify(xhr.request.body));
282 delete xhrTempBody.isDirty;
286 function mockAsyncBulkResponse() {
288 url: Cypress.config('baseUrl') + '/asyncInstantiation/bulk',
292 }).as("expectedPostAsyncInstantiation");