From 65fa0b3ef0a794b6434488af9bab847a1081ae24 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Fri, 23 Jun 2023 12:56:18 +0530 Subject: [PATCH] test: bulk update- select based Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- .../pages/Dashboard/BulkUpdate/index.ts | 12 +++ .../Dashboard/common/Cell/SelectOptionCell.ts | 2 +- tests/playwright/tests/db/bulkUpdate.spec.ts | 83 +++++++++++++++++-- 3 files changed, 90 insertions(+), 7 deletions(-) diff --git a/tests/playwright/pages/Dashboard/BulkUpdate/index.ts b/tests/playwright/pages/Dashboard/BulkUpdate/index.ts index b1de9e24a8..bf8d6e6eab 100644 --- a/tests/playwright/pages/Dashboard/BulkUpdate/index.ts +++ b/tests/playwright/pages/Dashboard/BulkUpdate/index.ts @@ -118,6 +118,18 @@ export class BulkUpdatePage extends BasePage { await timePanel.nth(1).locator('li').nth(+time[1]).click(); await picker.locator('.ant-picker-ok').click(); break; + case 'singleSelect': + picker = this.rootPage.locator('.ant-select-dropdown.active'); + await picker.waitFor(); + await picker.locator(`.nc-select-option-SingleSelect-${value}`).click(); + break; + case 'multiSelect': + picker = this.rootPage.locator('.ant-select-dropdown.active'); + await picker.waitFor(); + for (const val of value.split(',')) { + await picker.locator(`.nc-select-option-MultiSelect-${val}`).click(); + } + break; } } diff --git a/tests/playwright/pages/Dashboard/common/Cell/SelectOptionCell.ts b/tests/playwright/pages/Dashboard/common/Cell/SelectOptionCell.ts index eb94373ce0..f4dc982ed1 100644 --- a/tests/playwright/pages/Dashboard/common/Cell/SelectOptionCell.ts +++ b/tests/playwright/pages/Dashboard/common/Cell/SelectOptionCell.ts @@ -126,7 +126,7 @@ export class SelectOptionCellPageObject extends BasePage { await expect(this.rootPage.locator(`div.ant-select-item-option`).nth(counter)).toHaveText(option); counter++; } - await this.get({ index, columnHeader }).click(); + await this.rootPage.keyboard.press('Escape'); await this.rootPage.locator(`.nc-dropdown-single-select-cell`).nth(index).waitFor({ state: 'hidden' }); } diff --git a/tests/playwright/tests/db/bulkUpdate.spec.ts b/tests/playwright/tests/db/bulkUpdate.spec.ts index 029b74c78f..4a773a5804 100644 --- a/tests/playwright/tests/db/bulkUpdate.spec.ts +++ b/tests/playwright/tests/db/bulkUpdate.spec.ts @@ -10,7 +10,6 @@ test.describe('Bulk update', () => { let bulkUpdateForm: BulkUpdatePage; let context: any; let api: Api; - let records: any[]; let table; test.beforeEach(async ({ page }) => { @@ -26,7 +25,6 @@ test.describe('Bulk update', () => { }); table = await createDemoTable({ context, type: 'textBased', recordCnt: 50 }); - records = (await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 50 })).list; await page.reload(); await dashboard.closeTab({ title: 'Team & Auth' }); @@ -102,7 +100,7 @@ test.describe('Bulk update', () => { // verify api response const updatedRecords = (await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 50 })).list; - for (let i = 0; i < records.length; i++) { + for (let i = 0; i < updatedRecords.length; i++) { for (let j = 0; j < fields.length; j++) { expect(updatedRecords[i][fields[j]]).toEqual(fieldsFillText[j]); } @@ -115,7 +113,6 @@ test.describe('Bulk update - Number based', () => { let bulkUpdateForm: BulkUpdatePage; let context: any; let api: Api; - let records: any[]; let table; test.beforeEach(async ({ page }) => { @@ -131,7 +128,6 @@ test.describe('Bulk update - Number based', () => { }); table = await createDemoTable({ context, type: 'numberBased', recordCnt: 50 }); - records = (await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 50 })).list; await page.reload(); await dashboard.closeTab({ title: 'Team & Auth' }); @@ -176,7 +172,7 @@ test.describe('Bulk update - Number based', () => { // duration in seconds const APIResponse = [1, 1.1, 1.1, 10, 60000, 3, 2024, '10:10:00']; const updatedRecords = (await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 50 })).list; - for (let i = 0; i < records.length; i++) { + for (let i = 0; i < updatedRecords.length; i++) { for (let j = 0; j < fields.length; j++) { if (fields[j] === 'Time') { expect(updatedRecords[i][fields[j]]).toContain(APIResponse[j]); @@ -187,3 +183,78 @@ test.describe('Bulk update - Number based', () => { } }); }); + +test.describe('Bulk update - Select based', () => { + let dashboard: DashboardPage; + let bulkUpdateForm: BulkUpdatePage; + let context: any; + let api: Api; + let table; + + test.beforeEach(async ({ page }) => { + context = await setup({ page, isEmptyProject: true }); + dashboard = new DashboardPage(page, context.project); + bulkUpdateForm = dashboard.bulkUpdateForm; + + api = new Api({ + baseURL: `http://localhost:8080/`, + headers: { + 'xc-auth': context.token, + }, + }); + + table = await createDemoTable({ context, type: 'selectBased', recordCnt: 50 }); + await page.reload(); + + await dashboard.closeTab({ title: 'Team & Auth' }); + await dashboard.treeView.openTable({ title: 'selectBased' }); + + // Open bulk update form + await dashboard.grid.updateAll(); + }); + + test('Select based', async () => { + const fields = ['SingleSelect', 'MultiSelect']; + const fieldsFillText = ['jan', 'jan,feb,mar']; + const fieldsFillType = ['singleSelect', 'multiSelect']; + + // move all fields to active + for (let i = 0; i < fields.length; i++) { + await bulkUpdateForm.addField(0); + } + + // fill all fields + for (let i = 0; i < fields.length; i++) { + await bulkUpdateForm.fillField({ columnTitle: fields[i], value: fieldsFillText[i], type: fieldsFillType[i] }); + } + + // save form + await bulkUpdateForm.save({ awaitResponse: true }); + + // verify data on grid + const displayOptions = ['jan', 'feb', 'mar']; + for (let i = 0; i < fields.length; i++) { + if (fieldsFillType[i] === 'singleSelect') { + await dashboard.grid.cell.selectOption.verify({ + index: 5, + columnHeader: fields[i], + option: fieldsFillText[i], + }); + } else { + await dashboard.grid.cell.selectOption.verifyOptions({ + index: 5, + columnHeader: fields[i], + options: displayOptions, + }); + } + } + + // verify api response + const updatedRecords = (await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 50 })).list; + for (let i = 0; i < updatedRecords.length; i++) { + for (let j = 0; j < fields.length; j++) { + expect(updatedRecords[i][fields[j]]).toContain(fieldsFillText[j]); + } + } + }); +});