Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 MARKDOWN_IMAGE_MAX_HEIGHT,
5 MARKDOWN_IMAGE_MAX_WIDTH,
6 resolveMarkdownImageDisplaySize,
7} from "./markdownImageSize";
8
9describe("resolveMarkdownImageDisplaySize", () => {
10 it("keeps small images at their intrinsic size", () => {
11 expect(
12 resolveMarkdownImageDisplaySize({
13 sourceWidth: 96,
14 sourceHeight: 96,
15 availableWidth: 332,
16 }),
17 ).toEqual({ width: 96, height: 96 });
18 });
19
20 it("fits wide images to the available chat width", () => {
21 expect(
22 resolveMarkdownImageDisplaySize({
23 sourceWidth: 960,
24 sourceHeight: 540,
25 availableWidth: 332,
26 }),
27 ).toEqual({ width: 332, height: 186.75 });
28 });
29
30 it("caps wide images at 480 points on larger screens", () => {
31 expect(
32 resolveMarkdownImageDisplaySize({
33 sourceWidth: 960,
34 sourceHeight: 540,
35 availableWidth: 900,
36 }),
37 ).toEqual({ width: MARKDOWN_IMAGE_MAX_WIDTH, height: 270 });
38 });
39
40 it("caps tall images by height without changing their aspect ratio", () => {
41 expect(
42 resolveMarkdownImageDisplaySize({
43 sourceWidth: 400,
44 sourceHeight: 800,
45 availableWidth: 332,
46 }),
47 ).toEqual({ width: 240, height: MARKDOWN_IMAGE_MAX_HEIGHT });
48 });
49
50 it("rejects dimensions that cannot produce a stable layout", () => {
51 expect(
52 resolveMarkdownImageDisplaySize({ sourceWidth: 0, sourceHeight: 100, availableWidth: 332 }),
53 ).toBeNull();
54 expect(
55 resolveMarkdownImageDisplaySize({
56 sourceWidth: 100,
57 sourceHeight: Number.NaN,
58 availableWidth: 332,
59 }),
60 ).toBeNull();
61 });
62});