diff --git a/packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js b/packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js index 326b46f9fa..7d978a7a19 100644 --- a/packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js +++ b/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]}` diff --git a/scripts/cypress/fixtures/sampleFiles/Financial Sample.xlsx b/scripts/cypress/fixtures/sampleFiles/Financial Sample.xlsx new file mode 100644 index 0000000000..f049f345b8 Binary files /dev/null and b/scripts/cypress/fixtures/sampleFiles/Financial Sample.xlsx differ diff --git a/scripts/cypress/fixtures/sampleFiles/iFrame.html b/scripts/cypress/fixtures/sampleFiles/iFrame.html new file mode 100644 index 0000000000..e5bf5edc11 --- /dev/null +++ b/scripts/cypress/fixtures/sampleFiles/iFrame.html @@ -0,0 +1,16 @@ + + + +
+ + + + + + \ No newline at end of file diff --git a/scripts/cypress/integration/common/7a_create_project_from_excel.js b/scripts/cypress/integration/common/7a_create_project_from_excel.js index 335d1dbd3e..53eb7b026b 100644 --- a/scripts/cypress/integration/common/7a_create_project_from_excel.js +++ b/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