mirror of
https://github.com/OHTU-German-learning-website/OHTU-German-learning-website.git
synced 2026-10-12 19:13:51 +03:00
91 lines
2.3 KiB
JavaScript
91 lines
2.3 KiB
JavaScript
import { test, expect } from "@playwright/test";
|
|
|
|
async function gotoClickExerciseList(page) {
|
|
await page.goto("grammar/exercises/click", {
|
|
waitUntil: "domcontentloaded",
|
|
timeout: 60000,
|
|
});
|
|
}
|
|
|
|
function isOnLogin(url) {
|
|
return url.includes("/auth/login") || url.includes("/auth/register");
|
|
}
|
|
|
|
test.describe("Klick-Übungen", () => {
|
|
test("should load click exercises list or redirect to login", async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(60000);
|
|
|
|
await gotoClickExerciseList(page);
|
|
|
|
const currentUrl = page.url();
|
|
if (isOnLogin(currentUrl)) {
|
|
await expect(page).toHaveURL(/\/auth\/(login|register)\?redirect=/);
|
|
return;
|
|
}
|
|
|
|
await expect(page).toHaveURL(/\/grammar\/exercises\/click/);
|
|
await expect(
|
|
page.getByRole("heading", { name: /Klick-Übungen/i })
|
|
).toBeVisible();
|
|
});
|
|
|
|
test("should show exercise links or empty state", async ({ page }) => {
|
|
test.setTimeout(60000);
|
|
|
|
await gotoClickExerciseList(page);
|
|
|
|
const currentUrl = page.url();
|
|
if (isOnLogin(currentUrl)) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
const exerciseLinks = page.locator('a[href*="/grammar/exercises/click/"]');
|
|
const emptyState = page.getByText("Zurzeit sind keine Übungen verfügbar.");
|
|
|
|
const linkCount = await exerciseLinks.count();
|
|
if (linkCount > 0) {
|
|
await expect(exerciseLinks.first()).toBeVisible();
|
|
} else {
|
|
await expect(emptyState).toBeVisible();
|
|
}
|
|
});
|
|
|
|
test("should open a click exercise detail page when available", async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(60000);
|
|
|
|
await gotoClickExerciseList(page);
|
|
|
|
const currentUrl = page.url();
|
|
if (isOnLogin(currentUrl)) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
const exerciseLinks = page.locator('a[href*="/grammar/exercises/click/"]');
|
|
const linkCount = await exerciseLinks.count();
|
|
|
|
if (linkCount === 0) {
|
|
test.skip();
|
|
return;
|
|
}
|
|
|
|
const href = await exerciseLinks.first().getAttribute("href");
|
|
expect(href).toBeTruthy();
|
|
|
|
await page.goto(href, { waitUntil: "domcontentloaded", timeout: 60000 });
|
|
|
|
await expect(page).toHaveURL(
|
|
new RegExp(href.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
);
|
|
await expect(page.getByRole("heading").first()).toBeVisible();
|
|
await expect(
|
|
page.getByRole("button", { name: /Antworten überprüfen/i })
|
|
).toBeVisible();
|
|
});
|
|
});
|