Some checks failed
docker-images / resolve-build-targets (push) Successful in 6s
ui-regression / playwright-regression (push) Failing after 13m44s
docker-images / build-and-push (admin) (push) Successful in 1m13s
docker-images / build-and-push (backend) (push) Successful in 45m36s
docker-images / build-and-push (frontend) (push) Successful in 1m29s
docker-images / submit-indexnow (push) Successful in 18s
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { expect, type APIRequestContext, type Page } from '@playwright/test'
|
||
|
||
export const MOCK_BASE_URL = 'http://127.0.0.1:5159'
|
||
export const ADMIN_COOKIE = {
|
||
name: 'termi_admin_session',
|
||
value: 'mock-admin-session',
|
||
domain: '127.0.0.1',
|
||
path: '/',
|
||
}
|
||
|
||
export async function resetMockState(request: APIRequestContext) {
|
||
const response = await request.post(`${MOCK_BASE_URL}/__playwright/reset`)
|
||
expect(response.ok()).toBeTruthy()
|
||
}
|
||
|
||
export async function getDebugState(request: APIRequestContext) {
|
||
const response = await request.get(`${MOCK_BASE_URL}/__playwright/state`)
|
||
expect(response.ok()).toBeTruthy()
|
||
return response.json()
|
||
}
|
||
|
||
export async function patchAdminSiteSettings(
|
||
request: APIRequestContext,
|
||
payload: Record<string, unknown>,
|
||
) {
|
||
const response = await request.patch(`${MOCK_BASE_URL}/api/admin/site-settings`, {
|
||
headers: {
|
||
cookie: `${ADMIN_COOKIE.name}=${ADMIN_COOKIE.value}`,
|
||
},
|
||
data: payload,
|
||
})
|
||
expect(response.ok()).toBeTruthy()
|
||
return response.json()
|
||
}
|
||
|
||
export async function waitForHomeInteractive(page: Page) {
|
||
await page.waitForFunction(
|
||
() => (window as Window & { __termiHomeReady?: boolean }).__termiHomeReady === true,
|
||
)
|
||
}
|
||
|
||
export async function waitForCommentsReady(page: Page) {
|
||
await page.waitForFunction(
|
||
() => (window as Window & { __termiCommentsReady?: boolean }).__termiCommentsReady === true,
|
||
)
|
||
}
|
||
|
||
export async function waitForSubscriptionPopupReady(page: Page) {
|
||
await page.waitForFunction(
|
||
() =>
|
||
(window as Window & { __termiSubscriptionPopupReady?: boolean })
|
||
.__termiSubscriptionPopupReady === true,
|
||
)
|
||
}
|
||
|
||
export async function loginAdmin(page: Page) {
|
||
await page.goto('/login')
|
||
await page.getByLabel('用户名').fill('admin')
|
||
await page.getByLabel('密码').fill('admin123')
|
||
await page.getByRole('button', { name: '进入后台' }).click()
|
||
await expect(page).toHaveURL(/\/$/)
|
||
await expect(page.getByText('当前登录:admin')).toBeVisible()
|
||
}
|