Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ChatMarkdown.test.tsx

44 lines1.8 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { orderedListGutterStyle } from "./ChatMarkdown";
4​
5describe("orderedListGutterStyle", () => {
6 it("leaves the default gutter alone for single-digit lists", () => {
7 expect(orderedListGutterStyle(9, undefined)).toBeUndefined();
8 });
9​
10 it("leaves the default gutter alone for two-digit lists", () => {
11 expect(orderedListGutterStyle(99, undefined)).toBeUndefined();
12 });
13​
14 it("leaves the default gutter alone for a two-digit list that starts above 1", () => {
15 // start=50 + 49 items => last marker is "98", still two digits.
16 expect(orderedListGutterStyle(49, 50)).toBeUndefined();
17 });
18​
19 it("widens the gutter once the last marker reaches three digits", () => {
20 // item 100 is the bug from #6512: a 100-item list starting at 1.
21 expect(orderedListGutterStyle(100, undefined)).toEqual({ "--list-gutter": "4ch" });
22 });
23​
24 it("accounts for a non-default start attribute", () => {
25 // start=95 + 9 items => last marker is "103", three digits.
26 expect(orderedListGutterStyle(9, 95)).toEqual({ "--list-gutter": "4ch" });
27 expect(orderedListGutterStyle(5, "999995")).toEqual({ "--list-gutter": "7ch" });
28 });
29​
30 it("scales further for four-digit markers", () => {
31 expect(orderedListGutterStyle(1000, undefined)).toEqual({ "--list-gutter": "5ch" });
32 });
33​
34 it("uses the widest marker and includes a negative start's minus sign", () => {
35 expect(orderedListGutterStyle(1001, -1000)).toEqual({ "--list-gutter": "6ch" });
36 expect(orderedListGutterStyle(3, -15)).toEqual({ "--list-gutter": "4ch" });
37 expect(orderedListGutterStyle(3, -5)).toBeUndefined();
38 });
39​
40 it("treats a missing/zero item count as a single item", () => {
41 expect(orderedListGutterStyle(0, undefined)).toBeUndefined();
42 expect(orderedListGutterStyle(0, 100)).toEqual({ "--list-gutter": "4ch" });
43 });
44});