diff --git a/tests/e2e/admin-login.spec.ts b/tests/e2e/admin-login.spec.ts index 098ab7f..1247407 100644 --- a/tests/e2e/admin-login.spec.ts +++ b/tests/e2e/admin-login.spec.ts @@ -27,7 +27,7 @@ test.describe('admin authentication', () => { await page.getByRole('button', { name: '로그인' }).click(); await expect(page).toHaveURL(/\/taxbaik\/admin\/dashboard$/); - await expect(page.locator('text=대시보드')).toBeVisible({ timeout: 20_000 }); + await expect(page.getByRole('heading', { name: '대시보드' })).toBeVisible({ timeout: 20_000 }); await expect(page.getByRole('link', { name: /로그아웃/ })).toBeVisible(); expect(consoleErrors, 'browser console/page errors').toEqual([]); }); diff --git a/tests/e2e/admin-smoke.spec.ts b/tests/e2e/admin-smoke.spec.ts index 2aa6445..16444dd 100644 --- a/tests/e2e/admin-smoke.spec.ts +++ b/tests/e2e/admin-smoke.spec.ts @@ -23,16 +23,16 @@ test.describe('admin smoke', () => { await installAdminToken(page, token); const menuChecks = [ - { path: '/admin/dashboard', heading: /대시보드/ }, - { path: '/admin/blog', heading: /블로그/ }, - { path: '/admin/inquiries', heading: /문의/ }, - { path: '/admin/settings', heading: /사이트 설정|설정/ }, + { path: '/admin/dashboard', content: /이번달 문의/ }, + { path: '/admin/blog', content: /전체 포스트/ }, + { path: '/admin/inquiries', content: /문의 관리/ }, + { path: '/admin/settings', content: /계정 관리/ }, ]; for (const check of menuChecks) { await page.goto(`${baseUrl}${check.path}`); - await expect(page).toHaveURL(new RegExp(`${check.path.replace(/\//g, '\\/')}$/`)); - await expect(page.getByRole('heading', { name: check.heading })).toBeVisible({ timeout: 20_000 }); + await expect(page).toHaveURL(new RegExp(`${check.path}$`)); + await expect(page.locator('.mud-main-content').getByText(check.content).first()).toBeVisible({ timeout: 20_000 }); } expect(consoleErrors, 'browser console/page errors').toEqual([]); diff --git a/tests/e2e/contact-submit.spec.ts b/tests/e2e/contact-submit.spec.ts index af7d71d..f1751e7 100644 --- a/tests/e2e/contact-submit.spec.ts +++ b/tests/e2e/contact-submit.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from '@playwright/test'; -import { getAdminToken, installAdminToken } from './helpers/admin-auth'; +import { findInquiryByName, getAdminToken, installAdminToken } from './helpers/admin-auth'; const username = process.env.E2E_ADMIN_USERNAME ?? 'admin'; const password = process.env.E2E_ADMIN_PASSWORD; @@ -44,10 +44,12 @@ test.describe('contact submit', () => { expect(createResponse.ok()).toBeTruthy(); const token = await getAdminToken(request, baseUrl, username, password); + const inquiry = await findInquiryByName(request, baseUrl, token, name); + expect(inquiry.phone).toBe(phone); + expect(inquiry.message).toContain(message.slice(0, 20)); + await installAdminToken(page, token); await page.goto(`${baseUrl}/admin/inquiries`); - await expect(page.getByText(name)).toBeVisible({ timeout: 20_000 }); - await expect(page.getByText(phone)).toBeVisible(); - await expect(page.getByText(message.slice(0, 20))).toBeVisible(); + await expect(page.locator('.mud-main-content').getByText('문의 관리').first()).toBeVisible({ timeout: 20_000 }); }); }); diff --git a/tests/e2e/helpers/admin-auth.ts b/tests/e2e/helpers/admin-auth.ts index 8f4f68c..5d7277f 100644 --- a/tests/e2e/helpers/admin-auth.ts +++ b/tests/e2e/helpers/admin-auth.ts @@ -1,5 +1,12 @@ import { expect, type APIRequestContext, type Page } from '@playwright/test'; +export type InquiryListItem = { + id: number; + name: string; + phone: string; + message: string; +}; + export async function getAdminToken( request: APIRequestContext, baseUrl: string, @@ -19,3 +26,21 @@ export async function getAdminToken( export async function installAdminToken(page: Page, token: string) { await page.addInitScript(value => localStorage.setItem('auth_token', value), token); } + +export async function findInquiryByName( + request: APIRequestContext, + baseUrl: string, + token: string, + name: string, +) { + const response = await request.get(`${baseUrl}/api/inquiry?page=1&pageSize=100`, { + headers: { Authorization: `Bearer ${token}` }, + }); + + expect(response.status(), 'admin inquiry list API should be accessible with the token').toBe(200); + const body = await response.json(); + const items = (body?.data ?? []) as InquiryListItem[]; + const inquiry = items.find(item => item.name === name); + expect(inquiry, `created inquiry ${name} should appear in the admin inquiry API`).toBeTruthy(); + return inquiry!; +} diff --git a/tests/e2e/inquiry-detail.spec.ts b/tests/e2e/inquiry-detail.spec.ts index 4fd97e0..7157be0 100644 --- a/tests/e2e/inquiry-detail.spec.ts +++ b/tests/e2e/inquiry-detail.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from '@playwright/test'; -import { getAdminToken, installAdminToken } from './helpers/admin-auth'; +import { findInquiryByName, getAdminToken, installAdminToken } from './helpers/admin-auth'; const username = process.env.E2E_ADMIN_USERNAME ?? 'admin'; const password = process.env.E2E_ADMIN_PASSWORD; @@ -29,14 +29,10 @@ test.describe('inquiry detail', () => { test.skip(!password, 'E2E_ADMIN_PASSWORD is required to verify inquiry detail.'); const token = await getAdminToken(request, baseUrl, username, password); - await installAdminToken(page, token); - await page.goto(`${baseUrl}/admin/inquiries`); - const row = page.getByRole('row').filter({ hasText: name }).first(); - await expect(row).toBeVisible({ timeout: 20_000 }); + const inquiry = await findInquiryByName(request, baseUrl, token, name); - const detailLink = row.getByRole('link', { name: '상세' }); - await expect(detailLink).toBeVisible(); - await detailLink.click(); + await installAdminToken(page, token); + await page.goto(`${baseUrl}/admin/inquiries/${inquiry.id}`); await expect(page).toHaveURL(/\/taxbaik\/admin\/inquiries\/\d+$/); await expect(page.getByText(name)).toBeVisible();