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

terminalUiState.test.ts

53 lines1.5 KB

1import { beforeEach, describe, expect, it } from "vite-plus/test";
2import { EnvironmentId, ThreadId } from "@t3tools/contracts";
3​
4import {
5 cacheTerminalFontSize,
6 cacheTerminalGridSize,
7 getCachedTerminalFontSize,
8 getCachedTerminalGridSize,
9 resetTerminalUiStateCaches,
10} from "./terminalUiState";
11​
12describe("terminalUiState", () => {
13 beforeEach(() => {
14 resetTerminalUiStateCaches();
15 });
16​
17 it("caches terminal font size using the shared normalization rules", () => {
18 expect(getCachedTerminalFontSize()).toBeNull();
19 expect(cacheTerminalFontSize(8.5)).toBe(8.5);
20 expect(getCachedTerminalFontSize()).toBe(8.5);
21 expect(cacheTerminalFontSize(100)).toBe(14);
22 expect(getCachedTerminalFontSize()).toBe(14);
23 });
24​
25 it("stores terminal grid sizes per terminal target", () => {
26 const primaryTarget = {
27 environmentId: EnvironmentId.make("env-1"),
28 threadId: ThreadId.make("thread-1"),
29 terminalId: "default",
30 };
31 const otherTarget = {
32 environmentId: EnvironmentId.make("env-1"),
33 threadId: ThreadId.make("thread-1"),
34 terminalId: "term-2",
35 };
36​
37 expect(getCachedTerminalGridSize(primaryTarget)).toBeNull();
38 expect(
39 cacheTerminalGridSize(primaryTarget, {
40 cols: 107.9,
41 rows: 33.2,
42 }),
43 ).toEqual({
44 cols: 107,
45 rows: 33,
46 });
47 expect(getCachedTerminalGridSize(primaryTarget)).toEqual({
48 cols: 107,
49 rows: 33,
50 });
51 expect(getCachedTerminalGridSize(otherTarget)).toBeNull();
52 });
53});