Allow edit service button to be shown on service context menu in recreate mode.
[vid.git] / vid-webpack-master / cypress / integration / iFrames / instantiation-templates.e2e.ts
1 import ObjectLike = Cypress.ObjectLike;
2
3 describe('Drawing Board: Instantiation Templates', function () {
4
5   describe('Instantiation templates ', () => {
6
7     beforeEach(() => {
8       cy.clearSessionStorage();
9       cy.setTestApiParamToVNF();
10       cy.initAAIMock();
11       cy.initGetAAISubDetails();
12       cy.initVidMock();
13       cy.initDrawingBoardUserPermission();
14       cy.login();
15
16       mockAsyncBulkResponse();
17     });
18
19     afterEach(() => {
20       cy.screenshot();
21     });
22
23     describe('Load Page and Deploy', () => {
24
25       it(`Given a stored template - when click "deploy" - then a coherent request should be sent upon deploy`,  () => {
26
27         loadDrawingBoardWithRecreateMode();
28
29         // Then...
30         cy.getElementByDataTestsId("node-vProbe_NC_VNF 0").should('be.visible');
31         assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd();
32       });
33
34       it('View a template’s details as expected', ()=> {
35
36         loadDrawingBoardWithRecreateMode();
37
38         // Then...
39         cy.drawingBoardTreeOpenContextMenuByElementDataTestId("node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0")
40         .drawingBoardTreeClickOnContextMenuOptionByName('Edit')
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         cy.drawingBoardTreeOpenContextMenuByElementDataTestId("node-c5b26cc1-a66f-4b69-aa23-6abc7c647c88-vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0")
51         .drawingBoardTreeClickOnContextMenuOptionByName('Edit')
52         .getElementByDataTestsId("instanceName").should('have.value', 'hvf6arlba007_lba_Base_01')
53         .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6')
54         .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1')
55         .getElementByDataTestsId("rollback").should('contain', 'Rollback')
56         .getElementByDataTestsId("cancelButton").click();
57
58         cy.drawingBoardTreeOpenContextMenuByElementDataTestId("node-c09e4530-8fd8-418f-9483-2f57ce927b05-vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1")
59         .drawingBoardTreeClickOnContextMenuOptionByName('Edit')
60         .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6')
61         .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1')
62         .getElementByDataTestsId("rollback").should('contain', 'Rollback')
63         .getElementByDataTestsId("cancelButton").click();
64
65
66
67         assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd();
68         });
69
70       it(`Edit the service`,  function ()  {
71
72         loadDrawingBoardWithRecreateMode();
73
74         cy.openServiceContextMenu()
75         .getElementByDataTestsId("context-menu-header-edit-item").click()
76         .getElementByDataTestsId("instanceName").should('have.value', 'vProbe_NC_Service_DG_new_SI')
77         .getElementByDataTestsId("subscriberName").should('contain', 'SILVIA ROBBINS')
78         .getElementByDataTestsId("serviceType").should('contain', 'TYLER SILVIA')
79         .getElementByDataTestsId("owningEntity").should('contain', 'WayneHolland')
80         .getElementByDataTestsId("project").should('contain', 'WATKINS')
81         .getElementByDataTestsId("rollback").should('contain', 'Rollback');
82
83
84
85
86       });
87       });
88     });
89   });
90
91 function loadDrawingBoardWithRecreateMode() {
92   const serviceModelId = '6cfeeb18-c2b0-49df-987a-da47493c8e38';
93   const templateUuid = "46390edd-7100-46b2-9f18-419bd24fb60b";
94
95   const drawingBoardAction = `RECREATE`;
96   const templateTopologyEndpoint = "templateTopology";
97   cy.route(`**/rest/models/services/${serviceModelId}`,
98     'fixture:../support/jsonBuilders/mocks/jsons/instantiationTemplates/templates__service_model.json')
99   .as('serviceModel');
100
101   cy.route(`**/asyncInstantiation/${templateTopologyEndpoint}/${templateUuid}`,
102     'fixture:../../../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json')
103   .as('templateTopology');
104
105   // When...
106
107   cy.openIframe(`app/ui/#/servicePlanning/${drawingBoardAction}` +
108     `?jobId=${templateUuid}` +
109     `&serviceModelId=${serviceModelId}`);
110
111   cy.wait('@serviceModel');
112   cy.wait('@templateTopology');
113 }
114
115 function assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd() {
116   cy.getDrawingBoardDeployBtn().click();
117   cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
118     cy.readFile('../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json').then((expectedResult) => {
119       convertRollbackOnFailureValueFromStringToBoolean(expectedResult);
120
121       let xhrBodyWithoutIsDirtyField = removeIsDirtyFieldFromXhrRequestBody(xhr);
122       cy.deepCompare(xhrBodyWithoutIsDirtyField, expectedResult);
123     });
124   });
125 }
126
127   //We use this function because the deployService() on drawing-board-header.component class
128   // changes rollbackOnFailure value from string type to boolean.
129   function convertRollbackOnFailureValueFromStringToBoolean(expectedResult: any) {
130     expectedResult.rollbackOnFailure = Boolean(expectedResult.rollbackOnFailure);
131   }
132
133 function removeIsDirtyFieldFromXhrRequestBody(xhr : any) {
134   let xhrTempBody = JSON.parse(JSON.stringify(xhr.request.body));
135   delete xhrTempBody.isDirty;
136   return xhrTempBody;
137 }
138
139   function mockAsyncBulkResponse() {
140     cy.server().route({
141       url: Cypress.config('baseUrl') + '/asyncInstantiation/bulk',
142       method: 'POST',
143       status: 200,
144       response: "[]",
145     }).as("expectedPostAsyncInstantiation");
146   }