Phase 11: version PDF (FR-15)
- เลข version ใหม่: เว็บ-generate = v0 ฉบับตั้งต้น (ไม่มี PDF), add-in save (Start Versioning + Save & Version) = v1+ มี PDF เสมอ - PDF ผลิตจาก Word จริงผ่าน task pane เท่านั้น (getFileAsync Pdf + runtime guard, manifest ไม่เพิ่ม requirement); capture/upload เป็น best-effort — docx ผ่านแม้ PDF ล้ม + MessageBar เตือนตาม hasPdf - Backend: DocumentVersion.PdfObjectKey (nullable, migration AddVersionPdf) + sibling .pdf ใน bucket docx-versions · multipart part pdf (ผิด type → 400) · /download + /download-link รับ ?format=pdf (ไม่มี → 404) · presigned ฝังชื่อไฟล์ไทย + _vN (RFC 5987) - Web: เปิดไฟล์แทน blob-download — PDF แท็บใหม่, docx ผ่าน ms-word:ofe|u| พร้อม heuristic fallback ลิงก์สำรอง (useVersionOpen, versionDownload) · ปุ่ม "เปิดใน Word" ที่หน้า success ของฟอร์มสร้างเอกสาร - Spec v7 + CONTEXT.md + ADR 0001 + แผน docs/plans/version-pdf.md - Automated QA: backend 68 / add-in 63 / web 55 ผ่าน · manual acceptance ผ่านบน Word for Mac (2026-09-08) รวม fidelity + track changes — ค้างเฉพาะ Windows / Word on the web Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
parent
618328ffa7
commit
39d610a781
39 changed files with 1387 additions and 212 deletions
100
web/test/useVersionOpen.spec.ts
Normal file
100
web/test/useVersionOpen.spec.ts
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { createApp, type App } from 'vue'
|
||||
import { useVersionOpen } from '../app/composables/useVersionOpen'
|
||||
|
||||
let app: App
|
||||
let host: HTMLDivElement
|
||||
const apiJson = vi.fn()
|
||||
const replace = vi.fn()
|
||||
const close = vi.fn()
|
||||
let tab: { opener: unknown; closed: boolean; location: { replace: typeof replace }; close: typeof close }
|
||||
|
||||
function mount() {
|
||||
let result!: ReturnType<typeof useVersionOpen>
|
||||
host = document.createElement('div')
|
||||
document.body.append(host)
|
||||
app = createApp({ setup() { result = useVersionOpen(); return () => null } })
|
||||
app.mount(host)
|
||||
return result
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
vi.stubGlobal('useApi', () => ({ apiJson }))
|
||||
tab = { opener: {}, closed: false, location: { replace }, close }
|
||||
vi.spyOn(window, 'open').mockReturnValue(tab as unknown as Window)
|
||||
})
|
||||
afterEach(() => {
|
||||
app?.unmount()
|
||||
host?.remove()
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
vi.clearAllMocks()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
describe('version open lifecycle', () => {
|
||||
it('reserves PDF tab synchronously, navigates after auth, leaves completed PDF open on unmount', async () => {
|
||||
let resolve!: (value: unknown) => void
|
||||
apiJson.mockReturnValue(new Promise(r => { resolve = r }))
|
||||
const state = mount()
|
||||
const pending = state.openVersion('d', 'v', 'pdf')
|
||||
expect(window.open).toHaveBeenCalledWith('about:blank', '_blank')
|
||||
expect(tab.opener).toBeNull()
|
||||
expect(state.openingVersionId.value).toBe('v')
|
||||
resolve({ url: 'https://files.example/v.pdf' })
|
||||
await pending
|
||||
expect(replace).toHaveBeenCalledWith('https://files.example/v.pdf')
|
||||
expect(state.fallbackUrl.value).toBe('https://files.example/v.pdf')
|
||||
app.unmount()
|
||||
expect(close).not.toHaveBeenCalled()
|
||||
})
|
||||
it('keeps a fallback when popup is blocked', async () => {
|
||||
vi.mocked(window.open).mockReturnValue(null)
|
||||
apiJson.mockResolvedValue({ url: 'https://files.example/v.pdf' })
|
||||
const state = mount()
|
||||
await state.openVersion('d', 'v', 'pdf')
|
||||
expect(state.openNotice.value).toBeTruthy()
|
||||
expect(state.fallbackUrl.value).toBe('https://files.example/v.pdf')
|
||||
})
|
||||
it('closes pending tab immediately on reset and ignores a late response', async () => {
|
||||
let resolve!: (value: unknown) => void
|
||||
apiJson.mockReturnValue(new Promise(r => { resolve = r }))
|
||||
const state = mount()
|
||||
const pending = state.openVersion('d', 'v', 'pdf')
|
||||
state.resetOpen()
|
||||
expect(close).toHaveBeenCalledTimes(1)
|
||||
resolve({ url: 'https://files.example/v.pdf' })
|
||||
await pending
|
||||
expect(replace).not.toHaveBeenCalled()
|
||||
expect(state.fallbackUrl.value).toBeNull()
|
||||
})
|
||||
it('closes reserved tab and reports request failure', async () => {
|
||||
apiJson.mockRejectedValue(new Error('offline'))
|
||||
const state = mount()
|
||||
await state.openVersion('d', 'v', 'pdf')
|
||||
expect(close).toHaveBeenCalled()
|
||||
expect(state.downloadError.value).toBe('offline')
|
||||
expect(state.openingVersionId.value).toBeNull()
|
||||
})
|
||||
it('handles synchronous popup errors and restores controls', async () => {
|
||||
vi.mocked(window.open).mockImplementation(() => { throw new Error('popup error') })
|
||||
const state = mount()
|
||||
await state.openVersion('d', 'v', 'pdf')
|
||||
expect(state.downloadError.value).toBe('popup error')
|
||||
expect(state.openingVersionId.value).toBeNull()
|
||||
})
|
||||
it('offers Word fallback after timeout and removes listeners on unmount', async () => {
|
||||
const assign = vi.spyOn(window.location, 'assign').mockImplementation(() => {})
|
||||
const remove = vi.spyOn(window, 'removeEventListener')
|
||||
apiJson.mockResolvedValue({ url: 'https://files.example/v.docx?signature=a%2Fb' })
|
||||
const state = mount()
|
||||
await state.openVersion('d', 'v')
|
||||
expect(assign).toHaveBeenCalledWith('ms-word:ofe|u|https://files.example/v.docx?signature=a%2Fb')
|
||||
vi.advanceTimersByTime(1500)
|
||||
expect(state.openNotice.value).toBeTruthy()
|
||||
expect(state.fallbackUrl.value).toBeTruthy()
|
||||
app.unmount()
|
||||
expect(remove).toHaveBeenCalledWith('blur', expect.any(Function))
|
||||
})
|
||||
})
|
||||
17
web/test/versionDownload.spec.ts
Normal file
17
web/test/versionDownload.spec.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import { describe, expect, it } from 'vitest'
|
||||
import { versionFileName, versionDownloadPath, wordOpenUrl } from '../app/utils/versionDownload'
|
||||
|
||||
describe('version downloads', () => {
|
||||
it('names v0 and later artifacts', () => {
|
||||
expect(versionFileName('คำร้อง.DOCX', 0)).toBe('คำร้อง_v0.docx')
|
||||
expect(versionFileName('คำร้อง.docx', 1, 'pdf')).toBe('คำร้อง_v1.pdf')
|
||||
})
|
||||
it('requests the authenticated download-link format', () => {
|
||||
expect(versionDownloadPath('d', 'v')).toBe('/api/documents/d/versions/v/download-link')
|
||||
expect(versionDownloadPath('d', 'v', 'pdf')).toBe('/api/documents/d/versions/v/download-link?format=pdf')
|
||||
})
|
||||
it('preserves the signed URL exactly inside the Office URI', () => {
|
||||
const url = 'https://files.example/d.docx?X-Amz-Signature=abc&response-content-disposition=attachment%3B%20filename%2A%3DUTF-8%27%27'
|
||||
expect(wordOpenUrl(url)).toBe(`ms-word:ofe|u|${url}`)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue