+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
126 lines
4.2 KiB
TypeScript
126 lines
4.2 KiB
TypeScript
import { describe, expect, it } from "vite-plus/test";
|
|
|
|
import {
|
|
areFontAdvancesMonospace,
|
|
clampCodeFontSize,
|
|
clampInterfaceFontSize,
|
|
clampPromptFontSize,
|
|
DEFAULT_CODE_FONT_STACK,
|
|
DEFAULT_SANS_FONT_STACK,
|
|
appearanceFontStack,
|
|
cssFontFamilies,
|
|
resolveDefaultFamilyLabel,
|
|
resolveTerminalFontPreference,
|
|
resolveTerminalFontSizePreference,
|
|
} from "./appearanceFonts";
|
|
|
|
describe("areFontAdvancesMonospace", () => {
|
|
it("accepts a fixed advance and rejects any proportional glyph", () => {
|
|
expect(areFontAdvancesMonospace([10, 10, 10, 10])).toBe(true);
|
|
expect(areFontAdvancesMonospace([10, 10, 7, 10])).toBe(false);
|
|
expect(areFontAdvancesMonospace([10, 10.02])).toBe(false);
|
|
});
|
|
|
|
it("fails open when canvas metrics are unavailable", () => {
|
|
expect(areFontAdvancesMonospace([])).toBe(true);
|
|
expect(areFontAdvancesMonospace([Number.NaN, Number.NaN])).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("cssFontFamilies", () => {
|
|
it("returns null for effectively empty input", () => {
|
|
expect(cssFontFamilies("")).toBeNull();
|
|
expect(cssFontFamilies(" ")).toBeNull();
|
|
expect(cssFontFamilies(" , , ")).toBeNull();
|
|
});
|
|
|
|
it("quotes names with spaces and keeps single idents bare", () => {
|
|
expect(cssFontFamilies("Fira Code")).toBe('"Fira Code"');
|
|
expect(cssFontFamilies("monospace")).toBe("monospace");
|
|
expect(cssFontFamilies('"Comic Mono"')).toBe('"Comic Mono"');
|
|
});
|
|
|
|
it("normalizes comma-separated lists and strips embedded quotes", () => {
|
|
expect(cssFontFamilies(" Fira Code , Menlo ")).toBe('"Fira Code", Menlo');
|
|
expect(cssFontFamilies('Bad"Name')).toBe('"BadName"');
|
|
});
|
|
|
|
it("quotes names that are not single CSS idents", () => {
|
|
expect(cssFontFamilies("3270 Nerd Font")).toBe('"3270 Nerd Font"');
|
|
expect(cssFontFamilies("M+ 1m")).toBe('"M+ 1m"');
|
|
});
|
|
});
|
|
|
|
describe("resolveDefaultFamilyLabel", () => {
|
|
it("skips generic keywords and returns null for a stack of only generics", () => {
|
|
expect(resolveDefaultFamilyLabel("system-ui, sans-serif")).toBeNull();
|
|
expect(resolveDefaultFamilyLabel("ui-monospace, monospace")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("appearanceFontStack", () => {
|
|
it("prepends the custom family to the default stack", () => {
|
|
expect(appearanceFontStack("Fira Code", DEFAULT_CODE_FONT_STACK)).toBe(
|
|
`"Fira Code", ${DEFAULT_CODE_FONT_STACK}`,
|
|
);
|
|
});
|
|
|
|
it("falls back to the default stack when unset", () => {
|
|
expect(appearanceFontStack("", DEFAULT_SANS_FONT_STACK)).toBe(DEFAULT_SANS_FONT_STACK);
|
|
});
|
|
});
|
|
|
|
describe("resolveTerminalFontPreference", () => {
|
|
it("inherits the code font in simple mode", () => {
|
|
expect(
|
|
resolveTerminalFontPreference({ advanced: false, code: "Fira Code", terminal: "" }),
|
|
).toBe("Fira Code");
|
|
expect(
|
|
resolveTerminalFontPreference({
|
|
advanced: false,
|
|
code: "Fira Code",
|
|
terminal: "Berkeley Mono",
|
|
}),
|
|
).toBe("Fira Code");
|
|
});
|
|
|
|
it("keeps code and terminal fonts independent in advanced mode", () => {
|
|
expect(resolveTerminalFontPreference({ advanced: true, code: "Fira Code", terminal: "" })).toBe(
|
|
"",
|
|
);
|
|
expect(
|
|
resolveTerminalFontPreference({
|
|
advanced: true,
|
|
code: "Fira Code",
|
|
terminal: "Berkeley Mono",
|
|
}),
|
|
).toBe("Berkeley Mono");
|
|
});
|
|
});
|
|
|
|
describe("resolveTerminalFontSizePreference", () => {
|
|
it("inherits the code font size in simple mode", () => {
|
|
expect(resolveTerminalFontSizePreference({ advanced: false, code: 15, terminal: 12 })).toBe(15);
|
|
});
|
|
|
|
it("keeps code and terminal font sizes independent in advanced mode", () => {
|
|
expect(resolveTerminalFontSizePreference({ advanced: true, code: 15, terminal: 12 })).toBe(12);
|
|
});
|
|
});
|
|
|
|
describe("font size clamping", () => {
|
|
it("keeps sizes inside the ranges the UI can absorb", () => {
|
|
expect(clampInterfaceFontSize(16)).toBe(16);
|
|
expect(clampInterfaceFontSize(2)).toBe(12);
|
|
expect(clampInterfaceFontSize(96)).toBe(20);
|
|
expect(clampPromptFontSize(40)).toBe(20);
|
|
expect(clampCodeFontSize(1)).toBe(10);
|
|
});
|
|
|
|
it("rounds fractional values and falls back for unusable input", () => {
|
|
expect(clampCodeFontSize(13.4)).toBe(13);
|
|
expect(clampInterfaceFontSize(Number.NaN)).toBe(16);
|
|
expect(clampPromptFontSize(Number.POSITIVE_INFINITY)).toBe(14);
|
|
});
|
|
});
|