feat(webui): add reading text size preferences (#6325)

* feat(webui): add reading text size preferences

* fix(webui): align loading skeletons with reading typography
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-20 16:33:05 +08:00
1 parent 816c9221a0
commit 282839cc65
48 files changed
+662 -120

No files matched your search

+21
View File
@@ -26,6 +26,27 @@ describe("local preferences", () => {
expect(readLocalPreferences().brandLogos).toBe(false);
});
it.each([undefined, "obsolete", 24])("defaults missing or invalid reading sizes without resetting other preferences: %s", (readingTextSize) => {
localStorage.setItem(LOCAL_PREFS_STORAGE_KEY, JSON.stringify({
schemaVersion: 1,
readingTextSize,
activityMode: "expanded",
codeWrap: false,
brandLogos: false,
notificationSound: true,
fileEditDisplayMode: "diff",
}));
expect(readLocalPreferences()).toEqual({
...DEFAULT_LOCAL_PREFS,
readingTextSize: "standard",
activityMode: "expanded",
codeWrap: false,
brandLogos: false,
notificationSound: true,
fileEditDisplayMode: "diff",
});
});
it("keeps browser notifications opt-in", () => {
expect(DEFAULT_LOCAL_PREFS.browserNotifications).toBe(false);
expect(readLocalPreferences().browserNotifications).toBe(false);
+19 -1
View File
@@ -20,7 +20,7 @@ function Example({
mode = "buttons",
animateIndicator = true,
}: {
mode?: "buttons" | "tabs";
mode?: "buttons" | "tabs" | "radio";
animateIndicator?: boolean;
}) {
const [value, setValue] = useState("summary");
@@ -101,6 +101,24 @@ describe("SegmentedControl", () => {
expect(diff).toHaveFocus();
});
it("exposes one checked radio and moves selection and focus with the keyboard", () => {
render(<Example mode="radio" />);
const summary = screen.getByRole("radio", { name: "Summary" });
const diff = screen.getByRole("radio", { name: "Diff" });
expect(summary).toBeChecked();
expect(summary).toHaveAttribute("tabindex", "0");
expect(diff).toHaveAttribute("tabindex", "-1");
summary.focus();
fireEvent.keyDown(summary, { key: "ArrowRight" });
expect(diff).toBeChecked();
expect(diff).toHaveFocus();
expect(summary).not.toBeChecked();
fireEvent.keyDown(diff, { key: "Home" });
expect(summary).toBeChecked();
expect(summary).toHaveFocus();
});
it("can disable motion when the set of segments is dynamic", () => {
const { container } = render(<Example animateIndicator={false} />);
const summary = screen.getByRole("button", { name: "Summary" });
@@ -112,6 +112,18 @@ describe("Settings overview and appearance", () => {
expect(url.href).not.toContain("private-host");
});
it("saves the reading size immediately while preserving the other local preferences", async () => {
const previous = { ...DEFAULT_LOCAL_PREFS, codeWrap: false, brandLogos: false, notificationSound: true };
writeLocalPreferences(previous);
renderSettingsView({ initialSection: "appearance", initialSettings: settingsPayload() });
expect(screen.getByRole("radio", { name: "Standard reading text" })).toBeChecked();
fireEvent.click(screen.getByRole("radio", { name: "Large reading text" }));
await waitFor(() => expect(readLocalPreferences()).toEqual({ ...previous, readingTextSize: "large" }));
expect(screen.getByRole("radio", { name: "Large reading text" })).toBeChecked();
});
it("persists the file edit display local preference", async () => {
renderSettingsView({
initialSection: "appearance",
+2 -2
View File
@@ -585,7 +585,7 @@ describe("ThreadComposer", () => {
const input = screen.getByPlaceholderText("Ask anything...");
expect(input).toBeInTheDocument();
expect(input.className).toContain("min-h-[78px]");
expect(input.className).toContain("text-[16px]");
expect(input.className).toContain("text-composer");
expect(input.className).toContain("pt-[27px]");
fireEvent.change(input, { target: { value: "1" } });
expect(input.className).toContain("pt-[27px]");
@@ -820,7 +820,7 @@ describe("ThreadComposer", () => {
}
const input = screen.getByPlaceholderText("Type your message...");
expect(input.className).toContain("min-h-[50px]");
expect(input.className).toContain("text-[16px]");
expect(input.className).toContain("text-composer");
expect(input.parentElement?.parentElement?.className).toContain("max-w-[49.5rem]");
expect(input.parentElement?.parentElement?.className).toContain("rounded-panel");
expect(input.parentElement?.parentElement?.className).not.toContain("shadow-");
+5 -5
View File
@@ -10,7 +10,7 @@ import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
describe("touch form typography", () => {
it("keeps the touch baseline on compact shared fields without changing desktop classes", () => {
it("keeps the touch baseline and desktop text roles on compact shared fields", () => {
render(<>
<Input aria-label="Name" />
<Input aria-label="Address" className="text-[13px]" />
@@ -19,7 +19,7 @@ describe("touch form typography", () => {
for (const field of screen.getAllByRole("textbox")) {
expect(field).toHaveClass("touch-text-input");
}
expect(screen.getByLabelText("Name")).toHaveClass("text-sm");
expect(screen.getByLabelText("Name")).toHaveClass("text-ui-body");
expect(screen.getByLabelText("Address")).toHaveClass("text-[13px]");
expect(screen.getByLabelText("Pairing code")).toHaveClass("text-xs", "font-mono");
});
@@ -28,20 +28,20 @@ describe("touch form typography", () => {
const config = loadConfig(resolve(process.cwd(), "tailwind.config.js"));
const source = readFileSync(resolve(process.cwd(), "src/globals.css"), "utf8");
const result = await postcss([tailwindcss({ ...config, content: [{
raw: 'class="touch-text-input text-xs text-sm text-[13px] text-[19px]"',
raw: 'class="touch-text-input text-xs text-sm text-ui-body text-[13px] text-[19px]"',
}] })]).process(source, { from: undefined });
let baseline = -1;
let index = 0;
const compact: number[] = [];
result.root.walkRules((rule) => {
index++;
if ([".text-xs", ".text-sm", ".text-\\[13px\\]"].includes(rule.selector)) compact.push(index);
if ([".text-xs", ".text-sm", ".text-ui-body", ".text-\\[13px\\]"].includes(rule.selector)) compact.push(index);
if (rule.selector !== ".touch-text-input") return;
baseline = index;
expect(rule.parent).toMatchObject({ type: "atrule", name: "media", params: "(pointer: coarse)" });
expect(rule.nodes).toContainEqual(expect.objectContaining({ prop: "font-size", value: "max(16px, 1rem)" }));
});
expect(compact).toHaveLength(3);
expect(compact).toHaveLength(4);
expect(baseline).toBeGreaterThan(Math.max(...compact));
});
});