mirror of
https://github.com/penpot/penpot.git
synced 2025-05-09 23:06:43 +02:00
♻️ Refactor tests and pages
This commit is contained in:
parent
572c6f02e2
commit
0091ac0f5f
24 changed files with 201 additions and 254 deletions
38
frontend/playwright/ui/pages/BasePage.js
Normal file
38
frontend/playwright/ui/pages/BasePage.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
export class BasePage {
|
||||
static async mockRPC(page, path, jsonFilename, options) {
|
||||
if (!page) {
|
||||
throw new TypeError("Invalid page argument. Must be a Playwright page.");
|
||||
}
|
||||
if (typeof path !== "string" && !(path instanceof RegExp)) {
|
||||
throw new TypeError("Invalid path argument. Must be a string or a RegExp.");
|
||||
}
|
||||
const url = typeof path === "string" ? `**/api/rpc/command/${path}` : path;
|
||||
const interceptConfig = {
|
||||
status: 200,
|
||||
contentType: "application/transit+json",
|
||||
...options,
|
||||
};
|
||||
return page.route(url, (route) =>
|
||||
route.fulfill({
|
||||
...interceptConfig,
|
||||
path: `playwright/data/${jsonFilename}`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
#page = null;
|
||||
|
||||
constructor(page) {
|
||||
this.#page = page;
|
||||
}
|
||||
|
||||
get page() {
|
||||
return this.#page;
|
||||
}
|
||||
|
||||
async mockRPC(path, jsonFilename, options) {
|
||||
return BasePage.mockRPC(this.page, path, jsonFilename, options);
|
||||
}
|
||||
}
|
||||
|
||||
export default BasePage;
|
Loading…
Add table
Add a link
Reference in a new issue