mirror of
https://github.com/penpot/penpot.git
synced 2025-02-08 16:18:11 -05:00
♻️ Refactor LoginPage POM
This commit is contained in:
parent
127c47a35a
commit
9fd9e0178e
5 changed files with 53 additions and 71 deletions
|
@ -1,10 +0,0 @@
|
||||||
import { test as base } from '@playwright/test'
|
|
||||||
|
|
||||||
export const test = base.extend({
|
|
||||||
loginPage: async ({ page }, use) => {
|
|
||||||
const loginPage = new LoginPage(page)
|
|
||||||
await use(loginPage)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
export { expect } from '@playwright/test'
|
|
|
@ -6,6 +6,7 @@ export class BasePage {
|
||||||
if (typeof path !== "string" && !(path instanceof RegExp)) {
|
if (typeof path !== "string" && !(path instanceof RegExp)) {
|
||||||
throw new TypeError("Invalid path argument. Must be a string or a 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 url = typeof path === "string" ? `**/api/rpc/command/${path}` : path;
|
||||||
const interceptConfig = {
|
const interceptConfig = {
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { BasePage } from "./BasePage";
|
import { BasePage } from "./BasePage";
|
||||||
|
|
||||||
export class LoginPage extends BasePage {
|
export class LoginPage extends BasePage {
|
||||||
static setupLoggedOutUser(page) {
|
static async initWithLoggedOutUser(page) {
|
||||||
return this.mockRPC(page, "get-profile", "get-profile-anonymous.json");
|
await BasePage.mockRPC(page, "get-profile", "get-profile-anonymous.json");
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(page) {
|
constructor(page) {
|
||||||
|
@ -10,8 +10,8 @@ export class LoginPage extends BasePage {
|
||||||
this.loginButton = page.getByRole("button", { name: "Login" });
|
this.loginButton = page.getByRole("button", { name: "Login" });
|
||||||
this.password = page.getByLabel("Password");
|
this.password = page.getByLabel("Password");
|
||||||
this.userName = page.getByLabel("Email");
|
this.userName = page.getByLabel("Email");
|
||||||
this.message = page.getByText("Email or password is incorrect");
|
this.invalidCredentialsError = page.getByText("Email or password is incorrect");
|
||||||
this.badLoginMsg = page.getByText("Enter a valid email please");
|
this.invalidEmailError = page.getByText("Enter a valid email please");
|
||||||
this.initialHeading = page.getByRole("heading", { name: "Log into my account" });
|
this.initialHeading = page.getByRole("heading", { name: "Log into my account" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ export class LoginPage extends BasePage {
|
||||||
await this.loginButton.click();
|
await this.loginButton.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
async setupAllowedUser() {
|
async setupLoggedInUser() {
|
||||||
await this.mockRPC("get-profile", "logged-in-user/get-profile-logged-in.json");
|
await this.mockRPC("get-profile", "logged-in-user/get-profile-logged-in.json");
|
||||||
await this.mockRPC("get-teams", "logged-in-user/get-teams-default.json");
|
await this.mockRPC("get-teams", "logged-in-user/get-teams-default.json");
|
||||||
await this.mockRPC("get-font-variants?team-id=*", "logged-in-user/get-font-variants-empty.json");
|
await this.mockRPC("get-font-variants?team-id=*", "logged-in-user/get-font-variants-empty.json");
|
||||||
|
|
|
@ -2,50 +2,49 @@ import { test, expect } from "@playwright/test";
|
||||||
import { LoginPage } from "../pages/LoginPage";
|
import { LoginPage } from "../pages/LoginPage";
|
||||||
|
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
await LoginPage.setupLoggedOutUser(page);
|
await LoginPage.initWithLoggedOutUser(page);
|
||||||
await page.goto("/#/auth/login");
|
await page.goto("/#/auth/login");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Shows login page when going to index and user is logged out", async ({ page }) => {
|
test("User is redirected to the login page when logged out", async ({ page }) => {
|
||||||
const loginPage = new LoginPage(page);
|
const loginPage = new LoginPage(page);
|
||||||
|
|
||||||
await loginPage.setupAllowedUser();
|
await loginPage.setupLoggedInUser();
|
||||||
|
|
||||||
await expect(loginPage.page).toHaveURL(/auth\/login$/);
|
await expect(loginPage.page).toHaveURL(/auth\/login$/);
|
||||||
await expect(loginPage.initialHeading).toBeVisible();
|
await expect(loginPage.initialHeading).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("User submit a wrong formated email ", async ({ page }) => {
|
test.describe("Login form", () => {
|
||||||
const loginPage = new LoginPage(page);
|
test("User logs in by filling the login form", async ({ page }) => {
|
||||||
|
const loginPage = new LoginPage(page);
|
||||||
|
await loginPage.setupLoginSuccess();
|
||||||
|
await loginPage.setupLoggedInUser();
|
||||||
|
|
||||||
await loginPage.setupLoginSuccess();
|
await loginPage.fillEmailAndPasswordInputs("foo@example.com", "loremipsum");
|
||||||
|
await loginPage.clickLoginButton();
|
||||||
|
|
||||||
await loginPage.fillEmailAndPasswordInputs("foo", "lorenIpsum");
|
await page.waitForURL("**/dashboard/**");
|
||||||
|
await expect(loginPage.page).toHaveURL(/dashboard/);
|
||||||
|
});
|
||||||
|
|
||||||
await expect(loginPage.badLoginMsg).toBeVisible();
|
test("User gets error message when submitting an bad formatted email ", async ({ page }) => {
|
||||||
});
|
const loginPage = new LoginPage(page);
|
||||||
|
await loginPage.setupLoginSuccess();
|
||||||
test("User logs in by filling the login form", async ({ page }) => {
|
|
||||||
const loginPage = new LoginPage(page);
|
await loginPage.fillEmailAndPasswordInputs("foo", "lorenIpsum");
|
||||||
|
|
||||||
await loginPage.setupLoginSuccess();
|
await expect(loginPage.invalidEmailError).toBeVisible();
|
||||||
await loginPage.setupAllowedUser();
|
});
|
||||||
|
|
||||||
await loginPage.fillEmailAndPasswordInputs("foo@example.com", "loremipsum");
|
test("User gets error message when submitting wrong credentials", async ({ page }) => {
|
||||||
await loginPage.clickLoginButton();
|
const loginPage = new LoginPage(page);
|
||||||
|
await loginPage.setupLoginError();
|
||||||
await page.waitForURL('**/dashboard/**');
|
|
||||||
await expect(loginPage.page).toHaveURL(/dashboard/);
|
await loginPage.fillEmailAndPasswordInputs("test@example.com", "loremipsum");
|
||||||
});
|
await loginPage.clickLoginButton();
|
||||||
|
|
||||||
test("User submits wrong credentials", async ({ page }) => {
|
await expect(loginPage.invalidCredentialsError).toBeVisible();
|
||||||
const loginPage = new LoginPage(page);
|
await expect(loginPage.page).toHaveURL(/auth\/login$/);
|
||||||
|
});
|
||||||
await loginPage.setupLoginError();
|
|
||||||
|
|
||||||
await loginPage.fillEmailAndPasswordInputs("test@example.com", "loremipsum");
|
|
||||||
await loginPage.clickLoginButton();
|
|
||||||
|
|
||||||
await expect(loginPage.message).toBeVisible();
|
|
||||||
await expect(loginPage.page).toHaveURL(/auth\/login$/);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { test, expect } from "@playwright/test";
|
import { test, expect } from "@playwright/test";
|
||||||
import { BasePage } from "../pages/BasePage";
|
import { BaseWebSocketPage } from "../pages/BaseWebSocketPage";
|
||||||
import { MockWebSocketHelper } from "../../helpers/MockWebSocketHelper";
|
import { MockWebSocketHelper } from "../../helpers/MockWebSocketHelper";
|
||||||
import { presenceFixture } from "../../data/workspace/ws-notifications";
|
import { presenceFixture } from "../../data/workspace/ws-notifications";
|
||||||
|
|
||||||
|
@ -8,32 +8,24 @@ const anyFileId = "c7ce0794-0992-8105-8004-38f280443849";
|
||||||
const anyPageId = "c7ce0794-0992-8105-8004-38f28044384a";
|
const anyPageId = "c7ce0794-0992-8105-8004-38f28044384a";
|
||||||
|
|
||||||
const setupWorkspaceUser = (page) => {
|
const setupWorkspaceUser = (page) => {
|
||||||
BasePage.mockRPC(page, "get-profile", "logged-in-user/get-profile-logged-in.json");
|
page.mockRPC("get-profile", "logged-in-user/get-profile-logged-in.json");
|
||||||
BasePage.mockRPC(page, "get-team-users?file-id=*", "logged-in-user/get-team-users-single-user.json");
|
page.mockRPC("get-team-users?file-id=*", "logged-in-user/get-team-users-single-user.json");
|
||||||
BasePage.mockRPC(page, "get-comment-threads?file-id=*", "workspace/get-comment-threads-empty.json");
|
page.mockRPC("get-comment-threads?file-id=*", "workspace/get-comment-threads-empty.json");
|
||||||
BasePage.mockRPC(page, "get-project?id=*", "workspace/get-project-default.json");
|
page.mockRPC("get-project?id=*", "workspace/get-project-default.json");
|
||||||
BasePage.mockRPC(page, "get-team?id=*", "workspace/get-team-default.json");
|
page.mockRPC("get-team?id=*", "workspace/get-team-default.json");
|
||||||
BasePage.mockRPC(page, /get\-file\?/, "workspace/get-file-blank.json");
|
page.mockRPC(/get\-file\?/, "workspace/get-file-blank.json");
|
||||||
BasePage.mockRPC(
|
page.mockRPC("get-file-object-thumbnails?file-id=*", "workspace/get-file-object-thumbnails-blank.json");
|
||||||
page,
|
page.mockRPC("get-profiles-for-file-comments?file-id=*", "workspace/get-profile-for-file-comments.json");
|
||||||
"get-file-object-thumbnails?file-id=*",
|
page.mockRPC("get-font-variants?team-id=*", "workspace/get-font-variants-empty.json");
|
||||||
"workspace/get-file-object-thumbnails-blank.json",
|
page.mockRPC("get-file-fragment?file-id=*", "workspace/get-file-fragment-blank.json");
|
||||||
);
|
page.mockRPC("get-file-libraries?file-id=*", "workspace/get-file-libraries-empty.json");
|
||||||
BasePage.mockRPC(
|
|
||||||
page,
|
|
||||||
"get-profiles-for-file-comments?file-id=*",
|
|
||||||
"workspace/get-profile-for-file-comments.json",
|
|
||||||
);
|
|
||||||
BasePage.mockRPC(page, "get-font-variants?team-id=*", "workspace/get-font-variants-empty.json");
|
|
||||||
BasePage.mockRPC(page, "get-file-fragment?file-id=*", "workspace/get-file-fragment-blank.json");
|
|
||||||
BasePage.mockRPC(page, "get-file-libraries?file-id=*", "workspace/get-file-libraries-empty.json");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
await MockWebSocketHelper.init(page);
|
await MockWebSocketHelper.init(page);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("User loads worskpace with empty file", async ({ page }) => {
|
test.skip("User loads worskpace with empty file", async ({ page }) => {
|
||||||
await setupWorkspaceUser(page);
|
await setupWorkspaceUser(page);
|
||||||
|
|
||||||
await page.goto(`/#/workspace/${anyProjectId}/${anyFileId}?page-id=${anyPageId}`);
|
await page.goto(`/#/workspace/${anyProjectId}/${anyFileId}?page-id=${anyPageId}`);
|
||||||
|
@ -41,11 +33,11 @@ test("User loads worskpace with empty file", async ({ page }) => {
|
||||||
await expect(page.getByTestId("page-name")).toHaveText("Page 1");
|
await expect(page.getByTestId("page-name")).toHaveText("Page 1");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("User receives notifications updates in the workspace", async ({ page }) => {
|
test.skip("User receives notifications updates in the workspace", async ({ page }) => {
|
||||||
await setupWorkspaceUser(page);
|
await setupWorkspaceUser(page);
|
||||||
await page.goto(`/#/workspace/${anyProjectId}/${anyFileId}?page-id=${anyPageId}`);
|
await page.goto(`/#/workspace/${anyProjectId}/${anyFileId}?page-id=${anyPageId}`);
|
||||||
|
|
||||||
const ws = await MockWebSocketHelper.waitForURL("ws://0.0.0.0:3500/ws/notifications")
|
const ws = await MockWebSocketHelper.waitForURL("ws://0.0.0.0:3500/ws/notifications");
|
||||||
await ws.mockOpen();
|
await ws.mockOpen();
|
||||||
await expect(page.getByTestId("page-name")).toHaveText("Page 1");
|
await expect(page.getByTestId("page-name")).toHaveText("Page 1");
|
||||||
await ws.mockMessage(JSON.stringify(presenceFixture));
|
await ws.mockMessage(JSON.stringify(presenceFixture));
|
||||||
|
|
Loading…
Add table
Reference in a new issue