mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
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:
parent
6e38e9490d
commit
c7084c04c0
1 changed files with 22 additions and 1 deletions
|
|
@ -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 () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue