From 7f84884804715e98b4ae8e1fb39acd6da521d549 Mon Sep 17 00:00:00 2001 From: corescope-bot Date: Thu, 21 May 2026 20:59:03 +0000 Subject: [PATCH] test(color-picker): use real mouse click + wait for listener install (#1300) The outside-click test invoked document.body.click() via page.evaluate, which races the popover's deferred (setTimeout 0) document-level click listener registration AND uses HTMLElement.click() rather than a real PointerEvent. Both modes can let the listener miss the synthesized click, leaving the popover open and timing out waitForFunction at 8s. Fix: wait for the popover to actually have layout (proxy for listener install), then page.mouse.click(700, 500) which dispatches a real MouseEvent at a coordinate outside the popover (anchored at 100,100). Bump close-wait timeout to 15s as belt-and-suspenders. Test-only change; channel-color-picker.js untouched. --- test-channel-color-picker-e2e.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test-channel-color-picker-e2e.js b/test-channel-color-picker-e2e.js index e6003f2f..5081b8c4 100644 --- a/test-channel-color-picker-e2e.js +++ b/test-channel-color-picker-e2e.js @@ -165,14 +165,24 @@ function assert(c, m) { if (!c) throw new Error(m || 'assertion failed'); } await page.evaluate(() => window.ChannelColorPicker.show('#outsidechan', 100, 100)); await page.waitForSelector('.cc-picker-popover'); - // Click body far away - await page.evaluate(() => { - document.body.click(); - }); + // Wait for the deferred (setTimeout 0) document-level click listener + // to be installed before dispatching the outside click. Otherwise the + // click races the listener registration and the popover stays open. + await page.waitForFunction(() => { + const el = document.querySelector('.cc-picker-popover'); + const rect = el && el.getBoundingClientRect(); + return rect && rect.width > 0 && rect.height > 0; + }, { timeout: 5000 }); + // Real mouse click at a viewport coordinate that is clearly outside + // the popover (popover anchored at 100,100; click at 700,500). + // page.mouse.click dispatches PointerEvent + MouseEvent with real + // coords, more representative than HTMLElement.click() and reliably + // reaches the document-level capture-phase listener. + await page.mouse.click(700, 500); await page.waitForFunction(() => { const el = document.querySelector('.cc-picker-popover'); return el && el.style.display === 'none'; - }, { timeout: 3000 }); + }, { timeout: 15000 }); }); // Cleanup