Browse Source

test: bulk update- number based

Signed-off-by: Raju Udava <86527202+dstala@users.noreply.github.com>
test/pw-duplicate-check
Raju Udava 1 year ago
parent
commit
55eb5029ae
  1. 23
      tests/playwright/pages/Dashboard/BulkUpdate/index.ts
  2. 23
      tests/playwright/pages/Dashboard/common/Cell/TimeCell.ts
  3. 23
      tests/playwright/pages/Dashboard/common/Cell/YearCell.ts
  4. 6
      tests/playwright/pages/Dashboard/common/Cell/index.ts
  5. 130
      tests/playwright/tests/db/bulkUpdate.spec.ts

23
tests/playwright/pages/Dashboard/BulkUpdate/index.ts

@ -83,6 +83,7 @@ export class BulkUpdatePage extends BasePage {
//////////////////////////////////////////////////////////////////////////////
async fillField({ columnTitle, value, type = 'text' }: { columnTitle: string; value: string; type?: string }) {
let picker = null;
const field = this.form.locator(`[data-testid="nc-form-input-${columnTitle}"]`);
await field.hover();
await field.click();
@ -95,6 +96,28 @@ export class BulkUpdatePage extends BasePage {
await field.locator('textarea').waitFor();
await field.locator('textarea').fill(value);
break;
case 'rating':
await field
.locator('.ant-rate-star')
.nth(Number(value) - 1)
.click();
break;
case 'year':
picker = this.rootPage.locator('.ant-picker-dropdown.active');
await picker.waitFor();
await picker.locator(`td[title="${value}"]`).click();
break;
case 'time':
picker = this.rootPage.locator('.ant-picker-dropdown.active');
await picker.waitFor();
// eslint-disable-next-line no-case-declarations
const time = value.split(':');
// eslint-disable-next-line no-case-declarations
const timePanel = picker.locator('.ant-picker-time-panel-column');
await timePanel.nth(0).locator('li').nth(+time[0]).click();
await timePanel.nth(1).locator('li').nth(+time[1]).click();
await picker.locator('.ant-picker-ok').click();
break;
}
}

23
tests/playwright/pages/Dashboard/common/Cell/TimeCell.ts

@ -0,0 +1,23 @@
import { CellPageObject } from '.';
import BasePage from '../../../Base';
import { expect } from '@playwright/test';
export class TimeCellPageObject extends BasePage {
readonly cell: CellPageObject;
constructor(cell: CellPageObject) {
super(cell.rootPage);
this.cell = cell;
}
get({ index, columnHeader }: { index?: number; columnHeader: string }) {
return this.cell.get({ index, columnHeader });
}
async verify({ index, columnHeader, value }: { index: number; columnHeader: string; value: string }) {
const cell = await this.get({ index, columnHeader });
await cell.scrollIntoViewIfNeeded();
await cell.locator(`input[title="${value}"]`).waitFor({ state: 'visible' });
await expect(cell.locator(`[title="${value}"]`)).toBeVisible();
}
}

23
tests/playwright/pages/Dashboard/common/Cell/YearCell.ts

@ -0,0 +1,23 @@
import { CellPageObject } from '.';
import BasePage from '../../../Base';
import { expect } from '@playwright/test';
export class YearCellPageObject extends BasePage {
readonly cell: CellPageObject;
constructor(cell: CellPageObject) {
super(cell.rootPage);
this.cell = cell;
}
get({ index, columnHeader }: { index?: number; columnHeader: string }) {
return this.cell.get({ index, columnHeader });
}
async verify({ index, columnHeader, value }: { index: number; columnHeader: string; value: number }) {
const cell = await this.get({ index, columnHeader });
await cell.scrollIntoViewIfNeeded();
await cell.locator(`input[title="${value}"]`).waitFor({ state: 'visible' });
await expect(cell.locator(`[title="${value}"]`)).toBeVisible();
}
}

6
tests/playwright/pages/Dashboard/common/Cell/index.ts

@ -9,6 +9,8 @@ import { RatingCellPageObject } from './RatingCell';
import { DateCellPageObject } from './DateCell';
import { DateTimeCellPageObject } from './DateTimeCell';
import { GeoDataCellPageObject } from './GeoDataCell';
import { YearCellPageObject } from './YearCell';
import { TimeCellPageObject } from './TimeCell';
export interface CellProps {
index?: number;
@ -21,6 +23,8 @@ export class CellPageObject extends BasePage {
readonly attachment: AttachmentCellPageObject;
readonly checkbox: CheckboxCellPageObject;
readonly rating: RatingCellPageObject;
readonly year: YearCellPageObject;
readonly time: TimeCellPageObject;
readonly geoData: GeoDataCellPageObject;
readonly date: DateCellPageObject;
readonly dateTime: DateTimeCellPageObject;
@ -32,6 +36,8 @@ export class CellPageObject extends BasePage {
this.attachment = new AttachmentCellPageObject(this);
this.checkbox = new CheckboxCellPageObject(this);
this.rating = new RatingCellPageObject(this);
this.year = new YearCellPageObject(this);
this.time = new TimeCellPageObject(this);
this.geoData = new GeoDataCellPageObject(this);
this.date = new DateCellPageObject(this);
this.dateTime = new DateTimeCellPageObject(this);

130
tests/playwright/tests/db/bulkUpdate.spec.ts

@ -76,42 +76,114 @@ test.describe('Bulk update', () => {
});
test('Text based', async () => {
await bulkUpdateForm.addField(0);
await bulkUpdateForm.addField(0);
await bulkUpdateForm.addField(0);
await bulkUpdateForm.addField(0);
await bulkUpdateForm.addField(0);
const fields = ['SingleLineText', 'Email', 'PhoneNumber', 'URL', 'MultiLineText'];
const longText =
'Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. ';
const fieldsFillText = ['SingleLineText', 'a@b.com', '987654321', 'https://www.google.com', longText];
const fieldsFillType = ['text', 'text', 'text', 'text', 'longText'];
// move all fields to active
for (let i = 0; i < fields.length; i++) {
await bulkUpdateForm.addField(0);
}
await bulkUpdateForm.fillField({ columnTitle: 'SingleLineText', value: 'SingleLineText', type: 'text' });
await bulkUpdateForm.fillField({ columnTitle: 'Email', value: 'a@b.com', type: 'text' });
await bulkUpdateForm.fillField({ columnTitle: 'PhoneNumber', value: '987654321', type: 'text' });
await bulkUpdateForm.fillField({ columnTitle: 'URL', value: 'htps://www.google.com', type: 'text' });
await bulkUpdateForm.fillField({
columnTitle: 'MultiLineText',
value: 'Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. ',
type: 'longText',
});
// 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 });
await dashboard.grid.cell.verify({ index: 5, columnHeader: 'SingleLineText', value: 'SingleLineText' });
await dashboard.grid.cell.verify({ index: 5, columnHeader: 'Email', value: 'a@b.com' });
await dashboard.grid.cell.verify({ index: 5, columnHeader: 'PhoneNumber', value: '987654321' });
await dashboard.grid.cell.verify({ index: 5, columnHeader: 'URL', value: 'htps://www.google.com' });
await dashboard.grid.cell.verify({
index: 5,
columnHeader: 'MultiLineText',
value: 'Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. ',
// verify data on grid
for (let i = 0; i < fields.length; i++) {
await dashboard.grid.cell.verify({ index: 5, columnHeader: fields[i], value: fieldsFillText[i] });
}
// 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 j = 0; j < fields.length; j++) {
expect(updatedRecords[i][fields[j]]).toEqual(fieldsFillText[j]);
}
}
});
});
test.describe('Bulk update - Number based', () => {
let dashboard: DashboardPage;
let bulkUpdateForm: BulkUpdatePage;
let context: any;
let api: Api<any>;
let records: any[];
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: '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' });
await dashboard.treeView.openTable({ title: 'numberBased' });
// Open bulk update form
await dashboard.grid.updateAll();
});
test('Number based', async () => {
const fields = ['Number', 'Decimal', 'Currency', 'Percent', 'Duration', 'Rating', 'Year', 'Time'];
const fieldsFillText = ['1', '1.1', '1.1', '10', '16:40', '3', '2024', '10:10'];
const fieldsFillType = ['text', 'text', 'text', 'text', 'text', 'rating', 'year', 'time'];
// 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
for (let i = 0; i < fields.length; i++) {
if (fieldsFillType[i] === 'rating') {
await dashboard.grid.cell.rating.verify({ index: 5, columnHeader: fields[i], rating: +fieldsFillText[i] });
} else if (fieldsFillType[i] === 'year') {
await dashboard.grid.cell.year.verify({ index: 5, columnHeader: fields[i], value: +fieldsFillText[i] });
} else if (fieldsFillType[i] === 'time') {
await dashboard.grid.cell.time.verify({ index: 5, columnHeader: fields[i], value: fieldsFillText[i] });
} else {
await dashboard.grid.cell.verify({ index: 5, columnHeader: fields[i], value: fieldsFillText[i] });
}
}
// verify api response
// 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++) {
expect(updatedRecords[i].SingleLineText).toEqual('SingleLineText');
expect(updatedRecords[i].Email).toEqual('a@b.com');
expect(updatedRecords[i].PhoneNumber).toEqual('987654321');
expect(updatedRecords[i].URL).toEqual('htps://www.google.com');
expect(updatedRecords[i].MultiLineText).toEqual(
'Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. Long text. '
);
for (let j = 0; j < fields.length; j++) {
if (fields[j] === 'Time') {
expect(updatedRecords[i][fields[j]]).toContain(APIResponse[j]);
} else {
expect(+updatedRecords[i][fields[j]]).toEqual(APIResponse[j]);
}
}
}
});
});

Loading…
Cancel
Save