Skip to content

Commit dc8880c

Browse files
fix(ui): keep a stepper value that equals the shown default; tighten tests
1 parent 5db31a8 commit dc8880c

3 files changed

Lines changed: 17 additions & 21 deletions

File tree

‎webview-ui/src/components/settings/NumberStepper.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ export const NumberStepper = ({
4747
}
4848
const clamped = Math.min(max, Math.max(min, Math.round(next)))
4949
setDraft(String(clamped))
50-
// Committing the default clears the override so VS Code changes still flow through.
51-
onChange(clamped === fallback ? undefined : clamped)
50+
// Always the number the user chose. `fallback` is only what the box shows while nothing is set; for
51+
// the font sizes the real default is VS Code's own size, so a typed 12 must stay 12. Only Reset
52+
// clears the override.
53+
onChange(clamped)
5254
}
5355

5456
const buttonClass =

‎webview-ui/src/components/settings/__tests__/AppearancePreview.visual.tsx‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,3 @@ for (const theme of visualThemes) {
2121
await expect(story).toHaveScreenshot(`appearance-preview-${theme.name}.png`)
2222
})
2323
}
24-
25-
test("a reset preview ignores saved root values and uses the live fallbacks", async ({ mount, page }) => {
26-
const component = mountedStory(await mount("appearance-preview"))
27-
await page.evaluate(() => {
28-
const root = document.documentElement
29-
root.style.setProperty("--zoo-terminal-font-size", "30px")
30-
root.style.setProperty("--zoo-ui-scale", "2")
31-
})
32-
const reset = component.getByTestId("appearance-preview-reset").getByTestId("appearance-preview")
33-
const terminal = reset.locator("pre").nth(1)
34-
const size = await terminal.evaluate((el) => parseFloat(getComputedStyle(el).fontSize))
35-
// Not the saved 30px: the terminal falls back to VS Code's editor font size.
36-
expect(size).toBeLessThan(30)
37-
expect(await reset.evaluate((el) => getComputedStyle(el).getPropertyValue("--zoo-ui-scale").trim())).toBe("")
38-
})

‎webview-ui/src/components/settings/__tests__/NumberStepper.spec.tsx‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,19 @@ describe("NumberStepper", () => {
4444
expect(onChange).toHaveBeenLastCalledWith(15)
4545
})
4646

47-
it("clears the override when stepping back to the default", () => {
47+
it("keeps an explicit value that equals the displayed default: only Reset clears an override", () => {
4848
const { onChange } = setup({ value: 13 })
49-
fireEvent.click(screen.getByTestId("t-decrement")) // 12 == fallback
50-
expect(onChange).toHaveBeenLastCalledWith(undefined)
49+
fireEvent.click(screen.getByTestId("t-decrement")) // 12 == the shown fallback, but the user chose it
50+
expect(onChange).toHaveBeenLastCalledWith(12)
51+
expect(onChange).not.toHaveBeenCalledWith(undefined)
52+
})
53+
54+
it("stores a typed value that equals the displayed default as that number", () => {
55+
const { onChange, input } = setup()
56+
fireEvent.change(input, { target: { value: "12" } })
57+
fireEvent.blur(input)
58+
expect(onChange).toHaveBeenCalledTimes(1)
59+
expect(onChange).toHaveBeenLastCalledWith(12)
5160
})
5261

5362
it("disables the buttons at the limits", () => {
@@ -91,7 +100,7 @@ describe("NumberStepper", () => {
91100
fireEvent.change(input, { target: { value: "" } })
92101
fireEvent.blur(input)
93102
expect(input.value).toBe("16")
94-
expect(onChange).not.toHaveBeenCalledWith(NaN)
103+
expect(onChange).not.toHaveBeenCalled()
95104
})
96105

97106
it("clamps a typed zero up to the minimum (a real 0, unlike an emptied box)", () => {

0 commit comments

Comments
 (0)