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.
139 lines
3.8 KiB
139 lines
3.8 KiB
// playwright-dev-page.ts |
|
import { expect, Page } from "@playwright/test"; |
|
import BasePage from "../Base"; |
|
|
|
export class ProjectsPage extends BasePage { |
|
constructor(rootPage: Page) { |
|
super(rootPage); |
|
} |
|
|
|
prefixTitle(title: string) { |
|
const parallelId = process.env.TEST_PARALLEL_INDEX ?? '0' |
|
return `${title}${parallelId}`; |
|
} |
|
|
|
get() { |
|
return this.rootPage.locator('[pw-data="projects-container"]'); |
|
} |
|
|
|
// create project |
|
async createProject({ |
|
name = "sample", |
|
type = "xcdb", |
|
withoutPrefix, |
|
}: { |
|
name?: string; |
|
type?: string; |
|
withoutPrefix?: boolean; |
|
}) { |
|
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" |
|
); |
|
if (type === "xcdb") { |
|
await createProjectMenu |
|
.locator(`.ant-dropdown-menu-title-content`) |
|
.nth(0) |
|
.click(); |
|
} else { |
|
await createProjectMenu |
|
.locator(`.ant-dropdown-menu-title-content`) |
|
.nth(1) |
|
.click(); |
|
} |
|
|
|
await this.rootPage.locator(`.nc-metadb-project-name`).waitFor(); |
|
await this.rootPage.locator(`input.nc-metadb-project-name`).fill(name); |
|
await this.rootPage.locator(`input.nc-metadb-project-name`).press("Enter"); |
|
|
|
// fix me! wait for page to be rendered completely |
|
await this.rootPage.waitForTimeout(2000); |
|
} |
|
|
|
async reloadProjects() { |
|
const reloadUiAction = this.get().locator('[pw-data="projects-reload-button"]').click(); |
|
await this.waitForResponse( |
|
{ |
|
uiAction: reloadUiAction, |
|
requestUrlPathToMatch: "/api/v1/db/meta/projects", |
|
httpMethodsToMatch: ["GET"], |
|
} |
|
) |
|
} |
|
|
|
async waitToBeRendered() { |
|
await this.get().waitFor({ |
|
state: "visible", |
|
}); |
|
(await this.get().elementHandle())?.waitForElementState("stable"); |
|
await this.reloadProjects(); |
|
(await this.get().elementHandle())?.waitForElementState("stable"); |
|
} |
|
|
|
async openProject({title, withoutPrefix}: {title: string, withoutPrefix?: boolean}) { |
|
if(!withoutPrefix) title = this.prefixTitle(title); |
|
|
|
let project: any; |
|
|
|
await Promise.all([ |
|
this.rootPage.waitForResponse(async (res) => { |
|
let json:any = {} |
|
try{ |
|
json = await res.json() |
|
} catch(e) { |
|
return false; |
|
} |
|
|
|
const isRequiredResponse = res.request().url().includes('/api/v1/db/meta/projects') && |
|
['GET'].includes(res.request().method()) && |
|
json?.title === title; |
|
|
|
if(isRequiredResponse){ |
|
project = json; |
|
} |
|
|
|
return isRequiredResponse; |
|
}), |
|
this.get().locator(`.ant-table-cell`,{ |
|
hasText: title |
|
}).click() |
|
]); |
|
|
|
return project; |
|
} |
|
|
|
async deleteProject({title, withoutPrefix}: {title: string, withoutPrefix?: boolean}) { |
|
if(!withoutPrefix) title = this.prefixTitle(title); |
|
|
|
await this.get().locator(`[pw-data="delete-project-${title}"]`).click(); |
|
await this.rootPage.locator(`button:has-text("Yes")`).click(); |
|
|
|
await this.get().locator('.ant-table-row', {hasText: title}).waitFor({state: 'hidden'}); |
|
} |
|
|
|
|
|
async renameProject({ |
|
title, |
|
newTitle, |
|
withoutPrefix, |
|
}: { |
|
title: string; |
|
newTitle: string; |
|
withoutPrefix?: boolean; |
|
}) { |
|
if(!withoutPrefix) title = this.prefixTitle(title); |
|
if(!withoutPrefix) newTitle = this.prefixTitle(newTitle); |
|
|
|
const project = this.rootPage; |
|
const projRow = await project.locator(`tr`, { |
|
has: project.locator(`td.ant-table-cell:has-text("${title}")`), |
|
}); |
|
await projRow.locator(".nc-action-btn").nth(0).click(); |
|
await project.locator("input.nc-metadb-project-name").fill(newTitle); |
|
// press enter to save |
|
await project.locator("input.nc-metadb-project-name").press("Enter"); |
|
} |
|
}
|
|
|