Browse Source

test(cypress): import from excel validation

Signed-off-by: Raju Udava <sivadstala@gmail.com>
pull/789/head
Raju Udava 3 years ago
parent
commit
56925246a0
  1. BIN
      scripts/cypress/fixtures/sampleFiles/sample.xlsx
  2. 207
      scripts/cypress/integration/common/7a_create_project_from_excel.js
  3. 5
      scripts/cypress/integration/test/restMisc.js
  4. 15
      scripts/cypress/plugins/index.js
  5. 10
      scripts/cypress/plugins/read-xlsx.js

BIN
scripts/cypress/fixtures/sampleFiles/sample.xlsx

Binary file not shown.

207
scripts/cypress/integration/common/7a_create_project_from_excel.js

@ -4,82 +4,52 @@
import { projectsPage } from "../../support/page_objects/navigation" import { projectsPage } from "../../support/page_objects/navigation"
import { mainPage } from "../../support/page_objects/mainPage" import { mainPage } from "../../support/page_objects/mainPage"
import { staticProjects, roles, isTestSuiteActive } from "../../support/page_objects/projectConstants" import { isTestSuiteActive } from "../../support/page_objects/projectConstants"
// import fs from "fs"
// if (typeof require !== 'undefined') XLSX = require('xlsx'); // stores sheet names (table name)
// let filepath = `sampleFiles/simple.xlsx` let sheetList
// let workbook // stores table data (read from excel)
let sheetData
// const getSheetList = (wb) => { let filepath = `sampleFiles/simple.xlsx`
// return wb.SheetNames let expectedData = {
// } 0: ['number', 'Number'],
1: ['float', 'Decimal'],
// const getRow = (sheet, rowIdx) => { 2: ['text', 'SingleLineText']
// 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) => { // let filepath = `sampleFiles/sample.xlsx`
// const worksheet = workbook.Sheets[sheet]; // let expectedData = {
// var desired_cell = worksheet[cellIdx]; // 0: ['number', 'Number'],
// desired_value = (desired_cell ? desired_cell.v : undefined); // 1: ['float', 'Decimal'],
// return desired_value // 2: ['text', 'SingleLineText']
// } // }
export const genTest = (type, xcdb) => { export const genTest = (type, xcdb) => {
if (!isTestSuiteActive(type, xcdb)) return; if (!isTestSuiteActive(type, xcdb)) return;
describe(`Import from excel`, () => { describe(`Import from excel`, () => {
it('Admin SignUp', () => { before(() => {
cy.waitForSpinners(); // cy.waitForSpinners()
cy.signinOrSignup(roles.owner.credentials) // cy.signinOrSignup(roles.owner.credentials)
cy.wait(2000) // cy.wait(2000)
})
it(``, () => {
// cy.readFile('simple.xlsx').then((content) => {
// workbook = XLSX.read(content)
// cy.log(workbook) cy.task('readSheetList', { file: `./scripts/cypress/fixtures/${filepath}` })
.then((rows) => {
// cy.log(getSheetList(workbook)) cy.log(rows)
// cy.log(getRow('Sheet2', 1)) sheetList = rows
// cy.log(getColumn('Sheet2', 'A')) })
// })
// cy.task('readXlsx', { file: 'simple.xlsx', sheet: "Sheet2" }).then((rows) => {
// cy.log(rows)
// // expect(rows.length).to.equal(543)
// // expect(rows[0]["column name"]).to.equal(11060)
// })
cy.task('readSheetList', { file: 'simple.xlsx' }).then((rows) => { cy.task('readXlsx', { file: `./scripts/cypress/fixtures/${filepath}`, sheet: "Sheet2" })
.then((rows) => {
cy.log(rows) cy.log(rows)
// expect(rows.length).to.equal(543) sheetData = rows
// expect(rows[0]["column name"]).to.equal(11060)
}) })
}) })
it.skip('Upload excel as template', () => { it('Upload excel as template', () => {
mainPage.toolBarTopLeft(mainPage.HOME).click() mainPage.toolBarTopLeft(mainPage.HOME).click()
@ -91,35 +61,132 @@ export const genTest = (type, xcdb) => {
cy.get('.nc-excel-import-input').attachFile(filepath) cy.get('.nc-excel-import-input').attachFile(filepath)
cy.get('.nc-btn-use-template', { timeout: 120000 }).should('exist') cy.get('.nc-btn-use-template', { timeout: 120000 }).should('exist')
})
it('Verify pre-load template page', () => {
cy.getActiveContentModal().find('.v-expansion-panel').then((sheets) => {
// validate pre-load template page for (let i = 0; i < sheets.length; i++) {
cy.getActiveContentModal().find('.v-expansion-panel').then((panel) => {
// cy.log(panel.length) // verify if all sheet names are correct
for (let i = 0; i < panel.length; i++) { cy.wrap(sheets[i]).find('.title').then((blk) => {
// cy.log(panel[i])
cy.wrap(panel[i]).find('.title').then((blk) => {
cy.log(blk.text().trim()) cy.log(blk.text().trim())
expect(blk.text().trim()).to.equal(sheetList[i])
}) })
cy.wrap(panel[i]).find('.mdi-chevron-down').click()
cy.wait(1000) // for each sheet, expand to verify table names & their data types
cy.wrap(sheets[i]).find('.mdi-chevron-down').click()
cy.wait(500)
cy.get('.v-data-table').find('tr:visible').then((row) => { cy.get('.v-data-table').find('tr:visible').then((row) => {
// cy.log(row)
for (let j = 2; j < row.length; j++) { for (let j = 1; j < row.length; j++) {
// column name to match input in excel
cy.wrap(row[j]).find('[placeholder="Column name"]').then((obj) => { cy.wrap(row[j]).find('[placeholder="Column name"]').then((obj) => {
cy.log(obj[0].value) cy.log(obj[0].value)
expect(obj[0].value).to.equal(expectedData[j-1][0])
}) })
// datatype to match expected output
cy.wrap(row[j]).find('span.caption').then((obj) => { cy.wrap(row[j]).find('span.caption').then((obj) => {
cy.log(obj[0].innerText) cy.log(obj[0].innerText)
expect(obj[0].innerText).to.equal(expectedData[j-1][1])
}) })
} }
}) })
cy.wrap(panel[i]).find('.mdi-chevron-down').click()
// unwind
cy.wrap(sheets[i]).find('.mdi-chevron-down').click()
} }
}) })
}) })
it('Verify loaded data', () => {
// create rest/ gql project
cy.get('.nc-btn-use-template', { timeout: 120000 }).click()
// if (type == 'rest') {
// cy.getActiveMenu().find('[role="menuitem"]').contains('REST').click()
// } else {
// cy.getActiveMenu().find('[role="menuitem"]').contains('GQL').click()
// }
// wait for loading to be completed
projectsPage.waitHomePageLoad()
// open sheet & validate contents
// sheetData contains data read from excel in format
// 0: { float: 1.1, number: 1, text: "abc" }
// 1: { float: 1.2, number: 0, text: "def" }
cy.openTableTab('Sheet2')
for (const [key, value] of Object.entries(expectedData)) {
mainPage.getCell(value[0], 1).contains(sheetData[0][value[0]]).should('exist')
mainPage.getCell(value[0], 2).contains(sheetData[1][value[0]]).should('exist')
}
cy.closeTableTab('Sheet2')
cy.openTableTab('Sheet3')
for (const [key, value] of Object.entries(expectedData)) {
mainPage.getCell(value[0], 1).contains(sheetData[0][value[0]]).should('exist')
mainPage.getCell(value[0], 2).contains(sheetData[1][value[0]]).should('exist')
}
cy.closeTableTab('Sheet3')
})
after(() => {
// delete project once all operations are completed
mainPage.toolBarTopLeft(mainPage.HOME).click()
cy.wait(1000)
cy.get(`.nc-${type}-project-row .mdi-delete-circle-outline`, { timeout: 10000 })
.last()
.invoke('show')
.click();
cy.contains('Submit')
.closest('button')
.click();
})
}) })
} }
// 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 * @copyright Copyright (c) 2021, Xgene Cloud Ltd
* *

5
scripts/cypress/integration/test/restMisc.js

@ -7,6 +7,7 @@ let t6d = require('../common/6d_language_validation')
let t6e = require('../common/6e_project_operations') let t6e = require('../common/6e_project_operations')
let t6f = require('../common/6f_attachments') let t6f = require('../common/6f_attachments')
let t6g = require('../common/6g_base_share') let t6g = require('../common/6g_base_share')
let t7a = require('../common/7a_create_project_from_excel')
// use 0 as mode to execute individual files (debug mode, skip pre-configs) // use 0 as mode to execute individual files (debug mode, skip pre-configs)
// use 1 mode if noco.db doesnt contain user credentials (full run over GIT) // use 1 mode if noco.db doesnt contain user credentials (full run over GIT)
@ -27,6 +28,10 @@ const nocoTestSuite = (type, xcdb) => {
t6g.genTest(type, xcdb) t6g.genTest(type, xcdb)
// **deletes created project, hence place it @ end // **deletes created project, hence place it @ end
t6e.genTest(type, xcdb) t6e.genTest(type, xcdb)
// intended to keep this after earlier project deletion
// creates project using excel & deletes it
t7a.genTest(type, xcdb)
} }
nocoTestSuite('rest', false) nocoTestSuite('rest', false)

15
scripts/cypress/plugins/index.js

@ -12,6 +12,10 @@
// This function is called when a project is opened or re-opened (e.g. due to // This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing) // the project's config changing)
const { rmdir } = require('fs') const { rmdir } = require('fs')
// https://stackoverflow.com/questions/61934443/read-excel-files-in-cypress
const readXlsx = require('./read-xlsx')
/** /**
* @type {Cypress.PluginConfig} * @type {Cypress.PluginConfig}
*/ */
@ -37,17 +41,8 @@ module.exports = (on, config) => {
}) })
}) })
}, },
})
}
// https://stackoverflow.com/questions/61934443/read-excel-files-in-cypress
const readXlsx = require('./read-xlsx')
module.exports = (on, config) => {
on('task', {
'readXlsx': readXlsx.read, 'readXlsx': readXlsx.read,
'readSheetList': readXlsx.sheetList 'readSheetList': readXlsx.sheetList,
}) })
} }

10
scripts/cypress/plugins/read-xlsx.js

@ -10,6 +10,16 @@ const read = ({file, sheet}) => {
return rows return rows
} }
// const read = ({file, sheet}) => {
// const buf = fs.readFileSync(file);
// const workbook = XLSX.read(buf, { type: 'buffer' });
// const rows = XLSX.utils.sheet_to_json(workbook.Sheets[sheet], {
// header: 1,
// blankrows: false
// });
// return rows
// }
const sheetList = ({file}) => { const sheetList = ({file}) => {
const buf = fs.readFileSync(file); const buf = fs.readFileSync(file);
const workbook = XLSX.read(buf, { type: 'buffer' }); const workbook = XLSX.read(buf, { type: 'buffer' });

Loading…
Cancel
Save