e2e tests for my pages * feature/add-e2e-tests-for-mypages * remove unneccesary awaits Approved-by: Linus Flood
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { expect, type Page } from "@playwright/test"
|
|
|
|
const AUTH_URL_REGEX =
|
|
/https:\/\/.*\.scandichotels\.com\/authn\/authenticate\/scandic/i
|
|
|
|
export async function performLogin({
|
|
page,
|
|
username,
|
|
password,
|
|
}: {
|
|
page: Page
|
|
username: string
|
|
password: string
|
|
}) {
|
|
await page.goto("/en")
|
|
const loginLink = page.getByRole("link", { name: /log in\/join/i })
|
|
await expect(loginLink).not.toBeDisabled()
|
|
|
|
await loginLink.click()
|
|
|
|
await expect(page).toHaveURL(AUTH_URL_REGEX)
|
|
|
|
// Fill in the login form
|
|
|
|
const usernameTextBox = page.getByRole("textbox", {
|
|
name: /email \/ membership number/i,
|
|
})
|
|
await usernameTextBox.fill(username)
|
|
|
|
const passwordTextBox = page.getByRole("textbox", { name: /password/i })
|
|
await passwordTextBox.fill(password)
|
|
|
|
const signInButton = page.getByRole("button", { name: /log in/i })
|
|
await signInButton.click()
|
|
|
|
const profileButton = await getProfileButton(page)
|
|
await expect(profileButton).toBeVisible()
|
|
}
|
|
|
|
export async function getProfileButton(page: Page) {
|
|
return page.getByRole("button", {
|
|
name: /^\p{L}{2} hi \p{L}+!/iu,
|
|
})
|
|
}
|