test(ui): assert which element the chips-combobox popup anchors to

The previous assertion read data-chips, which is derived from the anchor prop
being truthy, so it stayed true even when the ref never reached the DOM and the
popup was still anchored to the inner input.

Stub distinct widths on the chips container and the input, then read the width
the positioner resolved. Reverting the anchor wiring now reports the input's
width instead of the field's, which is the actual bug.
This commit is contained in:
Yuneng Jiang 2026-08-14 18:03:34 -07:00
parent 6e38e9490d
commit c7084c04c0
No known key found for this signature in database

View file

@ -23,13 +23,34 @@ const openPopup = async (input: HTMLElement) => {
});
};
const stubWidth = (element: Element, width: number) =>
vi.spyOn(element, "getBoundingClientRect").mockReturnValue({
width,
height: 32,
top: 0,
left: 0,
right: width,
bottom: 32,
x: 0,
y: 0,
toJSON: () => ({}),
} as DOMRect);
const CHIPS_WIDTH = 300;
const INPUT_WIDTH = 200;
describe("MultiSelect", () => {
it("anchors the popup to the chips container rather than the inner input", async () => {
const { input } = renderMultiSelect();
const chips = input.closest("[data-slot='combobox-chips']");
expect(chips).not.toBeNull();
stubWidth(chips as Element, CHIPS_WIDTH);
stubWidth(input, INPUT_WIDTH);
const popup = await openPopup(input);
const positioner = popup.parentElement as HTMLElement;
expect(popup).toHaveAttribute("data-chips", "true");
expect(positioner.style.getPropertyValue("--anchor-width")).toBe(`${CHIPS_WIDTH}px`);
});
it("reports the selected option values", async () => {