mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-06 21:34:28 -05:00
* Initial * Progress * Initial UI * Can submit request * Progress * Show text if no scrims * Can cancel request, tabs * Delete post * Popover if can't delete * Request rows * Progress * Scrim page initial * Fix migration order * Progress * Progress * Works again * Make it compile * Make it compile again * Work * Progress * Progress * Progress * Associations initial * Association visibility work * notFoundVisibility form fields initial * Progress * Association leave/join + reset invite code * Progress * Select test * Merge branch 'rewrite' into scrims * Remeda for groupBy * Select with search * Outline styling for select * Select done? * Fix prop names * Paginated badges * Less important * Select no results * Handle limiting select width * UserSearch non-working * Fix problem from merge * Remove UserSearch for now * Remove todo * Flaggable * Remove TODOs * i18n start + styling * Progress * i18n done * Add association e2e test * E2E tests * Done? * Couple leftovers
107 lines
2.7 KiB
TypeScript
107 lines
2.7 KiB
TypeScript
import { type Locator, type Page, expect } from "@playwright/test";
|
|
import { ADMIN_ID } from "~/constants";
|
|
import type { SeedVariation } from "~/features/api-private/routes/seed";
|
|
import { tournamentBracketsPage } from "./urls";
|
|
|
|
export async function selectWeapon({
|
|
page,
|
|
name,
|
|
inputName = "weapon",
|
|
}: {
|
|
page: Page;
|
|
name: string;
|
|
inputName?: string;
|
|
}) {
|
|
return selectComboboxValue({ page, value: name, inputName });
|
|
}
|
|
|
|
export async function selectUser({
|
|
page,
|
|
userName,
|
|
labelName,
|
|
}: {
|
|
page: Page;
|
|
userName: string;
|
|
labelName: string;
|
|
}) {
|
|
const combobox = page.getByLabel(labelName);
|
|
await expect(combobox).not.toBeDisabled();
|
|
|
|
await combobox.clear();
|
|
await combobox.fill(userName);
|
|
await expect(page.getByTestId("combobox-option-0")).toBeVisible();
|
|
await page.keyboard.press("Enter");
|
|
}
|
|
|
|
export async function selectComboboxValue({
|
|
page,
|
|
value,
|
|
inputName,
|
|
locator,
|
|
}: {
|
|
page: Page;
|
|
value: string;
|
|
inputName?: string;
|
|
locator?: Locator;
|
|
}) {
|
|
if (!locator && !inputName) {
|
|
throw new Error("Must provide either locator or inputName");
|
|
}
|
|
const combobox = locator ?? page.getByTestId(`${inputName!}-combobox-input`);
|
|
await combobox.clear();
|
|
await combobox.fill(value);
|
|
await combobox.press("Enter");
|
|
}
|
|
|
|
/** page.goto that waits for the page to be hydrated before proceeding */
|
|
export async function navigate({ page, url }: { page: Page; url: string }) {
|
|
await page.goto(url);
|
|
await expect(page.getByTestId("hydrated")).toHaveCount(1);
|
|
}
|
|
|
|
export function seed(page: Page, variation?: SeedVariation) {
|
|
return page.request.post("/seed", {
|
|
form: { variation: variation ?? "DEFAULT" },
|
|
});
|
|
}
|
|
|
|
export function impersonate(page: Page, userId = ADMIN_ID) {
|
|
return page.request.post(`/auth/impersonate?id=${userId}`);
|
|
}
|
|
|
|
export async function submit(page: Page, testId?: string) {
|
|
const responsePromise = page.waitForResponse(
|
|
(res) => res.request().method() === "POST",
|
|
);
|
|
await page.getByTestId(testId ?? "submit-button").click();
|
|
await responsePromise;
|
|
}
|
|
|
|
export function isNotVisible(locator: Locator) {
|
|
return expect(locator).toHaveCount(0);
|
|
}
|
|
|
|
export function modalClickConfirmButton(page: Page) {
|
|
return page.getByTestId("confirm-button").click();
|
|
}
|
|
|
|
export async function fetchSendouInk<T>(url: string) {
|
|
const res = await fetch(`http://localhost:5173${url}`);
|
|
if (!res.ok) throw new Error("Response not successful");
|
|
|
|
return res.json() as T;
|
|
}
|
|
|
|
export const startBracket = async (page: Page, tournamentId = 2) => {
|
|
await seed(page);
|
|
await impersonate(page);
|
|
|
|
await navigate({
|
|
page,
|
|
url: tournamentBracketsPage({ tournamentId }),
|
|
});
|
|
|
|
await page.getByTestId("finalize-bracket-button").click();
|
|
await page.getByTestId("confirm-finalize-bracket-button").click();
|
|
};
|