88 lines
4.5 KiB
TypeScript
88 lines
4.5 KiB
TypeScript
/**
|
|
* /test → 프리필 → 분석 시작 → loading phase 폴링 → /report/:id 도달 풀 플로우.
|
|
*
|
|
* 외부 API(YouTube/Apify/Naver/Firecrawl/Perplexity)에 실호출이라
|
|
* 1 run · serial로 운영. 워커는 `--workers=1` 로 강제.
|
|
*/
|
|
import { test, expect, type Page } from '@playwright/test'
|
|
import { CLINICS } from '../src/features/dev/fixtures/mockUrls'
|
|
|
|
test.describe.configure({ mode: 'serial' })
|
|
|
|
async function pickAndSubmit(page: Page) {
|
|
await page.goto('/test')
|
|
|
|
const heading = page.locator('text=선택된 병원:').first()
|
|
await expect(heading).toBeVisible({ timeout: 10_000 })
|
|
const text = await heading.innerText()
|
|
const match = text.match(/선택된 병원:\s*(.+?)\s*\(/)
|
|
const label = match?.[1]
|
|
expect(label, `라벨 파싱 실패: "${text}"`).toBeTruthy()
|
|
|
|
const clinic = CLINICS.find((c) => c.label === label)
|
|
expect(clinic, `${label} 가 CLINICS에 없음`).toBeTruthy()
|
|
console.log(`[e2e] 선택된 병원: ${label}`)
|
|
|
|
if (clinic!.urls.homepage) {
|
|
await expect(page.getByLabel('홈페이지')).toHaveValue(clinic!.urls.homepage)
|
|
}
|
|
|
|
const analyzeBtn = page.getByRole('button', { name: /Analyze/i })
|
|
await expect(analyzeBtn).toBeEnabled()
|
|
await analyzeBtn.click()
|
|
|
|
await page.waitForURL(/\/report\/loading/, { timeout: 10_000 })
|
|
console.log(`[e2e] /report/loading 진입 (${new Date().toISOString()})`)
|
|
return label!
|
|
}
|
|
|
|
test('/test → 프리필 → 분석 시작 → phase 폴링 → /report/:id 도달', async ({ page }) => {
|
|
// 외부 API 의존 풀 플로우 — discovery(~20s) + collect(~40s) + report(~60s) + plan(~30s)
|
|
test.setTimeout(8 * 60_000)
|
|
|
|
const consoleErrors: string[] = []
|
|
const pageErrors: string[] = []
|
|
page.on('pageerror', (e) => pageErrors.push(e.message))
|
|
page.on('console', (msg) => {
|
|
if (msg.type() === 'error') consoleErrors.push(msg.text())
|
|
})
|
|
|
|
await pickAndSubmit(page)
|
|
|
|
// ── Phase 1: discovering → discovered ────────────────────────────
|
|
// discoverChannels 완료 시점에 URL이 /report/loading/<reportId> 로 replace 됨
|
|
await expect(page.locator('text=Channels discovered')).toBeVisible({ timeout: 90_000 })
|
|
console.log(`[e2e] ✓ Phase 1: Channels discovered (${new Date().toISOString()})`)
|
|
await expect(page).toHaveURL(/\/report\/loading\/[A-Za-z0-9-]+/, { timeout: 5_000 })
|
|
|
|
// ── Phase 2: collecting → collected ──────────────────────────────
|
|
await expect(page.locator('text=Data collected')).toBeVisible({ timeout: 180_000 })
|
|
console.log(`[e2e] ✓ Phase 2: Data collected (${new Date().toISOString()})`)
|
|
|
|
// ── Phase 3: generating active 상태 확인 ─────────────────────────
|
|
// 'Report generated'(완료 라벨)는 planning → complete → navigate 흐름이 빨라
|
|
// viewport에서 잡히지 않는 경우가 있어, 활성 라벨까지만 확인하고 URL 폴링으로 넘어감
|
|
await expect(page.locator('text=Generating AI marketing report')).toBeVisible({ timeout: 30_000 })
|
|
console.log(`[e2e] ✓ Phase 3: Generating report... (${new Date().toISOString()})`)
|
|
|
|
// ── 최종 /report/:id 도달 (Perplexity 호출 + plan 생성 포함 — 최대 6분) ──
|
|
await page.waitForURL(/\/report\/[A-Za-z0-9-]+$/, { timeout: 6 * 60_000 })
|
|
const finalUrl = page.url()
|
|
console.log(`[e2e] ✓ 최종 navigate: ${finalUrl} (${new Date().toISOString()})`)
|
|
expect(finalUrl).not.toContain('/loading')
|
|
|
|
// ── Report 페이지 본문 렌더링 확인 ───────────────────────────────
|
|
// GuestReportPage 로딩 스피너 → ReportBody. 'Marketing Intelligence Report' 헤더가 viewport 상단.
|
|
await expect(page.locator('text=리포트를 불러오는 중...')).toBeHidden({ timeout: 60_000 })
|
|
await expect(page.locator('text=Marketing Intelligence Report')).toBeVisible({ timeout: 30_000 })
|
|
console.log(`[e2e] ✓ Report 페이지 렌더 완료`)
|
|
|
|
// ── 콘솔 / 페이지 에러 0건 ────────────────────────────────────────
|
|
expect(pageErrors, `pageerror: ${pageErrors.join('\n')}`).toHaveLength(0)
|
|
// 콘솔 에러는 외부 채널 partial failure 등으로 발생할 수 있어 경고만 출력
|
|
if (consoleErrors.length > 0) {
|
|
console.warn(`[e2e] 콘솔 에러 ${consoleErrors.length}건 (non-blocking):`)
|
|
consoleErrors.slice(0, 5).forEach((e) => console.warn(` • ${e}`))
|
|
}
|
|
})
|