import { expect, test } from '@playwright/test' import postgres from 'postgres' test('멤버 댓글 페이지 이동·게시물 링크와 대시보드 최근 댓글을 표시한다', async ({ page }) => { const database = postgres(process.env.DATABASE_URL, { max: 1 }) let postId try { const login = await page.request.post('/admin/api/auth/login', { data: { email: 'playwright-admin@example.com', password: 'playwright-admin-password' } }) expect(login.ok()).toBeTruthy() const admin = await login.json() const created = await page.request.post('/admin/api/posts', { data: { title: '댓글 화면 검증 게시물', slug: 'comments-ui-test', content: '본문', status: 'published', tags: [], tagNames: {} } }) expect(created.ok()).toBeTruthy() postId = (await created.json()).id for (let index = 0; index < 11; index += 1) { await database` INSERT INTO comments (post_id, user_id, body, created_at) VALUES (${postId}, ${admin.userId}, ${`화면 댓글 ${index}`}, now() + ${index} * interval '1 second') ` } await page.goto(`/admin/members/${admin.userId}`) await page.waitForLoadState('networkidle') await expect(page.locator('.admin-member-activity')).toHaveCount(0) await page.getByRole('button', { name: '작성한 댓글', exact: true }).click() const list = page.locator('.admin-member-activity') await expect(list.locator('.admin-member-activity__item')).toHaveCount(10) await expect(list.locator('.admin-member-activity__body').first()).toHaveText('화면 댓글 10') await expect(list.getByRole('link', { name: '게시물 보기' }).first()).toHaveAttribute('href', '/post/comments-ui-test#comments') await list.getByRole('button', { name: '다음 페이지' }).click() await expect(list.locator('.admin-member-activity__item')).toHaveCount(1) await expect(list.locator('.admin-member-activity__body')).toHaveText('화면 댓글 0') await list.getByRole('button', { name: '이전 페이지' }).click() await expect(list.locator('.admin-member-activity__item')).toHaveCount(10) await list.getByLabel('작성한 댓글 검색').fill('화면 댓글 0') await list.getByRole('button', { name: '검색', exact: true }).click() await expect(list.locator('.admin-member-activity__item')).toHaveCount(1) await expect(list.locator('.admin-member-activity__body')).toHaveText('화면 댓글 0') await list.getByLabel('작성한 댓글 검색').fill('결과없음') await list.getByRole('button', { name: '검색', exact: true }).click() await expect(list).toContainText('검색 결과가 없습니다.') await page.getByRole('button', { name: '작성한 글', exact: true }).click() await expect(page.locator('.admin-member-activity__item')).toHaveCount(1) await page.getByLabel('작성한 글 검색').fill('없는글') await page.locator('.admin-member-activity').getByRole('button', { name: '검색', exact: true }).click() await expect(page.locator('.admin-member-activity')).toContainText('검색 결과가 없습니다.') await page.getByRole('button', { name: '정보', exact: true }).click() await expect(page.locator('.admin-member-form__body')).toBeVisible() await page.goto('/admin') await expect(page.locator('.admin-comment-list__item')).toHaveCount(5) await expect(page.locator('.admin-comment-list__body').first()).toHaveText('화면 댓글 10') await expect(page.locator('.admin-dashboard__csp')).toHaveCount(0) const recentBox = await page.locator('.admin-comment-list').boundingBox() expect(recentBox.height).toBeLessThan(250) await page.goto('/admin/posts') const row = page.locator('.admin-posts__row').filter({ hasText: '댓글 화면 검증 게시물' }) await expect(row.locator('.admin-posts__comment-count')).toHaveText('11') } finally { if (postId) await database`DELETE FROM posts WHERE id = ${postId}` await database.end() } })