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.
193 lines
5.8 KiB
193 lines
5.8 KiB
2 years ago
|
import { expect, Page } from '@playwright/test';
|
||
|
import BasePage from '../Base';
|
||
|
import { DashboardPage } from '../Dashboard';
|
||
2 years ago
|
|
||
|
export class ProjectsPage extends BasePage {
|
||
|
constructor(rootPage: Page) {
|
||
|
super(rootPage);
|
||
|
}
|
||
|
|
||
2 years ago
|
prefixTitle(title: string) {
|
||
2 years ago
|
const parallelId = process.env.TEST_PARALLEL_INDEX ?? '0';
|
||
2 years ago
|
return `nc_test_${parallelId}_${title}`;
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
get() {
|
||
2 years ago
|
return this.rootPage.locator('[data-nc="projects-container"]');
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
// create project
|
||
|
async createProject({
|
||
2 years ago
|
name = 'sample',
|
||
|
type = 'xcdb',
|
||
2 years ago
|
withoutPrefix,
|
||
|
}: {
|
||
|
name?: string;
|
||
|
type?: string;
|
||
|
withoutPrefix?: boolean;
|
||
|
}) {
|
||
2 years ago
|
if (!withoutPrefix) name = this.prefixTitle(name);
|
||
|
|
||
|
await this.rootPage.locator('.nc-new-project-menu').click();
|
||
|
|
||
|
const createProjectMenu = await this.rootPage.locator('.nc-dropdown-create-project');
|
||
2 years ago
|
|
||
2 years ago
|
if (type === 'xcdb') {
|
||
|
await createProjectMenu.locator(`.ant-dropdown-menu-title-content`).nth(0).click();
|
||
2 years ago
|
} else {
|
||
2 years ago
|
await createProjectMenu.locator(`.ant-dropdown-menu-title-content`).nth(1).click();
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
// todo: Fast page transition breaks the vue router
|
||
|
await this.rootPage.waitForTimeout(2000);
|
||
|
|
||
2 years ago
|
await this.rootPage.locator(`.nc-metadb-project-name`).waitFor();
|
||
|
await this.rootPage.locator(`input.nc-metadb-project-name`).fill(name);
|
||
2 years ago
|
|
||
|
await this.rootPage.waitForTimeout(2000);
|
||
|
|
||
|
await this.rootPage.locator(`button:has-text("Create")`).click({
|
||
|
delay: 2000,
|
||
|
});
|
||
2 years ago
|
|
||
|
// fix me! wait for page to be rendered completely
|
||
|
await this.rootPage.waitForTimeout(2000);
|
||
|
}
|
||
|
|
||
2 years ago
|
async reloadProjects() {
|
||
2 years ago
|
const reloadUiAction = this.get().locator('[data-nc="projects-reload-button"]').click();
|
||
2 years ago
|
await this.waitForResponse({
|
||
|
uiAction: reloadUiAction,
|
||
|
requestUrlPathToMatch: '/api/v1/db/meta/projects',
|
||
|
httpMethodsToMatch: ['GET'],
|
||
|
});
|
||
2 years ago
|
}
|
||
|
|
||
|
async waitToBeRendered() {
|
||
|
await this.get().waitFor({
|
||
2 years ago
|
state: 'visible',
|
||
2 years ago
|
});
|
||
2 years ago
|
(await this.get().elementHandle())?.waitForElementState('stable');
|
||
2 years ago
|
|
||
|
// Wait till the ant table is rendered
|
||
2 years ago
|
await this.get().locator('thead.ant-table-thead >> th').nth(0).waitFor({ state: 'visible' });
|
||
2 years ago
|
await expect(this.get().locator('thead.ant-table-thead >> th').nth(0)).toHaveText('Title');
|
||
2 years ago
|
|
||
2 years ago
|
// todo: remove this, all the above asserts are useless.
|
||
2 years ago
|
// The elements are actually invisible from screenshot but in dom level its visible. Lazy loading issue
|
||
|
await this.rootPage.waitForTimeout(1200);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async openProject({
|
||
|
title,
|
||
|
withoutPrefix,
|
||
|
waitForAuthTab = true,
|
||
|
}: {
|
||
|
title: string;
|
||
|
withoutPrefix?: boolean;
|
||
|
waitForAuthTab?: boolean;
|
||
|
}) {
|
||
2 years ago
|
// todo: Fast page transition breaks the vue router
|
||
|
await this.rootPage.waitForTimeout(2000);
|
||
|
|
||
2 years ago
|
if (!withoutPrefix) title = this.prefixTitle(title);
|
||
2 years ago
|
|
||
2 years ago
|
let project: any;
|
||
|
|
||
2 years ago
|
const openProjectUiAction = this.get()
|
||
|
.locator(`.ant-table-cell`, {
|
||
|
hasText: title,
|
||
|
})
|
||
|
.click();
|
||
2 years ago
|
|
||
2 years ago
|
await Promise.all([
|
||
2 years ago
|
this.rootPage.waitForResponse(async res => {
|
||
|
let json: any = {};
|
||
|
try {
|
||
|
json = await res.json();
|
||
|
} catch (e) {
|
||
2 years ago
|
return false;
|
||
|
}
|
||
|
|
||
2 years ago
|
const isRequiredResponse =
|
||
|
res.request().url().includes('/api/v1/db/meta/projects') &&
|
||
|
['GET'].includes(res.request().method()) &&
|
||
|
json?.title === title;
|
||
2 years ago
|
|
||
2 years ago
|
if (isRequiredResponse) {
|
||
2 years ago
|
project = json;
|
||
|
}
|
||
|
|
||
|
return isRequiredResponse;
|
||
|
}),
|
||
2 years ago
|
openProjectUiAction,
|
||
2 years ago
|
]);
|
||
|
|
||
2 years ago
|
const dashboard = new DashboardPage(this.rootPage, project);
|
||
|
|
||
2 years ago
|
if (waitForAuthTab) await dashboard.waitForTabRender({ title: 'Team & Auth' });
|
||
2 years ago
|
|
||
2 years ago
|
return project;
|
||
|
}
|
||
|
|
||
2 years ago
|
async deleteProject({ title, withoutPrefix }: { title: string; withoutPrefix?: boolean }) {
|
||
|
if (!withoutPrefix) title = this.prefixTitle(title);
|
||
2 years ago
|
|
||
2 years ago
|
await this.get().locator(`[data-nc="delete-project-${title}"]`).click();
|
||
2 years ago
|
await this.rootPage.locator(`button:has-text("Yes")`).click();
|
||
2 years ago
|
|
||
2 years ago
|
await this.get().locator('.ant-table-row', { hasText: title }).waitFor({ state: 'hidden' });
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
async renameProject({
|
||
|
title,
|
||
|
newTitle,
|
||
|
withoutPrefix,
|
||
|
}: {
|
||
|
title: string;
|
||
|
newTitle: string;
|
||
|
withoutPrefix?: boolean;
|
||
|
}) {
|
||
2 years ago
|
if (!withoutPrefix) title = this.prefixTitle(title);
|
||
|
if (!withoutPrefix) newTitle = this.prefixTitle(newTitle);
|
||
2 years ago
|
|
||
|
const project = this.rootPage;
|
||
|
const projRow = await project.locator(`tr`, {
|
||
|
has: project.locator(`td.ant-table-cell:has-text("${title}")`),
|
||
|
});
|
||
2 years ago
|
await projRow.locator('.nc-action-btn').nth(0).click();
|
||
2 years ago
|
|
||
|
// todo: Fast page transition breaks the vue router
|
||
|
await this.rootPage.waitForTimeout(2000);
|
||
|
|
||
2 years ago
|
await project.locator('input.nc-metadb-project-name').fill(newTitle);
|
||
2 years ago
|
// press enter to save
|
||
2 years ago
|
const submitAction = project.locator('input.nc-metadb-project-name').press('Enter');
|
||
2 years ago
|
await this.waitForResponse({
|
||
|
uiAction: submitAction,
|
||
|
requestUrlPathToMatch: 'api/v1/db/meta/projects/',
|
||
|
httpMethodsToMatch: ['PATCH'],
|
||
|
});
|
||
2 years ago
|
|
||
2 years ago
|
// todo: vue navigation breaks if page changes very quickly
|
||
|
await this.rootPage.waitForTimeout(1000);
|
||
2 years ago
|
}
|
||
2 years ago
|
|
||
|
async openLanguageMenu() {
|
||
2 years ago
|
await this.rootPage.locator('.nc-menu-translate').click();
|
||
2 years ago
|
}
|
||
|
|
||
|
async selectLanguage({ index }: { index: number }) {
|
||
2 years ago
|
const modal = await this.rootPage.locator('.nc-dropdown-menu-translate');
|
||
2 years ago
|
await modal.locator(`.ant-dropdown-menu-item`).nth(index).click();
|
||
|
}
|
||
|
|
||
|
async verifyLanguage(param: { json: any }) {
|
||
2 years ago
|
const title = await this.rootPage.locator(`.nc-project-page-title`);
|
||
|
const menu = this.rootPage.locator(`.nc-new-project-menu`);
|
||
2 years ago
|
await expect(title).toHaveText(param.json.title.myProject);
|
||
|
await expect(menu).toHaveText(param.json.title.newProj);
|
||
2 years ago
|
await this.rootPage.locator(`[placeholder="${param.json.activity.searchProject}"]`).waitFor();
|
||
2 years ago
|
}
|
||
2 years ago
|
}
|