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.
220 lines
6.9 KiB
220 lines
6.9 KiB
2 years ago
|
import { expect, Page } from '@playwright/test';
|
||
|
import { GridPage } from '..';
|
||
|
import BasePage from '../../../Base';
|
||
|
import { SelectOptionColumnPageObject } from './SelectOptionColumn';
|
||
2 years ago
|
|
||
2 years ago
|
export class ColumnPageObject extends BasePage {
|
||
|
readonly grid: GridPage;
|
||
2 years ago
|
readonly selectOption: SelectOptionColumnPageObject;
|
||
|
|
||
2 years ago
|
constructor(grid: GridPage) {
|
||
|
super(grid.rootPage);
|
||
|
this.grid = grid;
|
||
2 years ago
|
this.selectOption = new SelectOptionColumnPageObject(this);
|
||
|
}
|
||
|
|
||
2 years ago
|
get() {
|
||
2 years ago
|
return this.rootPage.locator('form[data-testid="add-or-edit-column"]');
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async create({
|
||
|
title,
|
||
2 years ago
|
type = 'SingleLineText',
|
||
|
formula = '',
|
||
|
childTable = '',
|
||
|
childColumn = '',
|
||
|
relationType = '',
|
||
|
rollupType = '',
|
||
|
format = '',
|
||
2 years ago
|
}: {
|
||
|
title: string;
|
||
|
type?: string;
|
||
2 years ago
|
formula?: string;
|
||
2 years ago
|
childTable?: string;
|
||
|
childColumn?: string;
|
||
2 years ago
|
relationType?: string;
|
||
2 years ago
|
rollupType?: string;
|
||
2 years ago
|
format?: string;
|
||
2 years ago
|
}) {
|
||
2 years ago
|
await this.grid.get().locator('.nc-column-add').click();
|
||
2 years ago
|
await this.rootPage.waitForTimeout(500);
|
||
2 years ago
|
await this.fillTitle({ title });
|
||
2 years ago
|
await this.rootPage.waitForTimeout(500);
|
||
2 years ago
|
await this.selectType({ type });
|
||
2 years ago
|
await this.rootPage.waitForTimeout(500);
|
||
2 years ago
|
|
||
|
switch (type) {
|
||
2 years ago
|
case 'SingleTextLine':
|
||
2 years ago
|
break;
|
||
2 years ago
|
case 'SingleSelect':
|
||
|
case 'MultiSelect':
|
||
2 years ago
|
await this.selectOption.addOption({
|
||
|
index: 0,
|
||
2 years ago
|
option: 'Option 1',
|
||
2 years ago
|
skipColumnModal: true,
|
||
|
});
|
||
|
await this.selectOption.addOption({
|
||
|
index: 1,
|
||
2 years ago
|
option: 'Option 2',
|
||
2 years ago
|
skipColumnModal: true,
|
||
|
});
|
||
2 years ago
|
break;
|
||
2 years ago
|
case 'Duration':
|
||
|
await this.get().locator('.ant-select-single').nth(1).click();
|
||
2 years ago
|
await this.rootPage
|
||
|
.locator(`.ant-select-item`, {
|
||
|
hasText: format,
|
||
|
})
|
||
|
.click();
|
||
|
break;
|
||
2 years ago
|
case 'Formula':
|
||
|
await this.get().locator('.nc-formula-input').fill(formula);
|
||
2 years ago
|
break;
|
||
2 years ago
|
case 'Lookup':
|
||
|
await this.get().locator('.ant-select-single').nth(1).click();
|
||
2 years ago
|
await this.rootPage
|
||
|
.locator(`.ant-select-item`, {
|
||
|
hasText: childTable,
|
||
|
})
|
||
|
.click();
|
||
2 years ago
|
await this.get().locator('.ant-select-single').nth(2).click();
|
||
2 years ago
|
await this.rootPage
|
||
|
.locator(`.ant-select-item`, {
|
||
|
hasText: childColumn,
|
||
|
})
|
||
|
.click();
|
||
|
break;
|
||
2 years ago
|
case 'Rollup':
|
||
|
await this.get().locator('.ant-select-single').nth(1).click();
|
||
2 years ago
|
await this.rootPage
|
||
|
.locator(`.ant-select-item`, {
|
||
|
hasText: childTable,
|
||
|
})
|
||
|
.click();
|
||
2 years ago
|
await this.get().locator('.ant-select-single').nth(2).click();
|
||
2 years ago
|
await this.rootPage
|
||
|
.locator(`.nc-dropdown-relation-column >> .ant-select-item`, {
|
||
|
hasText: childColumn,
|
||
|
})
|
||
|
.click();
|
||
2 years ago
|
await this.get().locator('.ant-select-single').nth(3).click();
|
||
2 years ago
|
await this.rootPage
|
||
|
.locator(`.nc-dropdown-rollup-function >> .ant-select-item`, {
|
||
|
hasText: rollupType,
|
||
|
})
|
||
|
.nth(0)
|
||
|
.click();
|
||
|
break;
|
||
2 years ago
|
case 'LinkToAnotherRecord':
|
||
2 years ago
|
await this.get()
|
||
2 years ago
|
.locator('.nc-ltar-relation-type >> .ant-radio')
|
||
|
.nth(relationType === 'Has Many' ? 0 : 1)
|
||
2 years ago
|
.click();
|
||
2 years ago
|
await this.get().locator('.ant-select-single').nth(1).click();
|
||
|
await this.rootPage.locator(`.nc-ltar-child-table >> input[type="search"]`).fill(childTable);
|
||
2 years ago
|
await this.rootPage
|
||
|
.locator(`.nc-dropdown-ltar-child-table >> .ant-select-item`, {
|
||
|
hasText: childTable,
|
||
|
})
|
||
|
.nth(0)
|
||
|
.click();
|
||
|
break;
|
||
2 years ago
|
default:
|
||
|
break;
|
||
|
}
|
||
|
|
||
2 years ago
|
await this.save();
|
||
|
}
|
||
|
|
||
2 years ago
|
async fillTitle({ title }: { title: string }) {
|
||
2 years ago
|
await this.get().locator('.nc-column-name-input').fill(title);
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async selectType({ type }: { type: string }) {
|
||
2 years ago
|
await this.get().locator('.ant-select-selector > .ant-select-selection-item').click();
|
||
2 years ago
|
|
||
2 years ago
|
await this.get().locator('.ant-select-selection-search-input[aria-expanded="true"]').waitFor();
|
||
|
await this.get().locator('.ant-select-selection-search-input[aria-expanded="true"]').fill(type);
|
||
2 years ago
|
|
||
|
// Select column type
|
||
2 years ago
|
await this.rootPage.locator(`text=${type}`).nth(1).click();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async delete({ title }: { title: string }) {
|
||
2 years ago
|
await this.grid.get().locator(`th[data-title="${title}"] >> svg.ant-dropdown-trigger`).click();
|
||
2 years ago
|
// await this.rootPage.locator('li[role="menuitem"]:has-text("Delete")').waitFor();
|
||
2 years ago
|
await this.rootPage.locator('li[role="menuitem"]:has-text("Delete")').click();
|
||
2 years ago
|
|
||
2 years ago
|
await this.rootPage.locator('button:has-text("Delete")').click();
|
||
2 years ago
|
|
||
|
// wait till modal is closed
|
||
2 years ago
|
await this.rootPage.locator('.nc-modal-column-delete').waitFor({ state: 'hidden' });
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async openEdit({
|
||
|
title,
|
||
2 years ago
|
type = 'SingleLineText',
|
||
|
formula = '',
|
||
2 years ago
|
format,
|
||
2 years ago
|
}: {
|
||
|
title: string;
|
||
|
type?: string;
|
||
|
formula?: string;
|
||
2 years ago
|
format?: string;
|
||
2 years ago
|
}) {
|
||
2 years ago
|
await this.grid.get().locator(`th[data-title="${title}"] .nc-ui-dt-dropdown`).click();
|
||
2 years ago
|
await this.rootPage.locator('li[role="menuitem"]:has-text("Edit")').click();
|
||
2 years ago
|
|
||
2 years ago
|
await this.get().waitFor({ state: 'visible' });
|
||
2 years ago
|
|
||
2 years ago
|
switch (type) {
|
||
2 years ago
|
case 'Formula':
|
||
|
await this.get().locator('.nc-formula-input').fill(formula);
|
||
2 years ago
|
break;
|
||
2 years ago
|
case 'Duration':
|
||
|
await this.get().locator('.ant-select-single').nth(1).click();
|
||
2 years ago
|
await this.rootPage
|
||
|
.locator(`.ant-select-item`, {
|
||
|
hasText: format,
|
||
|
})
|
||
|
.click();
|
||
|
break;
|
||
2 years ago
|
default:
|
||
|
break;
|
||
|
}
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async save({ isUpdated }: { isUpdated?: boolean } = {}) {
|
||
2 years ago
|
await this.waitForResponse({
|
||
|
uiAction: this.get().locator('button:has-text("Save")').click(),
|
||
|
requestUrlPathToMatch: 'api/v1/db/data/noco/',
|
||
|
httpMethodsToMatch: ['GET'],
|
||
2 years ago
|
responseJsonMatcher: json => json['pageInfo'],
|
||
2 years ago
|
});
|
||
2 years ago
|
|
||
2 years ago
|
await this.verifyToast({
|
||
2 years ago
|
message: isUpdated ? 'Column updated' : 'Column created',
|
||
2 years ago
|
});
|
||
2 years ago
|
await this.get().waitFor({ state: 'hidden' });
|
||
2 years ago
|
await this.rootPage.waitForTimeout(200);
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
2 years ago
|
async verify({ title, isVisible = true }: { title: string; isVisible?: boolean }) {
|
||
2 years ago
|
if (!isVisible) {
|
||
2 years ago
|
return await expect(await this.rootPage.locator(`th[data-title="${title}"]`)).not.toBeVisible();
|
||
2 years ago
|
}
|
||
2 years ago
|
await await expect(this.rootPage.locator(`th[data-title="${title}"]`)).toContainText(title);
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async verifyRoleAccess(param: { role: string }) {
|
||
2 years ago
|
await expect(this.grid.get().locator('.nc-column-add:visible')).toHaveCount(param.role === 'creator' ? 1 : 0);
|
||
|
await expect(this.grid.get().locator('.nc-ui-dt-dropdown:visible')).toHaveCount(param.role === 'creator' ? 3 : 0);
|
||
2 years ago
|
|
||
2 years ago
|
if (param.role === 'creator') {
|
||
|
await this.grid.get().locator('.nc-ui-dt-dropdown:visible').first().click();
|
||
|
await expect(this.rootPage.locator('.nc-dropdown-column-operations')).toHaveCount(1);
|
||
|
await this.grid.get().locator('.nc-ui-dt-dropdown:visible').first().click();
|
||
2 years ago
|
}
|
||
|
}
|
||
2 years ago
|
}
|