A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
/* Copyright 2026 Marimo. All rights reserved. */
import { render } from "@testing-library/react";
import * as React from "react";
import { describe, expect, it, vi } from "vitest";
import { RangeSlider } from "../range-slider";
vi.mock("react-aria", () => ({
useLocale: () => ({ locale: "en-US" }),
}));
vi.mock("../tooltip", () => {
const Wrapper = ({ children }: { children: React.ReactNode }) => (
<div>{children}</div>
);
const Content = ({ children }: { children: React.ReactNode }) => (
<div>{children}</div>
);
return {
TooltipContent: Content,
TooltipPortal: Wrapper,
TooltipProvider: Wrapper,
TooltipRoot: Wrapper,
TooltipTrigger: Wrapper,
};
});
vi.mock("radix-ui", () => {
const Primitive = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ children, ...props }, ref) => (
<div ref={ref} {...props}>
{children}
</div>
));
Primitive.displayName = "Primitive";
return {
Slider: {
Root: Primitive,
Track: Primitive,
Range: Primitive,
Thumb: Primitive,
},
};
});
describe("RangeSlider", () => {
it("formats both tooltip values without floating-point artifacts", () => {
const { getAllByText, queryByText } = render(
<RangeSlider
aria-label="Range"
min={0}
max={10}
step={0.01}
value={[1.2, 1.500000000000001]}
valueMap={(value) => value}
/>,
);
expect(getAllByText("1.2")).toHaveLength(1);
expect(getAllByText("1.5")).toHaveLength(1);
expect(queryByText("1.500000000000001")).toBeNull();
});
it("keeps the legacy precision when no step is supplied", () => {
const { getAllByText, queryByText } = render(
<RangeSlider
aria-label="Range"
min={0}
max={10}
value={[1.2, 1.500000000000001]}
valueMap={(value) => value}
/>,
);
expect(getAllByText("1.2")).toHaveLength(1);
expect(getAllByText("1.5")).toHaveLength(1);
expect(queryByText("1.500000000000001")).toBeNull();
});
it("retains value precision when no step is supplied", () => {
const { getByText } = render(
<RangeSlider
aria-label="Range"
min={0}
max={10}
value={[1.2345, 1.500000000000001]}
valueMap={(value) => value}
/>,
);
expect(getByText("1.2345")).toBeDefined();
expect(getByText("1.5")).toBeDefined();
});
it("preserves precision from finer-grained steps", () => {
const { getAllByText, queryByText } = render(
<RangeSlider
aria-label="Range"
min={0}
max={10}
step={0.001}
value={[1.234, 1.235000000000001]}
valueMap={(value) => value}
/>,
);
expect(getAllByText("1.234")).toHaveLength(1);
expect(getAllByText("1.235")).toHaveLength(1);
expect(queryByText("1.23")).toBeNull();
});
it("preserves precision for small tooltip values", () => {
const { getByText } = render(
<RangeSlider
aria-label="Range"
min={0}
max={0.01}
step={0.00001}
value={[0.00123, 0.0012400000000000002]}
valueMap={(value) => value}
/>,
);
expect(getByText("1.23e-3")).toBeDefined();
expect(getByText("1.24e-3")).toBeDefined();
});
it("infers precision from custom mapped steps", () => {
const steps = [1, 1.234, 2];
const { getAllByText } = render(
<RangeSlider
aria-label="Range"
min={0}
max={steps.length - 1}
step={1}
steps={steps}
value={[0, 1]}
valueMap={(value) => steps[value]}
/>,
);
expect(getAllByText("1")).toHaveLength(1);
expect(getAllByText("1.234")).toHaveLength(1);
});
it("preserves decimals from the slider origin", () => {
const { getAllByText } = render(
<RangeSlider
aria-label="Range"
min={0.5}
max={10.5}
step={1}
value={[0.5, 1.5]}
valueMap={(value) => value}
/>,
);
expect(getAllByText("0.5")).toHaveLength(1);
expect(getAllByText("1.5")).toHaveLength(1);
});
});