mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
4.0 KiB
113 lines
4.0 KiB
2 years ago
|
import { expect, Locator } from '@playwright/test';
|
||
|
import BasePage from '../../Base';
|
||
|
import { DashboardPage } from '..';
|
||
2 years ago
|
|
||
|
export class ExpandedFormPage extends BasePage {
|
||
|
readonly dashboard: DashboardPage;
|
||
|
readonly addNewTableButton: Locator;
|
||
2 years ago
|
readonly copyUrlButton: Locator;
|
||
2 years ago
|
readonly toggleCommentsButton: Locator;
|
||
2 years ago
|
|
||
|
constructor(dashboard: DashboardPage) {
|
||
|
super(dashboard.rootPage);
|
||
|
this.dashboard = dashboard;
|
||
2 years ago
|
this.addNewTableButton = this.dashboard.get().locator('.nc-add-new-table');
|
||
|
this.copyUrlButton = this.dashboard.get().locator('.nc-copy-row-url:visible');
|
||
|
this.toggleCommentsButton = this.dashboard.get().locator('.nc-toggle-comments:visible');
|
||
2 years ago
|
}
|
||
|
|
||
|
get() {
|
||
|
return this.dashboard.get().locator(`.nc-drawer-expanded-form`);
|
||
|
}
|
||
|
|
||
2 years ago
|
async gotoUsingUrlAndRowId({ rowId }: { rowId: string }) {
|
||
|
const url = await this.dashboard.rootPage.url();
|
||
2 years ago
|
const expandedFormUrl = '/' + url.split('/').slice(3).join('/').split('?')[0] + `?rowId=${rowId}`;
|
||
|
await this.rootPage.goto(expandedFormUrl);
|
||
2 years ago
|
await this.dashboard.waitForLoaderToDisappear();
|
||
|
}
|
||
|
|
||
2 years ago
|
async fillField({ columnTitle, value, type = 'text' }: { columnTitle: string; value: string; type?: string }) {
|
||
2 years ago
|
const field = this.get().locator(`[data-nc="nc-expand-col-${columnTitle}"]`);
|
||
2 years ago
|
await field.hover();
|
||
|
switch (type) {
|
||
2 years ago
|
case 'text':
|
||
|
await field.locator('input').fill(value);
|
||
2 years ago
|
break;
|
||
2 years ago
|
case 'belongsTo':
|
||
|
await field.locator('.nc-action-icon').click();
|
||
2 years ago
|
await this.dashboard.linkRecord.select(value);
|
||
|
break;
|
||
2 years ago
|
case 'hasMany':
|
||
|
case 'manyToMany':
|
||
2 years ago
|
await field.locator(`[data-cy="nc-child-list-button-link-to"]`).click();
|
||
|
await this.dashboard.linkRecord.select(value);
|
||
|
break;
|
||
|
}
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async save({
|
||
|
waitForRowsData = true,
|
||
|
}: {
|
||
|
waitForRowsData?: boolean;
|
||
2 years ago
|
} = {}) {
|
||
|
const saveRowAction = this.get().locator('button:has-text("Save Row")').click();
|
||
2 years ago
|
if (waitForRowsData) {
|
||
2 years ago
|
await this.waitForResponse({
|
||
2 years ago
|
uiAction: saveRowAction,
|
||
2 years ago
|
requestUrlPathToMatch: 'api/v1/db/data/noco/',
|
||
|
httpMethodsToMatch: ['GET'],
|
||
2 years ago
|
responseJsonMatcher: json => json['pageInfo'],
|
||
2 years ago
|
});
|
||
2 years ago
|
} else {
|
||
|
await this.waitForResponse({
|
||
|
uiAction: saveRowAction,
|
||
|
requestUrlPathToMatch: 'api/v1/db/data/noco/',
|
||
|
httpMethodsToMatch: ['POST'],
|
||
|
});
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
await this.get().press('Escape');
|
||
|
await this.get().waitFor({ state: 'hidden' });
|
||
2 years ago
|
await this.verifyToast({ message: `updated successfully.` });
|
||
2 years ago
|
await this.rootPage.locator('[data-nc="grid-load-spinner"]').waitFor({ state: 'hidden' });
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async verify({ header, url }: { header: string; url: string }) {
|
||
2 years ago
|
await expect(this.get().locator(`.nc-expanded-form-header`).last()).toContainText(header);
|
||
|
await expect.poll(() => this.rootPage.url()).toContain(url);
|
||
2 years ago
|
}
|
||
|
|
||
|
async close() {
|
||
2 years ago
|
await this.rootPage.keyboard.press('Escape');
|
||
2 years ago
|
}
|
||
|
|
||
|
async cancel() {
|
||
|
await this.get().locator('button:has-text("Cancel")').last().click();
|
||
|
}
|
||
|
|
||
|
async openChildCard(param: { column: string; title: string }) {
|
||
2 years ago
|
const childList = await this.get().locator(`[data-nc="nc-expand-col-${param.column}"]`);
|
||
2 years ago
|
await childList.locator(`.ant-card:has-text("${param.title}")`).click();
|
||
|
}
|
||
|
|
||
2 years ago
|
async verifyCount({ count }: { count: number }) {
|
||
2 years ago
|
return await expect(this.rootPage.locator(`.nc-drawer-expanded-form .ant-drawer-content`)).toHaveCount(count);
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async validateRoleAccess(param: { role: string }) {
|
||
2 years ago
|
if (param.role === 'commenter' || param.role === 'viewer') {
|
||
|
await expect(await this.get().locator('button:has-text("Save Row")')).toBeDisabled();
|
||
2 years ago
|
} else {
|
||
2 years ago
|
await expect(await this.get().locator('button:has-text("Save Row")')).toBeEnabled();
|
||
2 years ago
|
}
|
||
2 years ago
|
if (param.role === 'viewer') {
|
||
2 years ago
|
await expect(await this.toggleCommentsButton).toHaveCount(0);
|
||
2 years ago
|
} else {
|
||
2 years ago
|
await expect(await this.toggleCommentsButton).toHaveCount(1);
|
||
2 years ago
|
}
|
||
|
// press escape to close the expanded form
|
||
2 years ago
|
await this.rootPage.keyboard.press('Escape');
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|