mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-13 04:59:51 +08:00
refactor(lib): reuse MCP helpers for streaming preview and SVG extraction
- lib/utils.ts: remove convertToLegalXml and replaceNodes; the streaming preview now goes through wrapCellsInModel, autoFixXml and replacePageModel like the final commit path does - lib/utils.ts: extractDiagramXML reuses extractSvgEmbeddedXml, pageElement and decompressPageContent instead of hand-written SVG parsing and pako inflation - lib/use-file-processor.tsx: messages parameter is required, drop the English default texts only tests used - hooks/use-dictionary.ts, lib/i18n/utils.ts: drop duplicate default exports nobody imported - tests updated accordingly
This commit is contained in:
@@ -22,6 +22,8 @@ function deferred<T>() {
|
||||
const pdfFile = () =>
|
||||
new File(["%PDF"], "slow.pdf", { type: "application/pdf" })
|
||||
const textFile = () => new File(["notes"], "notes.txt", { type: "text/plain" })
|
||||
// The toast texts the hook formats; toast is mocked, so any texts do
|
||||
const messages = { tooLong: "{name} too long", readFailed: "failed {name}" }
|
||||
|
||||
describe("useFileProcessor", () => {
|
||||
beforeEach(() => {
|
||||
@@ -35,7 +37,7 @@ describe("useFileProcessor", () => {
|
||||
vi.mocked(extractTextFileContent).mockResolvedValue("notes")
|
||||
const a = pdfFile()
|
||||
const b = textFile()
|
||||
const { result } = renderHook(() => useFileProcessor())
|
||||
const { result } = renderHook(() => useFileProcessor(messages))
|
||||
|
||||
let done!: Promise<void>
|
||||
act(() => {
|
||||
@@ -59,7 +61,7 @@ describe("useFileProcessor", () => {
|
||||
vi.mocked(extractTextFileContent).mockResolvedValue("notes")
|
||||
const a = pdfFile()
|
||||
const b = textFile()
|
||||
const { result } = renderHook(() => useFileProcessor())
|
||||
const { result } = renderHook(() => useFileProcessor(messages))
|
||||
|
||||
let first!: Promise<void>
|
||||
act(() => {
|
||||
@@ -82,7 +84,7 @@ describe("useFileProcessor", () => {
|
||||
const pdf = deferred<string>()
|
||||
vi.mocked(extractPdfText).mockReturnValue(pdf.promise)
|
||||
const a = pdfFile()
|
||||
const { result } = renderHook(() => useFileProcessor())
|
||||
const { result } = renderHook(() => useFileProcessor(messages))
|
||||
|
||||
let first!: Promise<void>
|
||||
act(() => {
|
||||
|
||||
Reference in New Issue
Block a user