Browse Source

fix: playwright addNewRow wait for response issue

pull/7218/head
Ramesh Mane 1 year ago
parent
commit
2a4ed7ea59
  1. 24
      tests/playwright/pages/Dashboard/Grid/index.ts
  2. 8
      tests/playwright/tests/db/features/undo-redo.spec.ts

24
tests/playwright/pages/Dashboard/Grid/index.ts

@ -103,12 +103,10 @@ export class GridPage extends BasePage {
index = 0, index = 0,
columnHeader = 'Title', columnHeader = 'Title',
value, value,
networkValidation = true,
}: { }: {
index?: number; index?: number;
columnHeader?: string; columnHeader?: string;
value?: string; value?: string;
networkValidation?: boolean;
} = {}) { } = {}) {
const rowValue = value ?? `Row ${index}`; const rowValue = value ?? `Row ${index}`;
// wait for render to complete before count // wait for render to complete before count
@ -121,6 +119,11 @@ export class GridPage extends BasePage {
await this.rootPage.waitForTimeout(200); await this.rootPage.waitForTimeout(200);
await this.rootPage.waitForLoadState('domcontentloaded'); await this.rootPage.waitForLoadState('domcontentloaded');
// Start waiting for response before clicking add new cell. Note no await.
const addNewRowResponse = this.rootPage.waitForResponse(
res => res.url().includes('api/v1/db/data/noco') && res.request().method() === 'POST' && res.status() === 200
);
await this.get().locator('.nc-grid-add-new-cell').click(); await this.get().locator('.nc-grid-add-new-cell').click();
const rowCount = index + 1; const rowCount = index + 1;
@ -128,21 +131,8 @@ export class GridPage extends BasePage {
await this._fillRow({ index, columnHeader, value: rowValue }); await this._fillRow({ index, columnHeader, value: rowValue });
const clickOnColumnHeaderToSave = () => // Wait for add new row api response
this.get().locator(`[data-title="${columnHeader}"]`).locator(`span[data-test-id="${columnHeader}"]`).click(); await addNewRowResponse;
if (networkValidation) {
await this.waitForResponse({
uiAction: clickOnColumnHeaderToSave,
requestUrlPathToMatch: 'api/v1/db/data/noco',
httpMethodsToMatch: ['POST'],
// numerical types are returned in number format from the server
responseJsonMatcher: resJson => String(resJson?.[columnHeader]) === String(rowValue),
});
} else {
await clickOnColumnHeaderToSave();
await this.rootPage.waitForTimeout(300);
}
await this.rootPage.keyboard.press('Escape'); await this.rootPage.keyboard.press('Escape');
await this.rootPage.waitForTimeout(300); await this.rootPage.waitForTimeout(300);

8
tests/playwright/tests/db/features/undo-redo.spec.ts

@ -134,13 +134,13 @@ test.describe('Undo Redo', () => {
await dashboard.treeView.openTable({ title: 'numberBased' }); await dashboard.treeView.openTable({ title: 'numberBased' });
// Row.Create // Row.Create
await grid.addNewRow({ index: 10, value: '333', columnHeader: 'Number', networkValidation: true }); await grid.addNewRow({ index: 10, value: '333', columnHeader: 'Number' });
await grid.addNewRow({ index: 11, value: '444', columnHeader: 'Number', networkValidation: true }); await grid.addNewRow({ index: 11, value: '444', columnHeader: 'Number' });
await verifyRecords([333, 444]); await verifyRecords([333, 444]);
// Row.Update // Row.Update
await grid.editRow({ index: 10, value: '555', columnHeader: 'Number', networkValidation: true }); await grid.editRow({ index: 10, value: '555', columnHeader: 'Number' });
await grid.editRow({ index: 11, value: '666', columnHeader: 'Number', networkValidation: true }); await grid.editRow({ index: 11, value: '666', columnHeader: 'Number' });
await verifyRecords([555, 666]); await verifyRecords([555, 666]);
// Row.Delete // Row.Delete

Loading…
Cancel
Save