forgejo-frontend-integration/tests/user.ts
Aravinth Manivannan 80d6e80112
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
feat: refactor registration code to be reusable
2024-01-10 02:32:55 +05:30

43 lines
1.5 KiB
TypeScript

import { Page, expect } from "@playwright/test";
import { getRandomString } from "./utils";
import * as config from "./config";
export default class User {
username: string;
name: string;
email: string;
password: string;
constructor(name: string) {
this.name = name;
this.username = `playwright_${getRandomString(6)}_${name}`;
this.email = `${this.username}@playwright.local`;
this.password = "628acdbd8b7b3f";
}
async register(page: Page) {
await page.goto(config.INSTANCE_URL.toString());
await page.getByRole("link", { name: "Register" }).click();
await page.waitForURL("**/user/sign_up");
await page.getByLabel("Username").clear();
await page.getByLabel("Email Address").clear();
await page.getByLabel("Password", { exact: true }).clear();
await page.getByLabel("Confirm Password").clear();
await page.getByLabel("Username").fill(this.username);
await page.getByLabel("Email Address").fill(this.email);
await page.getByLabel("Password", { exact: true }).fill(this.password);
await page.getByLabel("Confirm Password").fill(this.password);
await page.getByRole("button", { name: "Register Account" }).click();
await page.waitForURL(config.INSTANCE_URL.toString());
await expect(page).toHaveTitle(
`${this.username} - Dashboard - Forgejo: Beyond coding. We forge.`
);
expect(page.locator(".positive > p:nth-child(1)")).toContainText(
"Account was successfully created. Welcome!"
);
}
}