From 30e79b1a28dc777cc777fafafc5022e8f7803f81 Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Fri, 3 May 2024 06:45:40 +0000 Subject: [PATCH] test: fix single select record insert using api --- tests/playwright/setup/index.ts | 4 ++- .../db/columns/columnMultiSelect.spec.ts | 16 ++-------- .../db/columns/columnSingleSelect.spec.ts | 32 ++++++++++++++++--- .../tests/db/columns/columnUserSelect.spec.ts | 8 +---- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/tests/playwright/setup/index.ts b/tests/playwright/setup/index.ts index 0b96820a16..f67022df7b 100644 --- a/tests/playwright/setup/index.ts +++ b/tests/playwright/setup/index.ts @@ -155,6 +155,7 @@ export interface NcContext { workspace: WorkspaceType; defaultProjectTitle: string; defaultTableTitle: string; + api: Api; } selectors.setTestIdAttribute('data-testid'); @@ -344,7 +345,7 @@ async function localInit({ // get current user information const user = await api.auth.me(); - return { data: { base, user, workspace, token }, status: 200 }; + return { data: { base, user, workspace, token, api }, status: 200 }; } catch (e) { console.error(`Error resetting base: ${process.env.TEST_PARALLEL_INDEX}`, e); return { data: {}, status: 500 }; @@ -477,6 +478,7 @@ const setup = async ({ workspace, defaultProjectTitle: 'Getting Started', defaultTableTitle: 'Features', + api: response?.data?.api, } as NcContext; }; diff --git a/tests/playwright/tests/db/columns/columnMultiSelect.spec.ts b/tests/playwright/tests/db/columns/columnMultiSelect.spec.ts index bb9c764bd7..1b81f11289 100644 --- a/tests/playwright/tests/db/columns/columnMultiSelect.spec.ts +++ b/tests/playwright/tests/db/columns/columnMultiSelect.spec.ts @@ -31,23 +31,11 @@ test.describe('Multi select', () => { options: ['Option 1', 'Option 2'], }); - api = new Api({ - baseURL: `http://localhost:8080/`, - headers: { - 'xc-auth': context.token, - }, - }); + api = context.api; const tables = await api.dbTable.list(context.base.id); tableId = tables.list.find((table: any) => table.title === 'sheet1').id; - await addRecordUsingAPI(context, tableId, [ - { - Id: 1, - Title: `Row 0`, - }, - ]); - - // page reload + await addRecordUsingAPI(context, tableId, [{ Id: 1, Title: `Row 0` }]); await page.reload(); }); diff --git a/tests/playwright/tests/db/columns/columnSingleSelect.spec.ts b/tests/playwright/tests/db/columns/columnSingleSelect.spec.ts index 74df46ddcc..ff9de479dc 100644 --- a/tests/playwright/tests/db/columns/columnSingleSelect.spec.ts +++ b/tests/playwright/tests/db/columns/columnSingleSelect.spec.ts @@ -3,15 +3,19 @@ import { DashboardPage } from '../../../pages/Dashboard'; import { GridPage } from '../../../pages/Dashboard/Grid'; import setup, { unsetup } from '../../../setup'; import { ToolbarPage } from '../../../pages/Dashboard/common/Toolbar'; +import { Api } from 'nocodb-sdk'; test.describe('Single select', () => { let dashboard: DashboardPage, grid: GridPage; let context: any; + let api: Api; + let tableId: string; test.beforeEach(async ({ page }) => { context = await setup({ page, isEmptyProject: true }); dashboard = new DashboardPage(page, context.base); grid = dashboard.grid; + api = context.api; await dashboard.treeView.createTable({ title: 'sheet1', baseTitle: context.base.title }); @@ -20,7 +24,11 @@ test.describe('Single select', () => { columnTitle: 'SingleSelect', options: ['Option 1', 'Option 2'], }); - await grid.addNewRow({ index: 0, value: 'Row 0' }); + + const tables = await api.dbTable.list(context.base.id); + tableId = tables.list.find((table: any) => table.title === 'sheet1').id; + await api.dbTableRow.bulkCreate('noco', context.base.id, tableId, [{ Id: 1, Title: `Row 0` }]); + await page.reload(); }); test.afterEach(async () => { @@ -120,12 +128,15 @@ test.describe('Single select - filter & sort', () => { let dashboard: DashboardPage, grid: GridPage, toolbar: ToolbarPage; let context: any; + let api: Api; + let tableId: string; test.beforeEach(async ({ page }) => { context = await setup({ page }); dashboard = new DashboardPage(page, context.base); toolbar = dashboard.grid.toolbar; grid = dashboard.grid; + api = context.api; await dashboard.treeView.createTable({ title: 'sheet1', baseTitle: context.base.title }); @@ -134,10 +145,21 @@ test.describe('Single select - filter & sort', () => { columnTitle: 'SingleSelect', options: ['foo', 'bar', 'baz'], }); - await grid.addNewRow({ index: 0, value: '1' }); - await grid.addNewRow({ index: 1, value: '2' }); - await grid.addNewRow({ index: 2, value: '3' }); - await grid.addNewRow({ index: 3, value: '4' }); + + const tables = await api.dbTable.list(context.base.id); + tableId = tables.list.find((table: any) => table.title === 'sheet1').id; + await api.dbTableRow.bulkCreate('noco', context.base.id, tableId, [ + { Id: 1, Title: '1' }, + { Id: 2, Title: '2' }, + { Id: 3, Title: '3' }, + { Id: 4, Title: '4' }, + ]); + await page.reload(); + + // await grid.addNewRow({ index: 0, value: '1' }); + // await grid.addNewRow({ index: 1, value: '2' }); + // await grid.addNewRow({ index: 2, value: '3' }); + // await grid.addNewRow({ index: 3, value: '4' }); await grid.cell.selectOption.select({ index: 1, columnHeader: 'SingleSelect', option: 'foo', multiSelect: false }); await grid.cell.selectOption.select({ index: 2, columnHeader: 'SingleSelect', option: 'bar', multiSelect: false }); diff --git a/tests/playwright/tests/db/columns/columnUserSelect.spec.ts b/tests/playwright/tests/db/columns/columnUserSelect.spec.ts index c59ddf0e49..c8ed51fa42 100644 --- a/tests/playwright/tests/db/columns/columnUserSelect.spec.ts +++ b/tests/playwright/tests/db/columns/columnUserSelect.spec.ts @@ -33,13 +33,7 @@ async function beforeEachInit({ page }: { page: any }) { if (isEE()) { workspacePage = new WorkspacePage(page); collaborationPage = workspacePage.collaboration; - - api = new Api({ - baseURL: `http://localhost:8080/`, - headers: { - 'xc-auth': context.token, - }, - }); + api = context.api; for (let i = 0; i < roleDb.length; i++) { try {