Browse Source

test(cypress): excel import using URL

Signed-off-by: Raju Udava <sivadstala@gmail.com>
pull/797/head
Raju Udava 3 years ago
parent
commit
005464ea1c
  1. 2
      packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js
  2. BIN
      scripts/cypress/fixtures/sampleFiles/Financial Sample.xlsx
  3. 16
      scripts/cypress/fixtures/sampleFiles/iFrame.html
  4. 151
      scripts/cypress/integration/common/7a_create_project_from_excel.js

2
packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js

@ -52,7 +52,7 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
for (let col = 0; col < rows[0].length; col++) {
let cn = (rows[0][col] ||
`field${col + 1}`).replace(/\./, '_')
`field${col + 1}`).replace(/\./, '_').trim()
if (cn in columnNamePrefixRef) {
cn = `${cn}${++columnNamePrefixRef[cn]}`

BIN
scripts/cypress/fixtures/sampleFiles/Financial Sample.xlsx

Binary file not shown.

16
scripts/cypress/fixtures/sampleFiles/iFrame.html

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<body>
<iframe
class="nc-embed"
src="http://localhost:3000/#/nc/base/7d4b551c-b5e0-41c9-a87b-f3984c21d2c7?embed"
frameborder="0"
width="100%"
height="700"
style="background: transparent; "></iframe>
</body>
</html>

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

@ -4,26 +4,60 @@
import { projectsPage } from "../../support/page_objects/navigation"
import { mainPage } from "../../support/page_objects/mainPage"
import { isTestSuiteActive } from "../../support/page_objects/projectConstants"
import { roles, isTestSuiteActive } from "../../support/page_objects/projectConstants"
// stores sheet names (table name)
let sheetList
// stores table data (read from excel)
let sheetData
//let UrlSheetData
let URL = 'https://go.microsoft.com/fwlink/?LinkID=521962'
let filepath = `sampleFiles/simple.xlsx`
// let UrlFilePath = `sampleFiles/Financial Sample.xlsx`
let expectedData = {
0: ['number', 'Number'],
1: ['float', 'Decimal'],
2: ['text', 'SingleLineText']
}
let UrlFileExpectedData = {
0: ['Segment', 'SingleSelect', ['Government']],
1: ['Country', 'SingleSelect', ['Canada']],
2: ['Product', 'SingleSelect', ['Carretera']],
3: ['Discount Band', 'SingleSelect', ['None']],
4: ['Units Sold', 'Decimal', [1618.5]],
5: ['Manufacturing Price', 'Number', [3]],
6: ['Sale Price', 'Number', [20]],
7: ['Gross Sales', 'Decimal', [32370]],
8: ['Discounts', 'Decimal', [0]],
9: ['Sales', 'Decimal', [32370]],
10: ['COGS', 'Decimal', [16185]],
11: ['Profit', 'Decimal', [16185]],
12: ['Date', 'Date', ['2014-01-01']],
13: ['Month Number', 'Number', [1]],
14: ['Month Name', 'SingleSelect', ['January']],
15: ['Year', 'SingleSelect', [2014]]
}
// let filepath = `sampleFiles/sample.xlsx`
// let expectedData = {
// 0: ['number', 'Number'],
// 1: ['float', 'Decimal'],
// 2: ['text', 'SingleLineText']
// 0: ['number', 'Number'],
// 1: ['float', 'Decimal'],
// 2: ['text', 'SingleLineText'],
// 3: ['boolean', 'Checkbox'],
// 4: ['currency', 'Currency'],
// 5: ['date', 'Date'],
// 6: ['field7', 'SingleLineText'],
// 7: ['multi line', 'LongText'],
// 8: ['multi select', 'MultiSelect'],
// 9: ['field10', 'SingleLineText'],
// 10: ['formula', 'Decimal'],
// 11: ['percentage', 'Decimal'],
// 12: ['dateTime', 'DateTime']
// }
export const genTest = (type, xcdb) => {
@ -46,10 +80,16 @@ export const genTest = (type, xcdb) => {
.then((rows) => {
cy.log(rows)
sheetData = rows
})
})
// cy.task('readXlsx', { file: `./scripts/cypress/fixtures/${UrlFilePath}`, sheet: "Sheet1" })
// .then((rows) => {
// cy.log(rows)
// UrlSheetData = rows
// })
})
it('Upload excel as template', () => {
it('File Upload: Upload excel as template', () => {
mainPage.toolBarTopLeft(mainPage.HOME).click()
@ -63,7 +103,7 @@ export const genTest = (type, xcdb) => {
cy.get('.nc-btn-use-template', { timeout: 120000 }).should('exist')
})
it('Verify pre-load template page', () => {
it('File Upload: Verify pre-load template page', () => {
cy.getActiveContentModal().find('.v-expansion-panel').then((sheets) => {
@ -77,7 +117,7 @@ export const genTest = (type, xcdb) => {
// for each sheet, expand to verify table names & their data types
cy.wrap(sheets[i]).find('.mdi-chevron-down').click()
cy.wait(500)
cy.wait(1000)
cy.get('.v-data-table').find('tr:visible').then((row) => {
for (let j = 1; j < row.length; j++) {
@ -102,7 +142,7 @@ export const genTest = (type, xcdb) => {
})
})
it('Verify loaded data', () => {
it('File Upload: Verify loaded data', () => {
// create rest/ gql project
cy.get('.nc-btn-use-template', { timeout: 120000 }).click()
@ -123,7 +163,7 @@ export const genTest = (type, xcdb) => {
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')
mainPage.getCell(value[0], 2).contains(sheetData[1][value[0]]).should('exist')
}
cy.closeTableTab('Sheet2')
@ -133,7 +173,98 @@ export const genTest = (type, xcdb) => {
mainPage.getCell(value[0], 2).contains(sheetData[1][value[0]]).should('exist')
}
cy.closeTableTab('Sheet3')
// 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();
})
it('URL: Upload excel as template', () => {
// click on "New Project"
cy.get(':nth-child(5) > .v-btn', { timeout: 20000 }).click()
// Subsequent form, select (+ Create) option
cy.get('.nc-create-project-from-excel', { timeout: 20000 }).click({ force: true })
cy.getActiveModal().find('.caption').contains('URL').click()
cy.get('.nc-excel-import-tab-item').find('input[type="url"]').click().type(URL)
cy.get('.nc-excel-import-tab-item').find('button').contains('Load').click()
cy.get('.nc-btn-use-template', { timeout: 120000 }).should('exist')
})
it('URL: Verify pre-load template page', () => {
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('Sheet1')
})
// for each sheet, expand to verify table names & their data types
cy.wrap(sheets[i]).find('.mdi-chevron-down').click()
cy.wait(3000).then(() => {
cy.get('.v-data-table').find('tr:visible').then((row) => {
// verification restricting to 10, as others need to be scrolled back into view
for (let j = 1; j <= 10/*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(UrlFileExpectedData[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(UrlFileExpectedData[j-1][1])
})
}
})
})
// unwind
cy.wrap(sheets[i]).find('.mdi-chevron-down').click()
}
})
})
it('URL: Verify loaded data', () => {
// create rest/ gql project
cy.get('.nc-btn-use-template', { timeout: 120000 }).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('Sheet1')
let idx = 0
for (const [key, value] of Object.entries(UrlFileExpectedData)) {
if(UrlFileExpectedData[idx][1] != 'Date')
mainPage.getCell(value[0], 1).contains(UrlFileExpectedData[idx++][2][0]).should('exist')
}
cy.closeTableTab('Sheet1')
})
after(() => {
// delete project once all operations are completed

Loading…
Cancel
Save