Add cypress test that check vnf popup contains correct lcp region data.
[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("lcpRegion").should('contain', 'hvf6')
41         .getElementByDataTestsId("cancelButton").click();
42
43         assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd();
44         });
45       });
46
47     });
48
49   });
50
51 function loadDrawingBoardWithRecreateMode() {
52   const serviceModelId = '6cfeeb18-c2b0-49df-987a-da47493c8e38';
53   const templateUuid = "46390edd-7100-46b2-9f18-419bd24fb60b";
54
55   const drawingBoardAction = `RECREATE`;
56   const templateTopologyEndpoint = "templateTopology";
57   cy.route(`**/rest/models/services/${serviceModelId}`,
58     'fixture:../support/jsonBuilders/mocks/jsons/instantiationTemplates/templates__service_model.json')
59   .as('serviceModel');
60
61   cy.route(`**/asyncInstantiation/${templateTopologyEndpoint}/${templateUuid}`,
62     'fixture:../../../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json')
63   .as('templateTopology');
64
65   // When...
66
67   cy.openIframe(`app/ui/#/servicePlanning/${drawingBoardAction}` +
68     `?jobId=${templateUuid}` +
69     `&serviceModelId=${serviceModelId}`);
70
71   cy.wait('@serviceModel');
72   cy.wait('@templateTopology');
73 }
74
75 function assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd() {
76   cy.getDrawingBoardDeployBtn().click();
77   cy.wait('@expectedPostAsyncInstantiation').then(xhr => {
78     cy.readFile('../vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json').then((expectedResult) => {
79       convertRollbackOnFailureValueFromStringToBoolean(expectedResult);
80
81       let xhrBodyWithoutIsDirtyField = removeIsDirtyFieldFromXhrRequestBody(xhr);
82       cy.deepCompare(xhrBodyWithoutIsDirtyField, expectedResult);
83     });
84   });
85 }
86
87   //We use this function because the deployService() on drawing-board-header.component class
88   // changes rollbackOnFailure value from string type to boolean.
89   function convertRollbackOnFailureValueFromStringToBoolean(expectedResult: any) {
90     expectedResult.rollbackOnFailure = Boolean(expectedResult.rollbackOnFailure);
91   }
92
93 function removeIsDirtyFieldFromXhrRequestBody(xhr : any) {
94   let xhrTempBody = JSON.parse(JSON.stringify(xhr.request.body));
95   delete xhrTempBody.isDirty;
96   return xhrTempBody;
97 }
98
99   function mockAsyncBulkResponse() {
100     cy.server().route({
101       url: Cypress.config('baseUrl') + '/asyncInstantiation/bulk',
102       method: 'POST',
103       status: 200,
104       response: "[]",
105     }).as("expectedPostAsyncInstantiation");
106   }