forked from cms/tibi-svelte-starter
✨ feat: add admin smoke tests and enhance testing documentation with new strategies and configurations
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import { test as base, expect, type Page } from "@playwright/test"
|
||||
import { attachConsoleMonitor } from "../fixtures/console-monitor"
|
||||
import { ADMIN_UI_CREDENTIALS, TEST_ADMIN_BASE_URL } from "../fixtures/test-constants"
|
||||
|
||||
export const test = base.extend({
|
||||
page: async ({ page }, use) => {
|
||||
const monitor = attachConsoleMonitor(page)
|
||||
|
||||
const origGoto = page.goto.bind(page)
|
||||
const origReload = page.reload.bind(page)
|
||||
|
||||
page.goto = ((url: string, opts?: any) =>
|
||||
origGoto(url, { waitUntil: "domcontentloaded", ...opts })) as typeof page.goto
|
||||
page.reload = ((opts?: any) => origReload({ waitUntil: "domcontentloaded", ...opts })) as typeof page.reload
|
||||
|
||||
await use(page)
|
||||
monitor.assertNoErrors()
|
||||
},
|
||||
})
|
||||
|
||||
export async function loginToAdmin(page: Page): Promise<void> {
|
||||
await page.goto(`${TEST_ADMIN_BASE_URL}/login`)
|
||||
|
||||
await page.getByLabel(/Benutzername|Username/i).fill(ADMIN_UI_CREDENTIALS.username)
|
||||
await page.getByLabel(/Passwort|Password/i).fill(ADMIN_UI_CREDENTIALS.password)
|
||||
await page.getByRole("button", { name: /Anmelden|Sign in|Login/i }).click()
|
||||
|
||||
await expect(page).toHaveURL(/\/projects\//, { timeout: 15000 })
|
||||
await expect(page.locator("main")).toBeVisible()
|
||||
}
|
||||
|
||||
export async function openNovaProjectDashboard(page: Page): Promise<void> {
|
||||
await loginToAdmin(page)
|
||||
|
||||
const germanLocaleButton = page.getByRole("button", { name: /^Deutsch$/ })
|
||||
if ((await germanLocaleButton.count()) > 0) {
|
||||
await germanLocaleButton.first().click()
|
||||
}
|
||||
|
||||
const openNovaButton = page.getByRole("button", { name: /Nova öffnen|Open Nova/i })
|
||||
if ((await openNovaButton.count()) > 0 && (await openNovaButton.first().isVisible())) {
|
||||
await openNovaButton.first().click()
|
||||
}
|
||||
|
||||
await expect(page.getByRole("textbox", { name: /Kollektionen durchsuchen|Search collections/i })).toBeVisible({
|
||||
timeout: 15000,
|
||||
})
|
||||
}
|
||||
|
||||
export async function openContentCollection(page: Page): Promise<void> {
|
||||
await openNovaProjectDashboard(page)
|
||||
await page
|
||||
.getByRole("link", { name: /Inhalte/ })
|
||||
.first()
|
||||
.click()
|
||||
|
||||
await expect(page).toHaveURL(/\/collections\/content$/)
|
||||
await expect(page.locator("main h1")).toHaveText("Inhalte")
|
||||
}
|
||||
|
||||
export async function openNewContentEntry(page: Page): Promise<void> {
|
||||
await openContentCollection(page)
|
||||
await page.getByRole("button", { name: /Neuer Eintrag|New Entry/i }).click()
|
||||
|
||||
await expect(page).toHaveURL(/\/collections\/content\/entries\/new/)
|
||||
await expect(page.getByRole("heading", { level: 1, name: /Neuer Eintrag|New Entry/i })).toBeVisible()
|
||||
}
|
||||
|
||||
export { expect, type Page }
|
||||
Reference in New Issue
Block a user