Files
sori.studio/tests/playwright/e2e/admin-comments.spec.js

77 lines
4.5 KiB
JavaScript

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 expect(page.getByRole('button', { name: '작성한 댓글', exact: true })).toHaveCount(0)
await page.getByRole('button', { name: '작성한 글', exact: true }).click()
const list = page.locator('.admin-member-activity')
const items = list.locator('.admin-member-activity__item')
await expect(items).toHaveCount(10)
await expect(list.locator('.admin-member-activity__body').first()).toHaveText('화면 댓글 10')
await expect(list.locator('.admin-member-activity__post').first()).toHaveAttribute('href', '/post/comments-ui-test#comments')
await list.getByRole('button', { name: '다음 페이지' }).click()
await expect(items).toHaveCount(2)
await expect(list.getByRole('columnheader')).toHaveText(['게시글', '내용', '작성일'])
await expect(list.locator('.admin-member-activity__body').last()).toHaveText('본문')
await list.getByLabel('작성 종류').selectOption('comment')
await expect(items).toHaveCount(10)
await list.getByRole('button', { name: '다음 페이지' }).click()
await expect(items).toHaveCount(1)
await list.getByLabel('작성한 글 검색').fill('화면 댓글 0')
await list.getByRole('button', { name: '검색', exact: true }).click()
await expect(items).toHaveCount(1)
await expect(list.locator('.admin-member-activity__body')).toHaveText('화면 댓글 0')
await list.getByLabel('작성 종류').selectOption('post')
await expect(list).toContainText('검색 결과가 없습니다.')
await list.getByLabel('작성한 글 검색').fill('')
await list.getByRole('button', { name: '검색', exact: true }).click()
await expect(items).toHaveCount(1)
await expect(list.locator('.admin-member-activity__body')).toHaveText('본문')
await list.getByLabel('작성 종류').selectOption('all')
await expect(items).toHaveCount(10)
const rowBox = await items.first().boundingBox()
expect(rowBox.height).toBeLessThan(40)
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')
const recentComment = page.locator('.admin-comment-list__item').first()
expect(await recentComment.locator(':scope > *').evaluateAll((elements) => elements.map((element) => element.className.split(' ')[0]))).toEqual([
'admin-comment-list__post', 'admin-comment-list__body', 'admin-comment-list__author', 'admin-comment-list__time'
])
await expect(recentComment.locator('.admin-comment-list__author')).toHaveAttribute('href', `/admin/members/${admin.userId}`)
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()
}
})