|
|
|
@ -4,82 +4,52 @@
|
|
|
|
|
|
|
|
|
|
import { projectsPage } from "../../support/page_objects/navigation" |
|
|
|
|
import { mainPage } from "../../support/page_objects/mainPage" |
|
|
|
|
import { staticProjects, roles, isTestSuiteActive } from "../../support/page_objects/projectConstants" |
|
|
|
|
// import fs from "fs"
|
|
|
|
|
import { isTestSuiteActive } from "../../support/page_objects/projectConstants" |
|
|
|
|
|
|
|
|
|
// if (typeof require !== 'undefined') XLSX = require('xlsx');
|
|
|
|
|
// let filepath = `sampleFiles/simple.xlsx`
|
|
|
|
|
// stores sheet names (table name)
|
|
|
|
|
let sheetList |
|
|
|
|
|
|
|
|
|
// let workbook
|
|
|
|
|
// stores table data (read from excel)
|
|
|
|
|
let sheetData |
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
// }
|
|
|
|
|
let filepath = `sampleFiles/simple.xlsx` |
|
|
|
|
let expectedData = { |
|
|
|
|
0: ['number', 'Number'], |
|
|
|
|
1: ['float', 'Decimal'], |
|
|
|
|
2: ['text', 'SingleLineText'] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
// let filepath = `sampleFiles/sample.xlsx`
|
|
|
|
|
// let expectedData = {
|
|
|
|
|
// 0: ['number', 'Number'],
|
|
|
|
|
// 1: ['float', 'Decimal'],
|
|
|
|
|
// 2: ['text', 'SingleLineText']
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const genTest = (type, xcdb) => { |
|
|
|
|
if (!isTestSuiteActive(type, xcdb)) return; |
|
|
|
|
|
|
|
|
|
describe(`Import from excel`, () => { |
|
|
|
|
|
|
|
|
|
it('Admin SignUp', () => { |
|
|
|
|
cy.waitForSpinners(); |
|
|
|
|
cy.signinOrSignup(roles.owner.credentials) |
|
|
|
|
cy.wait(2000)
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it(``, () => { |
|
|
|
|
// cy.readFile('simple.xlsx').then((content) => {
|
|
|
|
|
// workbook = XLSX.read(content)
|
|
|
|
|
|
|
|
|
|
// cy.log(workbook)
|
|
|
|
|
before(() => { |
|
|
|
|
// cy.waitForSpinners()
|
|
|
|
|
// cy.signinOrSignup(roles.owner.credentials)
|
|
|
|
|
// cy.wait(2000)
|
|
|
|
|
|
|
|
|
|
// cy.log(getSheetList(workbook))
|
|
|
|
|
// cy.log(getRow('Sheet2', 1))
|
|
|
|
|
// 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: `./scripts/cypress/fixtures/${filepath}` }) |
|
|
|
|
.then((rows) => { |
|
|
|
|
cy.log(rows) |
|
|
|
|
sheetList = rows |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
cy.task('readSheetList', { file: 'simple.xlsx' }).then((rows) => { |
|
|
|
|
cy.task('readXlsx', { file: `./scripts/cypress/fixtures/${filepath}`, sheet: "Sheet2" }) |
|
|
|
|
.then((rows) => { |
|
|
|
|
cy.log(rows) |
|
|
|
|
// expect(rows.length).to.equal(543)
|
|
|
|
|
// expect(rows[0]["column name"]).to.equal(11060)
|
|
|
|
|
sheetData = rows |
|
|
|
|
})
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it.skip('Upload excel as template', () => { |
|
|
|
|
it('Upload excel as template', () => { |
|
|
|
|
|
|
|
|
|
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-btn-use-template', { timeout: 120000 }).should('exist') |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
it('Verify pre-load template page', () => { |
|
|
|
|
|
|
|
|
|
// validate pre-load template page
|
|
|
|
|
cy.getActiveContentModal().find('.v-expansion-panel').then((panel) => { |
|
|
|
|
// cy.log(panel.length)
|
|
|
|
|
for (let i = 0; i < panel.length; i++) { |
|
|
|
|
// cy.log(panel[i])
|
|
|
|
|
cy.wrap(panel[i]).find('.title').then((blk) => { |
|
|
|
|
cy.getActiveContentModal().find('.v-expansion-panel').then((sheets) => { |
|
|
|
|
|
|
|
|
|
for (let i = 0; i < sheets.length; i++) { |
|
|
|
|
|
|
|
|
|
// verify if all sheet names are correct
|
|
|
|
|
cy.wrap(sheets[i]).find('.title').then((blk) => { |
|
|
|
|
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.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.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.log(obj[0].innerText) |
|
|
|
|
expect(obj[0].innerText).to.equal(expectedData[j-1][1]) |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// unwind
|
|
|
|
|
cy.wrap(sheets[i]).find('.mdi-chevron-down').click() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
cy.wrap(panel[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 |
|
|
|
|
* |
|
|
|
|