2024-01-09 23:35:51 +05:30
|
|
|
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2024-01-09 23:31:52 +05:30
|
|
|
import { test, expect } from "@playwright/test";
|
|
|
|
import * as config from "./config";
|
2024-01-10 01:54:34 +05:30
|
|
|
import User from "./user";
|
2024-01-09 23:31:52 +05:30
|
|
|
|
|
|
|
test("has title", async ({ page }) => {
|
|
|
|
await page.goto(config.INSTANCE_URL.toString());
|
2024-01-10 01:57:49 +05:30
|
|
|
await expect(page).toHaveTitle("Forgejo: Beyond coding. We forge.");
|
2024-01-09 23:31:52 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
test("Go to explore page", async ({ page }) => {
|
|
|
|
await page.goto(config.INSTANCE_URL.toString());
|
|
|
|
await page.getByRole("link", { name: "Explore" }).click();
|
|
|
|
await page.waitForURL("**/explore/repos");
|
|
|
|
|
2024-01-10 01:57:49 +05:30
|
|
|
await expect(page).toHaveTitle("Explore - Forgejo: Beyond coding. We forge.");
|
2024-01-09 23:31:52 +05:30
|
|
|
});
|
|
|
|
|
2024-01-10 03:01:10 +05:30
|
|
|
test("Test registration error: password mismatch", async ({ page }) => {
|
|
|
|
const user = new User("pwmismatch");
|
2024-01-10 01:54:34 +05:30
|
|
|
|
|
|
|
console.log(`running with user ${user.username}`);
|
|
|
|
|
2024-01-09 23:31:52 +05:30
|
|
|
await page.goto(config.INSTANCE_URL.toString());
|
|
|
|
await page.getByRole("link", { name: "Register" }).click();
|
|
|
|
await page.waitForURL("**/user/sign_up");
|
|
|
|
|
2024-01-10 01:54:34 +05:30
|
|
|
await page.getByLabel("Username").fill(user.username);
|
|
|
|
await page.getByLabel("Email Address").fill(user.email);
|
|
|
|
await page.getByLabel("Password", { exact: true }).fill(user.password);
|
2024-01-09 23:31:52 +05:30
|
|
|
// passwords don't match
|
2024-01-10 01:54:34 +05:30
|
|
|
await page.getByLabel("Confirm Password").fill(user.username);
|
2024-01-09 23:31:52 +05:30
|
|
|
|
|
|
|
await page.getByRole("button", { name: "Register Account" }).click();
|
|
|
|
|
|
|
|
await expect(page).toHaveTitle(
|
2024-01-10 01:57:49 +05:30
|
|
|
"Register - Forgejo: Beyond coding. We forge."
|
2024-01-09 23:31:52 +05:30
|
|
|
);
|
|
|
|
expect(page.locator(".negative > p:nth-child(1)")).toContainText(
|
2024-01-10 20:43:37 +05:30
|
|
|
"The passwords do not match"
|
2024-01-09 23:31:52 +05:30
|
|
|
);
|
2024-01-10 03:01:10 +05:30
|
|
|
});
|
|
|
|
|
2024-01-10 18:54:52 +05:30
|
|
|
test("Test registration error: dupe user", async ({ page }) => {
|
|
|
|
const user = new User("dupeuser");
|
2024-01-10 19:03:46 +05:30
|
|
|
const admin = new User(config.ADMIN_USERNAME);
|
|
|
|
admin.setAdmin();
|
2024-01-10 18:54:52 +05:30
|
|
|
|
|
|
|
|
2024-01-10 19:03:46 +05:30
|
|
|
await page.goto(config.INSTANCE_URL.toString());
|
2024-01-10 18:54:52 +05:30
|
|
|
await page.getByRole("link", { name: "Register" }).click();
|
|
|
|
await page.waitForURL("**/user/sign_up");
|
|
|
|
|
2024-01-10 19:03:46 +05:30
|
|
|
await page.getByLabel("Username").fill(admin.username);
|
2024-01-10 18:54:52 +05:30
|
|
|
await page.getByLabel("Email Address").fill(user.email);
|
|
|
|
await page.getByLabel("Password", { exact: true }).fill(user.password);
|
|
|
|
await page.getByLabel("Confirm Password").fill(user.password);
|
|
|
|
|
|
|
|
await page.getByRole("button", { name: "Register Account" }).click();
|
|
|
|
|
|
|
|
await expect(page).toHaveTitle(
|
|
|
|
"Register - Forgejo: Beyond coding. We forge."
|
|
|
|
);
|
|
|
|
await page.locator(".negative > p:nth-child(1)").waitFor();
|
|
|
|
expect(page.locator(".negative > p:nth-child(1)")).toContainText(
|
|
|
|
"The username is already taken."
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-01-10 19:03:46 +05:30
|
|
|
test("Test registration error: dupe email", async ({ page }) => {
|
|
|
|
const user = new User("dupemeail");
|
|
|
|
const admin = new User(config.ADMIN_USERNAME);
|
|
|
|
admin.setAdmin();
|
|
|
|
|
|
|
|
await page.goto(config.INSTANCE_URL.toString());
|
|
|
|
await page.getByRole("link", { name: "Register" }).click();
|
|
|
|
await page.waitForURL("**/user/sign_up");
|
|
|
|
|
|
|
|
await page.getByLabel("Username").fill(user.username);
|
|
|
|
await page.getByLabel("Email Address").fill(admin.email);
|
|
|
|
await page.getByLabel("Password", { exact: true }).fill(user.password);
|
|
|
|
await page.getByLabel("Confirm Password").fill(user.password);
|
|
|
|
|
|
|
|
await page.getByRole("button", { name: "Register Account" }).click();
|
|
|
|
|
|
|
|
await expect(page).toHaveTitle(
|
|
|
|
"Register - Forgejo: Beyond coding. We forge."
|
|
|
|
);
|
|
|
|
await page.locator(".negative > p:nth-child(1)").waitFor();
|
|
|
|
expect(page.locator(".negative > p:nth-child(1)")).toContainText(
|
|
|
|
"The email address is already used."
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2024-01-10 03:01:10 +05:30
|
|
|
test("Test successful registration", async ({ page }) => {
|
|
|
|
const user = new User("register");
|
|
|
|
|
|
|
|
console.log(`running with user ${user.username}`);
|
|
|
|
|
|
|
|
await page.goto(config.INSTANCE_URL.toString());
|
2024-01-09 23:31:52 +05:30
|
|
|
|
|
|
|
// successful registration
|
|
|
|
|
2024-01-10 02:32:55 +05:30
|
|
|
await user.register(page);
|
2024-01-09 23:31:52 +05:30
|
|
|
|
2024-01-10 02:06:26 +05:30
|
|
|
await page.waitForURL(config.INSTANCE_URL.toString());
|
2024-01-09 23:31:52 +05:30
|
|
|
await expect(page).toHaveTitle(
|
2024-01-10 01:57:49 +05:30
|
|
|
`${user.username} - Dashboard - Forgejo: Beyond coding. We forge.`
|
2024-01-09 23:31:52 +05:30
|
|
|
);
|
|
|
|
|
2024-01-10 01:54:34 +05:30
|
|
|
expect(page.locator(".positive > p:nth-child(1)")).toContainText(
|
2024-01-10 20:43:37 +05:30
|
|
|
"Account has been activated"
|
2024-01-10 01:54:34 +05:30
|
|
|
);
|
2024-01-09 23:31:52 +05:30
|
|
|
});
|
2024-01-10 03:01:10 +05:30
|
|
|
|
|
|
|
test("Test signout", async ({ page }) => {
|
|
|
|
const user = new User("signout");
|
|
|
|
|
|
|
|
// successful registration
|
|
|
|
await user.register(page);
|
|
|
|
await user.logout(page);
|
|
|
|
await expect(page).toHaveTitle("Forgejo: Beyond coding. We forge.");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Test login", async ({ page }) => {
|
|
|
|
const user = new User("login");
|
|
|
|
|
|
|
|
// successful registration
|
|
|
|
await user.register(page);
|
|
|
|
await user.logout(page);
|
|
|
|
await user.login(page);
|
|
|
|
await user.logout(page);
|
|
|
|
|
|
|
|
// sign in with email
|
|
|
|
await page.goto(config.INSTANCE_URL.toString());
|
|
|
|
await page.getByRole("link", { name: "Sign In" }).click();
|
|
|
|
await page.waitForURL("**/user/login**");
|
|
|
|
await page.getByLabel("Username").clear();
|
|
|
|
await page.getByLabel("Password", { exact: true }).clear();
|
|
|
|
await page.getByLabel("Username").fill(user.email);
|
|
|
|
await page.getByLabel("Password", { exact: true }).fill(user.password);
|
|
|
|
await page.getByRole("button", { name: "Sign In" }).click();
|
|
|
|
|
|
|
|
await expect(page).toHaveTitle(
|
|
|
|
`${user.username} - Dashboard - Forgejo: Beyond coding. We forge.`
|
|
|
|
);
|
|
|
|
});
|