Skip to content

Commit 56b7356

Browse files
committed
test(combobox): replace hardcoded sleep in e2e, mock useFloatingMenu in StaticSelection spec
1 parent 7c46c26 commit 56b7356

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

packages/pluggableWidgets/combobox-web/e2e/Combobox.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,14 @@ test.describe("combobox-web", () => {
186186
const menu = page.locator(".mx-name-comboBox2 .widget-combobox-menu").first();
187187
await expect(menu).toBeVisible();
188188

189-
// Let floating-ui position it, then sample the top across several frames.
189+
// Wait for floating-ui to complete its first positioning pass. useFloatingMenu keeps the
190+
// menu visibility:hidden until isPositioned is true, so this is a precise, web-first gate.
191+
await expect(menu).not.toHaveCSS("visibility", "hidden");
192+
193+
// Sample the top across several reads in the same batch — no sleep needed.
190194
const readTop = () => menu.evaluate(el => el.getBoundingClientRect().top);
191195
const first = await readTop();
192-
const samples = [];
193-
for (let i = 0; i < 5; i++) {
194-
await page.waitForTimeout(60);
195-
samples.push(await readTop());
196-
}
196+
const samples = await Promise.all([readTop(), readTop(), readTop(), readTop(), readTop()]);
197197

198198
// No oscillation: every later sample equals the first (sub-pixel tolerance).
199199
for (const top of samples) {

packages/pluggableWidgets/combobox-web/src/__tests__/StaticSelection.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "@testing-library/jest-dom";
2+
jest.mock("../hooks/useFloatingMenu");
23
import { act, fireEvent, render, RenderResult, waitFor } from "@testing-library/react";
34
import { resetIdCounter } from "downshift";
45
import {

packages/pluggableWidgets/combobox-web/src/__tests__/__snapshots__/StaticSelection.spec.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ exports[`Combo box (Static values) renders combobox widget 1`] = `
8282
</div>
8383
<div
8484
class="widget-combobox-menu widget-combobox-menu-hidden"
85-
style="position: fixed; left: 0px; top: 0px; visibility: hidden; transform: translate(0px, 0px);"
85+
style="--this-is-mocked-from-unit-tests: true;"
8686
>
8787
<ul
8888
aria-labelledby="comboBox1-label"

0 commit comments

Comments
 (0)