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