cb6b4c3731
Co-authored-by: Cursor <cursoragent@cursor.com>
128 lines
4.8 KiB
TypeScript
128 lines
4.8 KiB
TypeScript
import { mkdtempSync, rmSync, existsSync } from 'fs'
|
|
import { join } from 'path'
|
|
import { tmpdir } from 'os'
|
|
import { test, expect } from '@playwright/test'
|
|
import {
|
|
launchApp,
|
|
skipOnboarding,
|
|
createBookAndOpenEditor,
|
|
ensureChapterEditor,
|
|
dismissCockpitIfOpen,
|
|
addCharacterSetting,
|
|
openCharacterSetting
|
|
} from './helpers'
|
|
|
|
async function openChapterByIndex(page: import('@playwright/test').Page, index = 0): Promise<void> {
|
|
await page.getByTestId('sidebar-tab-chapters').click()
|
|
await page.getByTestId(/^chapter-item-/).nth(index).click()
|
|
await expect(page.getByTestId('chapter-meta-open')).toBeVisible({ timeout: 10_000 })
|
|
}
|
|
|
|
async function setChapterStoryTime(
|
|
page: import('@playwright/test').Page,
|
|
storyTime: string,
|
|
chapterIndex = 0
|
|
): Promise<void> {
|
|
await openChapterByIndex(page, chapterIndex)
|
|
await page.getByTestId('chapter-meta-open').click()
|
|
await expect(page.getByTestId('chapter-meta-panel')).toBeVisible({ timeout: 10_000 })
|
|
await page.getByTestId('chapter-meta-story-time').fill(storyTime)
|
|
await page.getByTestId('chapter-meta-save').click()
|
|
await expect(page.getByTestId('chapter-meta-panel')).toBeHidden({ timeout: 10_000 })
|
|
}
|
|
|
|
test.describe('Story timeline', () => {
|
|
let userDataDir: string
|
|
|
|
test.beforeEach(() => {
|
|
userDataDir = mkdtempSync(join(tmpdir(), 'bilin-e2e-timeline-'))
|
|
})
|
|
|
|
test.afterEach(() => {
|
|
if (userDataDir && existsSync(userDataDir)) {
|
|
try {
|
|
rmSync(userDataDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 200 })
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|
|
})
|
|
|
|
test('E2E-TL-01: open story timeline lists chapters', async () => {
|
|
const app = await launchApp(userDataDir)
|
|
const page = await app.firstWindow()
|
|
await skipOnboarding(page)
|
|
await createBookAndOpenEditor(page, '时间线测试书')
|
|
await dismissCockpitIfOpen(page)
|
|
await ensureChapterEditor(page)
|
|
await setChapterStoryTime(page, '730')
|
|
|
|
await page.getByTestId('open-timeline').click()
|
|
await expect(page.getByTestId('timeline-modal')).toBeVisible({ timeout: 10_000 })
|
|
await expect(page.getByTestId('timeline-list')).toContainText('730')
|
|
|
|
await app.close()
|
|
})
|
|
|
|
test('E2E-TL-02: character birth year and chapter times show in timeline', async () => {
|
|
const app = await launchApp(userDataDir)
|
|
const page = await app.firstWindow()
|
|
await skipOnboarding(page)
|
|
await createBookAndOpenEditor(page, '角色年龄测试')
|
|
await dismissCockpitIfOpen(page)
|
|
await ensureChapterEditor(page)
|
|
|
|
await addCharacterSetting(page, '林远')
|
|
await openCharacterSetting(page, '林远')
|
|
await expect(page.getByTestId('character-arc-panel')).toBeVisible({ timeout: 15_000 })
|
|
await page.getByTestId('character-birth-date').fill('700')
|
|
await page.getByRole('button', { name: '保存' }).click()
|
|
|
|
await page.getByTestId('sidebar-tab-chapters').click()
|
|
await openChapterByIndex(page, 0)
|
|
await setChapterStoryTime(page, '710', 0)
|
|
|
|
await page.getByRole('button', { name: '+ 新章' }).click()
|
|
await expect(page.locator('.ProseMirror')).toBeVisible({ timeout: 10_000 })
|
|
await setChapterStoryTime(page, '730', 1)
|
|
|
|
await page.getByTestId('open-timeline').click()
|
|
await expect(page.getByTestId('timeline-modal')).toBeVisible({ timeout: 10_000 })
|
|
await expect(page.getByTestId('timeline-list')).toContainText('710')
|
|
await expect(page.getByTestId('timeline-list')).toContainText('730')
|
|
await expect(page.locator('.timeline-item--conflict')).toHaveCount(0)
|
|
|
|
await app.close()
|
|
})
|
|
|
|
test('E2E-TL-03: timeline conflict shows red warning', async () => {
|
|
const app = await launchApp(userDataDir)
|
|
const page = await app.firstWindow()
|
|
await skipOnboarding(page)
|
|
await createBookAndOpenEditor(page, '时间冲突测试')
|
|
await dismissCockpitIfOpen(page)
|
|
await ensureChapterEditor(page)
|
|
|
|
await addCharacterSetting(page, '主角')
|
|
await openCharacterSetting(page, '主角')
|
|
await expect(page.getByTestId('character-arc-panel')).toBeVisible({ timeout: 15_000 })
|
|
await page.getByTestId('character-birth-date').fill('700')
|
|
await page.getByRole('button', { name: '保存' }).click()
|
|
|
|
await page.getByTestId('sidebar-tab-chapters').click()
|
|
await openChapterByIndex(page, 0)
|
|
await setChapterStoryTime(page, '730', 0)
|
|
|
|
await page.getByRole('button', { name: '+ 新章' }).click()
|
|
await expect(page.locator('.ProseMirror')).toBeVisible({ timeout: 10_000 })
|
|
await setChapterStoryTime(page, '720', 1)
|
|
|
|
await page.getByTestId('open-timeline').click()
|
|
await expect(page.getByTestId('timeline-modal')).toBeVisible({ timeout: 10_000 })
|
|
await expect(page.locator('.timeline-item--conflict')).toHaveCount(1, { timeout: 10_000 })
|
|
await expect(page.getByTestId('timeline-conflict-msg')).toBeVisible()
|
|
|
|
await app.close()
|
|
})
|
|
})
|