fix: update unit tests for DecodedPreview return type and outpaint tier arg

This commit is contained in:
SnapOtter
2026-05-13 15:53:09 +08:00
parent c3dc98834d
commit e1ca06cd95
3 changed files with 10 additions and 4 deletions
+1
View File
@@ -87,6 +87,7 @@ describe("outpaint", () => {
"20", "20",
"30", "30",
"40", "40",
"balanced",
], ],
expect.any(Object), expect.any(Object),
); );
@@ -118,6 +118,7 @@ describe("fetchDecodedPreview", () => {
fetchMock.mockResolvedValueOnce({ fetchMock.mockResolvedValueOnce({
ok: true, ok: true,
blob: () => Promise.resolve(blob), blob: () => Promise.resolve(blob),
headers: { get: () => null },
}); });
const file = new File(["heic-data"], "photo.heic", { type: "image/heic" }); const file = new File(["heic-data"], "photo.heic", { type: "image/heic" });
@@ -132,7 +133,7 @@ describe("fetchDecodedPreview", () => {
const formData = opts.body as FormData; const formData = opts.body as FormData;
expect(formData.get("file")).toBe(file); expect(formData.get("file")).toBe(file);
expect(result).toBe("blob:preview-url"); expect(result?.url).toBe("blob:preview-url");
expect(createObjectURL).toHaveBeenCalledWith(blob); expect(createObjectURL).toHaveBeenCalledWith(blob);
}); });
+7 -3
View File
@@ -1535,7 +1535,11 @@ describe("useCollageStore", () => {
const needsMock = vi.mocked(imagePreview.needsServerPreview); const needsMock = vi.mocked(imagePreview.needsServerPreview);
const fetchPreviewMock = vi.mocked(imagePreview.fetchDecodedPreview); const fetchPreviewMock = vi.mocked(imagePreview.fetchDecodedPreview);
needsMock.mockReturnValueOnce(true); needsMock.mockReturnValueOnce(true);
fetchPreviewMock.mockResolvedValueOnce("blob:preview-decoded"); fetchPreviewMock.mockResolvedValueOnce({
url: "blob:preview-decoded",
originalWidth: null,
originalHeight: null,
});
const heicFile = new File(["heic-data"], "photo.heic", { type: "image/heic" }); const heicFile = new File(["heic-data"], "photo.heic", { type: "image/heic" });
useCollageStore.getState().addImages([heicFile]); useCollageStore.getState().addImages([heicFile]);
@@ -1559,7 +1563,7 @@ describe("useCollageStore", () => {
const fetchPreviewMock = vi.mocked(imagePreview.fetchDecodedPreview); const fetchPreviewMock = vi.mocked(imagePreview.fetchDecodedPreview);
needsMock.mockReturnValueOnce(true); needsMock.mockReturnValueOnce(true);
let resolvePreview!: (v: string | null) => void; let resolvePreview!: (v: import("@/lib/image-preview").DecodedPreview | null) => void;
fetchPreviewMock.mockReturnValueOnce( fetchPreviewMock.mockReturnValueOnce(
new Promise((resolve) => { new Promise((resolve) => {
resolvePreview = resolve; resolvePreview = resolve;
@@ -1573,7 +1577,7 @@ describe("useCollageStore", () => {
useCollageStore.getState().removeImage(0); useCollageStore.getState().removeImage(0);
// Now resolve the preview -- should not crash (idx === -1 path) // Now resolve the preview -- should not crash (idx === -1 path)
resolvePreview("blob:late-preview"); resolvePreview({ url: "blob:late-preview", originalWidth: null, originalHeight: null });
// Give the promise chain time to settle // Give the promise chain time to settle
await new Promise((r) => setTimeout(r, 10)); await new Promise((r) => setTimeout(r, 10));