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

appearanceFonts.browser.test.ts

55 lines1.6 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import "~/index.css";
4import { applyAppearanceFontVariables } from "./appearanceFonts";
5​
6function renderedFontSize(style: (probe: HTMLElement) => void): string {
7 const probe = document.createElement("div");
8 style(probe);
9 document.body.append(probe);
10 try {
11 return getComputedStyle(probe).fontSize;
12 } finally {
13 probe.remove();
14 }
16​
17const composerFontSize = () =>
18 renderedFontSize((probe) => {
19 // The composer editor's own size class.
20 probe.className = "text-(length:--font-size-prompt,var(--text-sm))";
21 });
22​
23const touchComposerFontSize = () =>
24 renderedFontSize((probe) => {
25 probe.style.fontSize = "var(--font-size-prompt-touch)";
26 });
27​
28describe("applyAppearanceFontVariables", () => {
29 it("sizes the composer from the interface size until fonts are set separately", () => {
30 const root = document.documentElement;
31 const style = root.getAttribute("style");
32 const preferences = {
33 sans: "",
34 code: "",
35 composer: "",
36 sizeInterface: 20,
37 sizePrompt: 14,
38 sizeCode: 13,
39 smoothing: true,
40 };
41 try {
42 applyAppearanceFontVariables(root, { ...preferences, separate: false });
43 expect(composerFontSize()).toBe("17.5px");
44 expect(touchComposerFontSize()).toBe("17.5px");
45​
46 applyAppearanceFontVariables(root, { ...preferences, separate: true });
47 expect(composerFontSize()).toBe("14px");
48 // iOS zooms into inputs under 16px.
49 expect(touchComposerFontSize()).toBe("16px");
50 } finally {
51 if (style === null) root.removeAttribute("style");
52 else root.setAttribute("style", style);
53 }
54 });
55});