From 9cad5bd0b488c2579ce3afcf01d7a239a9064c9d Mon Sep 17 00:00:00 2001 From: Raju Udava <86527202+dstala@users.noreply.github.com> Date: Tue, 7 Feb 2023 20:23:21 +0530 Subject: [PATCH] test: filters for checkbox Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com> --- tests/playwright/setup/xcdb-records.ts | 4 ++ tests/playwright/tests/filters.spec.ts | 81 ++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/tests/playwright/setup/xcdb-records.ts b/tests/playwright/setup/xcdb-records.ts index d43aa958b0..4edd3df393 100644 --- a/tests/playwright/setup/xcdb-records.ts +++ b/tests/playwright/setup/xcdb-records.ts @@ -96,7 +96,11 @@ const rowMixedValue = (column: ColumnType, index: number) => { const multiSelect = ['jan,feb,mar', 'apr,may,jun', 'jul,aug,sep', 'oct,nov,dec', 'jan,feb,mar', null]; + const checkbox = [true, false, false, true, false, true, false, false, true, true]; + switch (column.uidt) { + case UITypes.Checkbox: + return checkbox[index % checkbox.length]; case UITypes.Number: case UITypes.Percent: return numbers[index % numbers.length]; diff --git a/tests/playwright/tests/filters.spec.ts b/tests/playwright/tests/filters.spec.ts index e807e12306..c085f1f6aa 100644 --- a/tests/playwright/tests/filters.spec.ts +++ b/tests/playwright/tests/filters.spec.ts @@ -572,3 +572,84 @@ test.describe('Filter Tests: Select based', () => { await selectBasedFilterTest('MultiSelect', '', 'jan,feb,mar', 'jan,feb,mar'); }); }); + +test.describe('Filter Tests: AddOn', () => { + async function addOnFilterTest(dataType) { + await dashboard.closeTab({ title: 'Team & Auth' }); + await dashboard.treeView.openTable({ title: 'addOnTypes' }); + + const filterList = [ + { + op: 'is checked', + value: null, + rowCount: records.list.filter(r => r[dataType] === 1).length, + }, + { + op: 'is not checked', + value: null, + rowCount: records.list.filter(r => r[dataType] !== 1).length, + }, + ]; + + for (let i = 0; i < filterList.length; i++) { + await verifyFilter({ + column: dataType, + opType: filterList[i].op, + value: filterList[i].value, + result: { rowCount: filterList[i].rowCount }, + dataType: dataType, + }); + } + } + test.beforeEach(async ({ page }) => { + context = await setup({ page }); + dashboard = new DashboardPage(page, context.project); + toolbar = dashboard.grid.toolbar; + + api = new Api({ + baseURL: `http://localhost:8080/`, + headers: { + 'xc-auth': context.token, + }, + }); + + const columns = [ + { + column_name: 'Id', + title: 'Id', + uidt: UITypes.ID, + }, + { + column_name: 'Checkbox', + title: 'Checkbox', + uidt: UITypes.Checkbox, + }, + ]; + + try { + const project = await api.project.read(context.project.id); + const table = await api.base.tableCreate(context.project.id, project.bases?.[0].id, { + table_name: 'addOnTypes', + title: 'addOnTypes', + columns: columns, + }); + + const rowAttributes = []; + for (let i = 0; i < 400; i++) { + const row = { + Checkbox: rowMixedValue(columns[1], i), + }; + rowAttributes.push(row); + } + + await api.dbTableRow.bulkCreate('noco', context.project.id, table.id, rowAttributes); + records = await api.dbTableRow.list('noco', context.project.id, table.id, { limit: 400 }); + } catch (e) { + console.error(e); + } + }); + + test('Filter: Checkbox', async () => { + await addOnFilterTest('Checkbox'); + }); +});