import { afterEach, describe, expect, it, vi } from "vitest"; import { apiRequestBlob } from "../../../../client/src/api/http"; afterEach(() => vi.unstubAllGlobals()); describe("browser download Content-Disposition filenames", () => { it.each([ ["attachment; filename=legacy.xls; filename*=UTF-8''%E6%8A%A5%E9%94%80%E5%88%B6%E5%8D%95_PB-001.xls", "报销制单_PB-001.xls"], ["attachment; FILENAME*=utf-8'zh'%E6%8A%A5%E9%94%80.xls; filename=legacy.xls", "报销.xls"], ['attachment; filename="receipt.pdf"', "receipt.pdf"], ["attachment; filename*=UTF-8''%broken; filename=legacy.xls", "legacy.xls"], ["attachment; filename*=ISO-8859-1''abc; filename=legacy.xls", "legacy.xls"], ["attachment; filename*=UTF-8''; filename=legacy.xls", "legacy.xls"], ["attachment", null], ])("resolves %s", async (header, filename) => { vi.stubGlobal("fetch", vi.fn().mockResolvedValue(new Response("synthetic", { status: 200, headers: { "content-disposition": header }, }))); const response = await apiRequestBlob("/synthetic-download", { auth: false }); expect(response.filename).toBe(filename); expect(await response.blob.text()).toBe("synthetic"); }); });