test: de-flake cart-drawer overflow spec via consent pre-seed#69
Conversation
The cart-drawer footer test dismissed the first-visit analytics-consent banner reactively (click "decline" if visible after load). On a fresh context the banner could render a beat after the visibility check, stay up, overlay the drawer footer, and intercept pointer events → flaky fail. Pre-seed the consent choice in localStorage via addInitScript BEFORE navigation so the banner never renders. Deterministic, simpler, faster; scope is this one test — no product-code change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the cart_drawer_overflow.spec.ts end-to-end test to pre-set the analytics consent choice to 'denied' in localStorage using page.addInitScript before navigating. This replaces the previous logic that attempted to dynamically find and click the decline button on the consent banner. The reviewer suggested also setting window.__ohbmAnalyticsConsent = 'denied' in the init script to ensure the banner is successfully blocked even in environments where localStorage is disabled or throws an error.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| await page.addInitScript(() => { | ||
| try { | ||
| localStorage.setItem('ohbm2026.analytics.consent.v1', 'denied'); | ||
| } catch { | ||
| /* storage unavailable — banner will show; not this test's concern */ | ||
| } | ||
| }); |
There was a problem hiding this comment.
To make the consent suppression even more robust, we can also set window.__ohbmAnalyticsConsent = 'denied' directly in the init script.
Since ConsentBanner.svelte checks window.__ohbmAnalyticsConsent on mount and suppresses the banner if it is set to 'denied', doing this ensures the banner is successfully blocked even in test environments where localStorage is disabled or throws an error.
| await page.addInitScript(() => { | |
| try { | |
| localStorage.setItem('ohbm2026.analytics.consent.v1', 'denied'); | |
| } catch { | |
| /* storage unavailable — banner will show; not this test's concern */ | |
| } | |
| }); | |
| await page.addInitScript(() => { | |
| try { | |
| localStorage.setItem('ohbm2026.analytics.consent.v1', 'denied'); | |
| } catch { | |
| /* storage unavailable — banner will show; not this test's concern */ | |
| } | |
| (window as any).__ohbmAnalyticsConsent = 'denied'; | |
| }); |
|
Thanks @gemini-code-assist — I checked the bootstrap and am not taking this suggestion, because setting the global in
(For transparency: on the CI preview host the path is |
|
Thanks for the detailed explanation, @satra. That makes perfect sense. I appreciate the clarification on how the |
Summary
De-flakes
site/src/tests/e2e/cart_drawer_overflow.spec.ts. The test dismissed the first-visit analytics-consent banner reactively — clicking "decline" only if the banner happened to be visible at the moment it checked. On a fresh context the banner can render a beat after that check, stay up, overlay the cart drawer's footer buttons, and intercept pointer events, failing the test intermittently.This pre-seeds the consent choice in
localStorageviapage.addInitScriptbefore navigation, so the banner never renders. Deterministic, simpler, and faster.Scope
Verification
prettier(the one remaining prettier warning on this file is a pre-existing long line I did not touch).🤖 Generated with Claude Code