sendou.ink/e2e/tournament-bracket.spec.ts
Kalle 144da5d158
Tournament groups->SE, underground bracket etc. (#1628)
* Renders groups

* Bracket data refactoring

* Starting bracket working (first bracket only)

* TODOs + crash fix

* Source bracket logic initial

* Bracket progression (DE underground bracket)

* Preview working for second bracket

* Bracket nav initial

* Check-in to bracket feature

* Start Underground bracket

* Team/teams pages tweaks to support underground bracket

* Underground bracket finalization progress

* Tournament class

* id -> userId + more useOutletContext removed

* Bracket loader refactored out

* Migrate admin to useTournament

* Bracket.settings

* Slim tournament loader

* Fix useEffect infinite loop

* Adjust waiting for teams text

* Refactor old tournament DB call from to admin

* Admin action: check in/out from specific bracket

* Standings work

* Back button from match page -> correct bracket

* Standings logic for DE grand finals

* Standings + finalize bracket

* Dev log

* Unit tests utils etc.

* Adjust TODOs

* Fix round robin issues

* Add RR tests

* Round robin standings initial

* Wins against tied + points tiebreaker progress

* Fix losing state when switching between tabs

* Add check-in indications to seeding page

* Link to user page on seed tool

* Submit points

* Total points from bracket manager

* findById gonezino

* Ahead of time check-in

* Couple todos

* Reopen logic refactor

* Tournament format settings

* RR->SE placements, skipping underground bracket

* Fix tournament team page round names

* More teams to UG bracket if first round of DE only byes

* Fix graphics bug

* Fixes

* Fix some E2E tests

* Fix E2E tests
2024-01-30 00:32:13 +02:00

228 lines
6.6 KiB
TypeScript

import { type Page, test, expect } from "@playwright/test";
import { ADMIN_DISCORD_ID } from "~/constants";
import { NZAP_TEST_ID } from "~/db/seed/constants";
import {
impersonate,
isNotVisible,
navigate,
seed,
submit,
} from "~/utils/playwright";
import {
tournamentBracketsPage,
tournamentPage,
userResultsPage,
} from "~/utils/urls";
import { startBracket } from "./shared";
const navigateToMatch = async (page: Page, matchId: number) => {
await expect(async () => {
await page.locator(`[data-match-id="${matchId}"]`).click();
await expect(page.getByTestId("match-header")).toBeVisible();
}).toPass();
};
const reportResult = async (
page: Page,
amountOfMapsToReport: 1 | 2 | 4,
sidesWithMoreThanFourPlayers: ("first" | "last")[] = ["last"],
winner: 1 | 2 = 1,
) => {
await page.getByTestId("tab-Report score").click();
if (sidesWithMoreThanFourPlayers.includes("first")) {
await page.getByTestId("player-checkbox-0").first().click();
await page.getByTestId("player-checkbox-1").first().click();
await page.getByTestId("player-checkbox-2").first().click();
await page.getByTestId("player-checkbox-3").first().click();
}
if (sidesWithMoreThanFourPlayers.includes("last")) {
await page.getByTestId("player-checkbox-0").last().click();
await page.getByTestId("player-checkbox-1").last().click();
await page.getByTestId("player-checkbox-2").last().click();
await page.getByTestId("player-checkbox-3").last().click();
}
await page.getByTestId(`winner-radio-${winner}`).click();
await page.getByTestId("report-score-button").click();
await expect(page.getByText(winner === 1 ? "1-0" : "0-1")).toBeVisible();
if (amountOfMapsToReport >= 2) {
await page.getByTestId(`winner-radio-${winner}`).click();
await page.getByTestId("report-score-button").click();
if (amountOfMapsToReport === 2) {
await expect(page.getByTestId("report-timestamp")).toBeVisible();
}
}
if (amountOfMapsToReport === 4) {
await expect(page.getByText("2-0")).toBeVisible();
await page.getByTestId(`winner-radio-${winner}`).click();
await page.getByTestId("report-score-button").click();
await expect(page.getByText("3-0")).toBeVisible();
await page.getByTestId(`winner-radio-${winner}`).click();
await page.getByTestId("report-score-button").click();
await expect(page.getByTestId("report-timestamp")).toBeVisible();
}
};
const backToBracket = async (page: Page) => {
await page.getByTestId("back-to-bracket-button").click();
await expect(page.getByTestId("brackets-viewer")).toBeVisible();
};
const expectScore = (page: Page, score: [number, number]) =>
expect(page.getByText(score.join("-"))).toBeVisible();
// 1) Report winner of N-ZAP's first match
// 2) Report winner of the adjacent match by using admin powers
// 3) Report one match on the only losers side match available
// 4) Try to reopen N-ZAP's first match and fail
// 5) Undo score of first losers match
// 6) Try to reopen N-ZAP's first match and succeed
// 7) As N-ZAP, undo all scores and switch to different team sweeping
test.describe("Tournament bracket", () => {
test("reports score and sees bracket update", async ({ page }) => {
const tournamentId = 2;
await startBracket(page);
await impersonate(page, NZAP_TEST_ID);
await navigate({
page,
url: tournamentBracketsPage({ tournamentId }),
});
// 1)
await page.locator('[data-match-id="5"]').click();
await reportResult(page, tournamentId);
await backToBracket(page);
// 2)
await impersonate(page);
await navigate({
page,
url: tournamentBracketsPage({ tournamentId }),
});
await navigateToMatch(page, 6);
await reportResult(page, 2);
await backToBracket(page);
// 3)
await navigateToMatch(page, 18);
await reportResult(page, 1, ["first", "last"]);
await backToBracket(page);
// 4)
await navigateToMatch(page, 5);
await isNotVisible(page.getByTestId("reopen-match-button"));
await backToBracket(page);
// 5)
await navigateToMatch(page, 18);
await page.getByTestId("undo-score-button").click();
await expectScore(page, [0, 0]);
await backToBracket(page);
// 6)
await navigateToMatch(page, 5);
await page.getByTestId("reopen-match-button").click();
await expectScore(page, [1, 0]);
// 7)
await impersonate(page, NZAP_TEST_ID);
await navigate({
page,
url: tournamentBracketsPage({ tournamentId }),
});
await navigateToMatch(page, 5);
await page.getByTestId("undo-score-button").click();
await expectScore(page, [0, 0]);
await reportResult(page, 2, ["last"], 2);
await backToBracket(page);
await expect(
page.locator("[data-round-id='5'] [data-participant-id='102']"),
).toBeVisible();
});
test("adds a sub mid tournament (from non checked in team)", async ({
page,
}) => {
const tournamentId = 1;
await startBracket(page, tournamentId);
// captain of the first team
await impersonate(page, 5);
await navigate({
page,
url: tournamentBracketsPage({ tournamentId }),
});
await page.getByTestId("add-sub-button").click();
await page.getByTestId("copy-invite-link-button").click();
const inviteLinkProd: string = await page.evaluate(
"navigator.clipboard.readText()",
);
const inviteLink = inviteLinkProd.replace(
"https://sendou.ink",
"http://localhost:5800",
);
await impersonate(page, NZAP_TEST_ID);
await navigate({
page,
url: inviteLink,
});
await submit(page);
await expect(page).toHaveURL(/brackets/);
});
test("completes and finalizes a small tournament", async ({ page }) => {
const tournamentId = 2;
await seed(page);
await impersonate(page);
await navigate({
page,
url: tournamentPage(tournamentId),
});
await page.getByTestId("admin-tab").click();
await page.getByLabel("Action").selectOption("CHECK_OUT");
for (let id = 103; id < 117; id++) {
await page.getByLabel("Team").selectOption(String(id));
await submit(page);
}
await navigate({
page,
url: tournamentBracketsPage({ tournamentId }),
});
await page.getByTestId("finalize-bracket-button").click();
await page.locator('[data-match-id="1"]').click();
await reportResult(page, 4, []);
await backToBracket(page);
await page.getByTestId("finalize-tournament-button").click();
await page.getByTestId("confirm-button").click();
await navigate({
page,
url: userResultsPage({ discordId: ADMIN_DISCORD_ID }),
});
await expect(page.getByText("In The Zone 22")).toBeVisible();
});
});