mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: update unit tests for DecodedPreview return type and outpaint tier arg
This commit is contained in:
@@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -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));
|
||||||
|
|||||||
Reference in New Issue
Block a user