This commit is contained in:
2026-06-16 08:18:10 -06:00
parent 19cc1ffdfa
commit 660039b3cf
9 changed files with 639 additions and 103 deletions

View File

@@ -2,11 +2,13 @@ import { flushPromises, mount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createEmptyBook, createEmptyTeachingDesign } from '../domain/teachingDesign'
import * as booksApi from '../services/booksApi'
import * as zipExporter from '../services/zipExporter'
import BatchGenerateDialog from './BatchGenerateDialog.vue'
import GenerateLessonDialog from './GenerateLessonDialog.vue'
import WorkspaceView from './WorkspaceView.vue'
vi.mock('../services/booksApi')
vi.mock('../services/zipExporter')
function mockBook(data = createEmptyBook()): void {
vi.mocked(booksApi.getBook).mockResolvedValue({
@@ -189,4 +191,20 @@ describe('WorkspaceView', () => {
expect(wrapper.text()).toContain('点击或拖拽上传')
})
it('downloads the exported zip with the book name', async () => {
const data = createEmptyBook()
data.designs.push(createEmptyTeachingDesign('1.md'))
const blob = new Blob(['zip'])
mockBook(data)
vi.mocked(zipExporter.createBookZip).mockResolvedValue(blob)
const wrapper = mount(WorkspaceView, { props: { bookId: 'b1' } })
await flushPromises()
await wrapper.get('[data-testid="export"]').trigger('click')
await flushPromises()
expect(zipExporter.downloadBlob).toHaveBeenCalledWith(blob, '示例整本.zip')
})
})

View File

@@ -14,6 +14,7 @@ import UploadDropzone from './UploadDropzone.vue'
import WorkspaceToolbar from './WorkspaceToolbar.vue'
const BATCH_GENERATE_CONCURRENCY = 3
const DEFAULT_EXPORT_ZIP_NAME = 'teaching-design-book'
const props = defineProps<{ bookId: string }>()
@@ -104,10 +105,15 @@ function handlePrint(): void {
document.title = prev
}
function createExportZipFilename(name: string): string {
const stem = name.trim().replace(/[\\/:*?"<>|]/g, '_')
return `${stem || DEFAULT_EXPORT_ZIP_NAME}.zip`
}
async function handleExport(): Promise<void> {
try {
const blob = await createBookZip(book.value.designs)
downloadBlob(blob, 'teaching-design-book.zip')
downloadBlob(blob, createExportZipFilename(bookName.value))
} catch {
errorMessage.value = '导出失败,请重试。'
}