Fix tests by generating random lowercase strings for prefixes

This commit is contained in:
thiloho
2024-10-04 20:48:21 +02:00
parent e96b78b7ce
commit 5ebd40966c
2 changed files with 16 additions and 6 deletions

View File

@@ -1,11 +1,14 @@
import { test, expect } from "@playwright/test"; import { test, expect } from "@playwright/test";
import { randomBytes } from "node:crypto"; import { randomBytes } from "node:crypto";
import { platform } from "node:os";
const username = randomBytes(8).toString("hex"); const username = randomBytes(8).toString("hex");
const collabUsername = randomBytes(8).toString("hex"); const collabUsername = randomBytes(8).toString("hex");
const collabUsername2 = randomBytes(8).toString("hex"); const collabUsername2 = randomBytes(8).toString("hex");
const collabUsername3 = randomBytes(8).toString("hex"); const collabUsername3 = randomBytes(8).toString("hex");
const collabUsername4 = randomBytes(8).toString("hex"); const collabUsername4 = randomBytes(8).toString("hex");
const customPrefix = Buffer.from(randomBytes(16).map((byte) => (byte % 26) + 97)).toString();
const customPrefix2 = Buffer.from(randomBytes(16).map((byte) => (byte % 26) + 97)).toString();
const password = "T3stuser??!!"; const password = "T3stuser??!!";
const permissionLevels = [10, 20, 30]; const permissionLevels = [10, 20, 30];
@@ -57,7 +60,7 @@ test.describe.serial("Collaborator tests", () => {
await page.getByRole("link", { name: "Publish" }).click(); await page.getByRole("link", { name: "Publish" }).click();
await page.getByRole("button", { name: "Publish" }).click(); await page.getByRole("button", { name: "Publish" }).click();
await page.getByLabel("Prefix:").click(); await page.getByLabel("Prefix:").click();
await page.getByLabel("Prefix:").fill("setup"); await page.getByLabel("Prefix:").fill(customPrefix);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await page.goto("/"); await page.goto("/");
@@ -458,8 +461,13 @@ test.describe.serial("Collaborator tests", () => {
test("Set custom domain prefix", async ({ page }) => { test("Set custom domain prefix", async ({ page }) => {
await page.getByRole("link", { name: "Blog" }).click(); await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Publish" }).click(); await page.getByRole("link", { name: "Publish" }).click();
const isMac = platform() === "darwin";
const modifier = isMac ? "Meta" : "Control";
await page.getByLabel("Prefix:").click(); await page.getByLabel("Prefix:").click();
await page.getByLabel("Prefix:").fill("blog"); await page.keyboard.press(`${modifier}+A`);
await page.keyboard.press(`Backspace`);
await page.getByLabel("Prefix:").fill(customPrefix2);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
if ([10, 20].includes(permissionLevel)) { if ([10, 20].includes(permissionLevel)) {

View File

@@ -9,6 +9,8 @@ const __dirname = dirname(__filename);
const username = randomBytes(8).toString("hex"); const username = randomBytes(8).toString("hex");
const collabUsername = randomBytes(8).toString("hex"); const collabUsername = randomBytes(8).toString("hex");
const customPrefix = Buffer.from(randomBytes(16).map((byte) => (byte % 26) + 97)).toString();
const customPrefix2 = Buffer.from(randomBytes(16).map((byte) => (byte % 26) + 97)).toString();
const password = "T3stuser??!!"; const password = "T3stuser??!!";
const test = base.extend<{ authenticatedPage: Page }>({ const test = base.extend<{ authenticatedPage: Page }>({
@@ -189,12 +191,12 @@ test.describe.serial("Website tests", () => {
const clipPage = await context.newPage(); const clipPage = await context.newPage();
await clipPage.goto("https://picsum.photos/400/400.jpg"); await clipPage.goto("https://picsum.photos/400/400.jpg");
await clipPage.keyboard.press(`${modifier}+KeyC`); await clipPage.keyboard.press(`${modifier}+C`);
await page.bringToFront(); await page.bringToFront();
await page.keyboard.press("Enter"); await page.keyboard.press("Enter");
await page.keyboard.press("Enter"); await page.keyboard.press("Enter");
await page.keyboard.press(`${modifier}+KeyV`); await page.keyboard.press(`${modifier}+V`);
await expect(page.getByText("Successfully uploaded image")).toBeVisible(); await expect(page.getByText("Successfully uploaded image")).toBeVisible();
}); });
@@ -353,7 +355,7 @@ test.describe.serial("Website tests", () => {
await page.getByRole("link", { name: "Blog" }).click(); await page.getByRole("link", { name: "Blog" }).click();
await page.getByRole("link", { name: "Publish" }).click(); await page.getByRole("link", { name: "Publish" }).click();
await page.getByLabel("Prefix:").click(); await page.getByLabel("Prefix:").click();
await page.getByLabel("Prefix:").fill("blog"); await page.getByLabel("Prefix:").fill(customPrefix);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully created/updated")).toBeVisible(); await expect(page.getByText("Successfully created/updated")).toBeVisible();
@@ -361,7 +363,7 @@ test.describe.serial("Website tests", () => {
await page.getByRole("link", { name: "Documentation" }).click(); await page.getByRole("link", { name: "Documentation" }).click();
await page.getByRole("link", { name: "Publish" }).click(); await page.getByRole("link", { name: "Publish" }).click();
await page.getByLabel("Prefix:").click(); await page.getByLabel("Prefix:").click();
await page.getByLabel("Prefix:").fill("docs"); await page.getByLabel("Prefix:").fill(customPrefix2);
await page.getByRole("button", { name: "Submit" }).click(); await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText("Successfully created/updated")).toBeVisible(); await expect(page.getByText("Successfully created/updated")).toBeVisible();
}); });