|
1 | 1 | import { render, fireEvent, waitFor } from "@testing-library/react" |
2 | 2 | import { describe, it, expect, vi } from "vitest" |
3 | 3 | import { UISettings } from "../UISettings" |
| 4 | +import { telemetryClient } from "@/utils/TelemetryClient" |
| 5 | + |
| 6 | +vi.mock("@/utils/TelemetryClient", () => ({ |
| 7 | + telemetryClient: { capture: vi.fn() }, |
| 8 | +})) |
4 | 9 |
|
5 | 10 | describe("UISettings", () => { |
6 | 11 | const defaultProps = { |
@@ -41,4 +46,52 @@ describe("UISettings", () => { |
41 | 46 | rerender(<UISettings {...defaultProps} reasoningBlockCollapsed={true} />) |
42 | 47 | expect(checkbox.checked).toBe(true) |
43 | 48 | }) |
| 49 | + |
| 50 | + describe("chat font size", () => { |
| 51 | + it("shows the default font size when unset (init)", () => { |
| 52 | + const { getByText, getByTestId } = render(<UISettings {...defaultProps} chatFontSize={undefined} />) |
| 53 | + expect(getByTestId("chat-font-size-slider")).toBeTruthy() |
| 54 | + // Default falls back to VS Code-equivalent default value. |
| 55 | + expect(getByText("13px")).toBeTruthy() |
| 56 | + }) |
| 57 | + |
| 58 | + it("shows the configured font size when set", () => { |
| 59 | + const { getByText } = render(<UISettings {...defaultProps} chatFontSize={20} />) |
| 60 | + expect(getByText("20px")).toBeTruthy() |
| 61 | + }) |
| 62 | + |
| 63 | + it("persists a user-edited font size via setCachedStateField", () => { |
| 64 | + const setCachedStateField = vi.fn() |
| 65 | + const { getByTestId } = render( |
| 66 | + <UISettings {...defaultProps} chatFontSize={14} setCachedStateField={setCachedStateField} />, |
| 67 | + ) |
| 68 | + |
| 69 | + const slider = getByTestId("chat-font-size-slider").querySelector('[role="slider"]') as HTMLElement |
| 70 | + slider.focus() |
| 71 | + fireEvent.keyDown(slider, { key: "ArrowRight" }) |
| 72 | + |
| 73 | + expect(setCachedStateField).toHaveBeenCalledWith("chatFontSize", 15) |
| 74 | + expect(telemetryClient.capture).toHaveBeenCalledWith("ui_settings_chat_font_size_changed", { value: 15 }) |
| 75 | + }) |
| 76 | + |
| 77 | + it("disables reset when unset and clears the value on reset", () => { |
| 78 | + const setCachedStateField = vi.fn() |
| 79 | + const { getByTestId, rerender } = render( |
| 80 | + <UISettings {...defaultProps} chatFontSize={undefined} setCachedStateField={setCachedStateField} />, |
| 81 | + ) |
| 82 | + |
| 83 | + const resetUnset = getByTestId("chat-font-size-reset") as HTMLButtonElement |
| 84 | + expect(resetUnset.disabled).toBe(true) |
| 85 | + |
| 86 | + rerender( |
| 87 | + <UISettings {...defaultProps} chatFontSize={18} setCachedStateField={setCachedStateField} />, |
| 88 | + ) |
| 89 | + const resetSet = getByTestId("chat-font-size-reset") as HTMLButtonElement |
| 90 | + expect(resetSet.disabled).toBe(false) |
| 91 | + |
| 92 | + fireEvent.click(resetSet) |
| 93 | + expect(setCachedStateField).toHaveBeenCalledWith("chatFontSize", undefined) |
| 94 | + expect(telemetryClient.capture).toHaveBeenCalledWith("ui_settings_chat_font_size_reset") |
| 95 | + }) |
| 96 | + }) |
44 | 97 | }) |
0 commit comments