From 94dc3c44c3e6fb5fba2a3539c0eef55079543bc0 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Wed, 31 Aug 2022 21:21:12 +0530 Subject: [PATCH] test: cy explicit delete local storage before restoring Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- .../common/7a_create_project_from_excel.js | 62 ++----------------- .../integration/spec/roleValidation.spec.js | 4 +- scripts/cypress-v2/support/commands.js | 14 +++-- 3 files changed, 18 insertions(+), 62 deletions(-) diff --git a/scripts/cypress-v2/integration/common/7a_create_project_from_excel.js b/scripts/cypress-v2/integration/common/7a_create_project_from_excel.js index 709dc79c67..8bc8d93b4f 100644 --- a/scripts/cypress-v2/integration/common/7a_create_project_from_excel.js +++ b/scripts/cypress-v2/integration/common/7a_create_project_from_excel.js @@ -69,6 +69,8 @@ export const genTest = (apiType, dbType) => { describe(`Import from excel`, () => { before(() => { + // loginPage.signIn(roles.owner.credentials); + cy.restoreLocalStorage(); cy.wait(1000); @@ -106,15 +108,9 @@ export const genTest = (apiType, dbType) => { cy.get('.nc-import-menu').should('exist').click() cy.getActiveMenu().find('.ant-dropdown-menu-item').contains('Microsoft Excel').click() - // trigger import - // cy.get(`[data-menu-id="addORImport"]`).click(); - // cy.getActivePopUp().contains("Microsoft Excel").should('exist').click(); - cy.get(".nc-input-import").should('exist').find('input').attachFile(filepath); cy.toastWait("Uploaded file simple.xlsx successfully"); cy.get(".nc-btn-import").should('exist').click(); - - // cy.toastWait("Uploaded file simple.xlsx successfully") }); it("File Upload: Verify pre-load template page", () => { @@ -161,11 +157,12 @@ export const genTest = (apiType, dbType) => { } }); cy.getActiveModal().find(".ant-btn-primary").click(); + + // wait for page to get loaded (issue observed in CI-CD) + cy.wait(5000); }); it("File Upload: Verify loaded data", () => { - // wait for page to get loaded (issue observed in CICD) - cy.wait(5000); cy.openTableTab("Sheet2", 2); for (const [key, value] of Object.entries(expectedData)) { @@ -192,19 +189,6 @@ export const genTest = (apiType, dbType) => { .should("exist"); } cy.closeTableTab("Sheet3"); - - // // delete project once all operations are completed - // cy.get('.nc-noco-brand-icon').click(); - // - // cy.get(`.nc-action-btn`) - // .should("exist") - // .last() - // .click(); - // - // cy.getActiveModal() - // .find(".ant-btn-dangerous") - // .should("exist") - // .click(); }); it.skip("URL: Upload excel as template", () => { @@ -302,42 +286,6 @@ export const genTest = (apiType, dbType) => { }); }; -// if (typeof require !== 'undefined') XLSX = require('xlsx'); - -// let workbook - -// const getSheetList = (wb) => { -// return wb.SheetNames -// } - -// const getRow = (sheet, rowIdx) => { -// let sheetData = XLSX.utils.sheet_to_json(workbook.Sheets[sheet], { -// header: 1, -// blankrows: false -// }); - -// return sheetData[rowIdx] -// } - -// // https://stackoverflow.com/questions/40630606/how-to-read-only-column-a-value-from-excel-using-nodejs -// const getColumn = (sheet, colIdx) => { -// let columnA = [] -// const worksheet = workbook.Sheets[sheet]; -// for (let z in worksheet) { -// if (z.toString()[0] === colIdx) { -// columnA.push(worksheet[z].v); -// } -// } -// return columnA -// } - -// const getCell = (sheet, cellIdx) => { -// const worksheet = workbook.Sheets[sheet]; -// var desired_cell = worksheet[cellIdx]; -// desired_value = (desired_cell ? desired_cell.v : undefined); -// return desired_value -// } - /** * @copyright Copyright (c) 2021, Xgene Cloud Ltd * diff --git a/scripts/cypress-v2/integration/spec/roleValidation.spec.js b/scripts/cypress-v2/integration/spec/roleValidation.spec.js index b2f904baaf..2a8cb0498c 100644 --- a/scripts/cypress-v2/integration/spec/roleValidation.spec.js +++ b/scripts/cypress-v2/integration/spec/roleValidation.spec.js @@ -10,7 +10,8 @@ export function _advSettings(roleType, mode) { cy.log(roleType, mode); if(mode === 'baseShare') { - cy.get('.nc-project-menu').should('not.exist') + cy.get('.nc-project-menu').should('exist').click() + cy.getActiveMenu().find(`[data-menu-id="language"]`).should('exist') return; } @@ -230,6 +231,7 @@ export function _viewMenu(roleType, mode) { menuWithSubmenuCount = 2; // Get API Snippet menuWithoutSubmenuCount = 1 + if(mode === 'baseShare') menuWithoutSubmenuCount = 0 } else if (roleType === "commenter" || roleType === "viewer") { // Download CSV & Download excel menuWithSubmenuCount = 0; diff --git a/scripts/cypress-v2/support/commands.js b/scripts/cypress-v2/support/commands.js index c0f644cbc4..000bdc194d 100644 --- a/scripts/cypress-v2/support/commands.js +++ b/scripts/cypress-v2/support/commands.js @@ -243,9 +243,12 @@ Cypress.Commands.add("saveLocalStorage", (name) => { return; } + LOCAL_STORAGE_MEMORY = {}; Object.keys(localStorage).forEach((key) => { LOCAL_STORAGE_MEMORY[key] = localStorage[key]; }); + cy.printLocalStorage(); + }); Cypress.Commands.add("restoreLocalStorage", (name) => { @@ -257,11 +260,13 @@ Cypress.Commands.add("restoreLocalStorage", (name) => { return; } - Object.keys(LOCAL_STORAGE_MEMORY).forEach((key) => { - localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key]); - }); + cy.deleteLocalStorage().then(() => { + Object.keys(LOCAL_STORAGE_MEMORY).forEach((key) => { + localStorage.setItem(key, LOCAL_STORAGE_MEMORY[key]); + }); - cy.printLocalStorage(); + cy.printLocalStorage(); + }); }); Cypress.Commands.add("deleteLocalStorage", () => { @@ -273,6 +278,7 @@ Cypress.Commands.add("deleteLocalStorage", () => { Cypress.Commands.add('printLocalStorage', () => { cy.task('log', `[printLocalStorage]`); cy.task('log', JSON.stringify(localStorage, null, 2)); + cy.task('log', JSON.stringify(LOCAL_STORAGE_MEMORY, null, 2)); }) Cypress.Commands.add("getActiveModal", () => {