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.
148 lines
5.2 KiB
148 lines
5.2 KiB
2 years ago
|
import { expect, Locator } from '@playwright/test';
|
||
|
import { GridPage } from '../../Grid';
|
||
|
import BasePage from '../../../Base';
|
||
|
import { AttachmentCellPageObject } from './AttachmentCell';
|
||
|
import { SelectOptionCellPageObject } from './SelectOptionCell';
|
||
|
import { SharedFormPage } from '../../../SharedForm';
|
||
|
import { CheckboxCellPageObject } from './CheckboxCell';
|
||
|
import { RatingCellPageObject } from './RatingCell';
|
||
2 years ago
|
|
||
2 years ago
|
export class CellPageObject extends BasePage {
|
||
2 years ago
|
readonly parent: GridPage | SharedFormPage;
|
||
2 years ago
|
readonly selectOption: SelectOptionCellPageObject;
|
||
2 years ago
|
readonly attachment: AttachmentCellPageObject;
|
||
2 years ago
|
readonly checkbox: CheckboxCellPageObject;
|
||
|
readonly rating: RatingCellPageObject;
|
||
2 years ago
|
constructor(parent: GridPage | SharedFormPage) {
|
||
|
super(parent.rootPage);
|
||
|
this.parent = parent;
|
||
2 years ago
|
this.selectOption = new SelectOptionCellPageObject(this);
|
||
2 years ago
|
this.attachment = new AttachmentCellPageObject(this);
|
||
2 years ago
|
this.checkbox = new CheckboxCellPageObject(this);
|
||
|
this.rating = new RatingCellPageObject(this);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
get({ index, columnHeader }: { index?: number; columnHeader: string }): Locator {
|
||
2 years ago
|
if (this.parent instanceof SharedFormPage) {
|
||
2 years ago
|
return this.parent.get().locator(`[data-nc="nc-form-input-cell-${columnHeader}"]`);
|
||
2 years ago
|
} else {
|
||
2 years ago
|
return this.parent.get().locator(`td[data-nc="cell-${columnHeader}-${index}"]`);
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async click({ index, columnHeader }: { index: number; columnHeader: string }) {
|
||
2 years ago
|
return await this.get({ index, columnHeader }).click();
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async dblclick({ index, columnHeader }: { index?: number; columnHeader: string }) {
|
||
2 years ago
|
return await this.get({ index, columnHeader }).dblclick();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async fillText({ index, columnHeader, text }: { index?: number; columnHeader: string; text: string }) {
|
||
2 years ago
|
await this.dblclick({
|
||
|
index,
|
||
|
columnHeader,
|
||
|
});
|
||
2 years ago
|
await this.get({ index, columnHeader }).locator('input').fill(text);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async inCellExpand({ index, columnHeader }: { index: number; columnHeader: string }) {
|
||
2 years ago
|
await this.get({ index, columnHeader }).hover();
|
||
2 years ago
|
await this.waitForResponse({
|
||
2 years ago
|
uiAction: this.get({ index, columnHeader }).locator('.nc-action-icon >> nth=0').click(),
|
||
2 years ago
|
requestUrlPathToMatch: '/api/v1/db/data/noco/',
|
||
|
httpMethodsToMatch: ['GET'],
|
||
2 years ago
|
});
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async inCellAdd({ index, columnHeader }: { index: number; columnHeader: string }) {
|
||
2 years ago
|
await this.get({ index, columnHeader }).hover();
|
||
2 years ago
|
await this.get({ index, columnHeader }).locator('.nc-action-icon.nc-plus').click();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async verify({ index, columnHeader, value }: { index: number; columnHeader: string; value: string | string[] }) {
|
||
|
const _verify = async text => {
|
||
2 years ago
|
await expect
|
||
|
.poll(async () => {
|
||
|
const innerTexts = await this.get({
|
||
|
index,
|
||
|
columnHeader,
|
||
|
}).allInnerTexts();
|
||
2 years ago
|
return typeof innerTexts === 'string' ? [innerTexts] : innerTexts;
|
||
2 years ago
|
})
|
||
|
.toContain(text);
|
||
|
};
|
||
2 years ago
|
|
||
2 years ago
|
if (Array.isArray(value)) {
|
||
|
for (const text of value) {
|
||
2 years ago
|
await _verify(text);
|
||
|
}
|
||
|
} else {
|
||
|
await _verify(value);
|
||
|
}
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
// todo: Improve param names (i.e value => values)
|
||
2 years ago
|
// verifyVirtualCell
|
||
|
// : virtual relational cell- HM, BT, MM
|
||
|
// : verify link count & cell value
|
||
|
//
|
||
2 years ago
|
async verifyVirtualCell({
|
||
|
index,
|
||
|
columnHeader,
|
||
|
count,
|
||
|
value,
|
||
|
}: {
|
||
|
index: number;
|
||
|
columnHeader: string;
|
||
2 years ago
|
count?: number;
|
||
2 years ago
|
value: string[];
|
||
|
}) {
|
||
|
// const count = value.length;
|
||
|
const cell = this.get({ index, columnHeader });
|
||
2 years ago
|
const chips = cell.locator('.chips > .chip');
|
||
2 years ago
|
|
||
|
// verify chip count & contents
|
||
2 years ago
|
if (count) await expect(chips).toHaveCount(count);
|
||
2 years ago
|
|
||
|
// verify only the elements that are passed in
|
||
|
for (let i = 0; i < value.length; ++i) {
|
||
2 years ago
|
await expect(await chips.nth(i)).toHaveText(value[i]);
|
||
2 years ago
|
}
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async unlinkVirtualCell({ index, columnHeader }: { index: number; columnHeader: string }) {
|
||
2 years ago
|
const cell = this.get({ index, columnHeader });
|
||
|
await cell.click();
|
||
2 years ago
|
await cell.locator('.nc-icon.unlink-icon').click();
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async verifyRoleAccess(param: { role: string }) {
|
||
|
// normal text cell
|
||
2 years ago
|
const cell = await this.get({ index: 0, columnHeader: 'Country' });
|
||
2 years ago
|
// editable cell
|
||
|
await cell.dblclick();
|
||
2 years ago
|
await expect(await cell.locator(`input`)).toHaveCount(param.role === 'creator' || param.role === 'editor' ? 1 : 0);
|
||
2 years ago
|
// right click context menu
|
||
2 years ago
|
await cell.click({ button: 'right' });
|
||
|
await expect(await this.rootPage.locator(`.nc-dropdown-grid-context-menu:visible`)).toHaveCount(
|
||
|
param.role === 'creator' || param.role === 'editor' ? 1 : 0
|
||
|
);
|
||
2 years ago
|
|
||
|
// virtual cell
|
||
2 years ago
|
const vCell = await this.get({ index: 0, columnHeader: 'City List' });
|
||
2 years ago
|
await vCell.hover();
|
||
|
// in-cell add
|
||
2 years ago
|
await expect(await vCell.locator('.nc-action-icon.nc-plus:visible')).toHaveCount(
|
||
|
param.role === 'creator' || param.role === 'editor' ? 1 : 0
|
||
2 years ago
|
);
|
||
|
// in-cell expand (all have access)
|
||
2 years ago
|
await expect(await vCell.locator('.nc-action-icon.nc-arrow-expand:visible')).toHaveCount(1);
|
||
2 years ago
|
await vCell.click();
|
||
|
// unlink
|
||
2 years ago
|
await expect(await vCell.locator('.nc-icon.unlink-icon:visible')).toHaveCount(
|
||
|
param.role === 'creator' || param.role === 'editor' ? 1 : 0
|
||
2 years ago
|
);
|
||
|
}
|
||
2 years ago
|
}
|