When feature toggle is active then SDNC preload files is enable.
[vid.git] / vid-webpack-master / cypress / integration / iFrames / sdncPreload.e2e.ts
1 describe('SDNC preload ', () => {
2
3   beforeEach(() => {
4     cy.clearSessionStorage();
5     cy.setTestApiParamToGR();
6     cy.initAAIMock();
7     cy.initGetAAISubDetails();
8     cy.initVidMock();
9     cy.initDrawingBoardUserPermission();
10     cy.login();
11   });
12
13   afterEach(() => {
14     cy.screenshot();
15   });
16
17   it('feature toggle is on and SDNC is checked then SDNC preload file is enable : upload success' , () => {
18     mockPreloadResult(true, 200);
19     cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);
20     cy.editNode("node-c09e4530-8fd8-418f-9483-2f57ce927b05-vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1");
21     checkUploadLinkLogic();
22
23     uploadFile().then(() => {
24       cy.get('.sdc-modal__content').should('contain', 'The pre-load file(s) have been uploaded successfully.');
25       cy.getElementByDataTestsId('button-ok').click()
26         .getElementByDataTestsId('sdnc_pereload_upload_link').should('contain', 'Upload another')
27     });
28   });
29
30   it('feature toggle is on and SDNC is checked then SDNC preload file is enable : upload fail', () => {
31     mockPreloadResult(false, 200);
32     cy.loadDrawingBoardWithRecreateMode(templateWithVnfSetup);
33
34     cy.editNode("node-c09e4530-8fd8-418f-9483-2f57ce927b05-vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1");
35     checkUploadLinkLogic();
36
37     uploadFile().then(() => {
38       cy.get('.sdc-modal__content').should('contain', 'Failed to upload one or more of the files, please retry.');
39       cy.getElementByDataTestsId('button-ok').click()
40         .getElementByDataTestsId('sdnc_pereload_upload_link').should('contain', 'Upload')
41     });
42   });
43 });
44
45
46 let apiTestResources = '../vid-automation/src/test/resources/asyncInstantiation/';
47
48 const templateWithVnfSetup = {
49   serviceModelId: '6cfeeb18-c2b0-49df-987a-da47493c8e38',
50   instanceTemplateFile: apiTestResources + 'templates__instance_template.json',
51   instanceTemplateSetWithoutModifyFile: apiTestResources + 'templates__instance_from_template__set_without_modify1.json',
52   serviceModelFile: '../support/jsonBuilders/mocks/jsons/instantiationTemplates/templates__service_model.json',
53 };
54
55 function mockAsyncBulkResponse() {
56   cy.server().route({
57     url: Cypress.config('baseUrl') + '/asyncInstantiation/bulk',
58     method: 'POST',
59     status: 200,
60     response: true,
61   }).as("expectedPostAsyncInstantiation");
62 }
63
64 function mockPreloadResult(response: boolean, status?: number) {
65   cy.server().route({
66     url: Cypress.config('baseUrl') + '/preload',
67     method: 'POST',
68     status: status ? status : 200,
69     response: response,
70   }).as("preload");
71 }
72
73
74 function uploadFile() {
75   // @ts-ignore
76   return new Promise((resolve) => {
77     const fileName = '../support/uploadFiles/sdncPreLoadFileExample.json';
78     cy.fixture(fileName).then(fileContent => {
79       // @ts-ignore
80       cy.get('input[type=file]').eq(0).upload({fileContent, fileName, mimeType: 'application/json'}).then(() => {
81         resolve();
82       });
83     })
84   });
85 }
86
87 function checkUploadLinkLogic() {
88   cy.getElementByDataTestsId('sdnc_pereload_upload_link').should('contain', 'Upload').should('not.have.class', 'disabled')
89     .getElementByDataTestsId('sdncPreLoad').click()
90     .getElementByDataTestsId('sdnc_pereload_upload_link').should('contain', 'Upload').should('have.class', 'disabled')
91     .getElementByDataTestsId('sdncPreLoad').click()
92 }