summaryrefslogtreecommitdiffhomepage
path: root/src/features/chat/adapter/image-encode.test.ts
blob: dbaa8ae70dc79831c7f14dcacb559af706ae57a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { describe, expect, it } from "vitest";
import { convertToJpeg } from "./image-encode";

describe("convertToJpeg (canvas edge — real environment, no mocks)", () => {
  it("skips non-convertible formats without touching the canvas", async () => {
    const jpeg = new File([new Uint8Array([0xff, 0xd8])], "photo.jpg", { type: "image/jpeg" });
    await expect(convertToJpeg(jpeg)).resolves.toBe(null);
    const gif = new File([new Uint8Array([0x47])], "anim.gif", { type: "image/gif" });
    await expect(convertToJpeg(gif)).resolves.toBe(null);
    const unnamed = new File([new Uint8Array([0x00])], "blob", { type: "" });
    await expect(convertToJpeg(unnamed)).resolves.toBe(null);
  });

  it("falls back to null on decode failure (no real canvas in this environment)", async () => {
    const png = new File([new Uint8Array([0x89, 0x50])], "shot.png", { type: "image/png" });
    // jsdom has no `createImageBitmap` → the decode throws → the failure path
    // must resolve to `null` (never reject), so sending is never blocked.
    await expect(convertToJpeg(png)).resolves.toBe(null);
  });
});