Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
test(webv2): stop two more browser tests inheriting the previous test's cursor
Lincoln Steinc5de5395cf62
diff --git a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceBars.browser.test.tsx b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceBars.browser.test.tsxindex 8078adab1c..4804072598 100644--- a/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceBars.browser.test.tsx+++ b/invokeai/frontend/webv2/src/features/generation/ui/shared/ConditioningRebalanceBars.browser.test.tsx@@ -4,6 +4,7 @@ import { system } from '@theme/system';import { act } from 'react';import { createRoot, type Root } from 'react-dom/client';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { userEvent } from 'vitest/browser';import { ConditioningRebalanceBars } from './ConditioningRebalanceBars';@@ -65,6 +66,33 @@ const lastPreview = (): number[] => (onPreview.mock.calls.at(-1)?.[0] as number[const lastCommit = (): number[] => (onCommit.mock.calls.at(-1)?.[0] as number[] | undefined) ?? [];+/**+ * Puts the pointer somewhere harmless and undoes any scroll a previous test+ * left behind.+ *+ * Every tap here is a synthetic PointerEvent at a computed coordinate, but the+ * *real* cursor keeps whatever position the last test gave it. Left over the+ * track, it emits its own pointer events at its own location, and the component+ * dutifully reports that index — an instrumented failure showed the intended+ * `7` arriving and then a spurious `6` after it, which is what breaks+ * `toHaveBeenLastCalledWith`. The same run showed the track's `left` at -393+ * rather than 0, i.e. the document had been scrolled sideways by another test,+ * which moves which bar the stationary cursor is over.+ */+const resetPointerAndScroll = async (): Promise<void> => {+ const parking = document.createElement('div');++ parking.style.cssText = 'position:fixed;right:0;bottom:0;width:2px;height:2px;z-index:2147483647';+ document.body.append(parking);++ await act(async () => {+ await userEvent.hover(parking);+ });++ parking.remove();+ window.scrollTo(0, 0);+};+beforeEach(() => {host = document.createElement('div');document.body.append(host);@@ -79,6 +107,7 @@ afterEach(async () => {host?.remove();host = null;root = null;+ await resetPointerAndScroll();});describe('ConditioningRebalanceBars', () => {diff --git a/invokeai/frontend/webv2/src/platform/ui/hints/FeatureHint.browser.test.tsx b/invokeai/frontend/webv2/src/platform/ui/hints/FeatureHint.browser.test.tsxindex 662fc3d437..3cd6d715ff 100644--- a/invokeai/frontend/webv2/src/platform/ui/hints/FeatureHint.browser.test.tsx+++ b/invokeai/frontend/webv2/src/platform/ui/hints/FeatureHint.browser.test.tsx@@ -36,11 +36,36 @@ let host: HTMLDivElement | null = null;let root: Root | null = null;(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;+/**+ * Returns the pointer to the viewport origin — where the harness below states+ * it starts.+ *+ * That only holds for the first test. Once one has hovered the trigger the+ * cursor stays on it, so the next render mounts a fresh trigger underneath the+ * pointer and the card opens before the test asks for it. That surfaced as a+ * strict-mode violation, with `CLIP skip` matching both the trigger and the+ * already-open card's own heading and paragraph. The trigger is inset by+ * 120px, so the origin is reliably clear of it.+ */+const parkPointer = async (): Promise<void> => {+ const parking = document.createElement('div');++ parking.style.cssText = 'position:fixed;left:0;top:0;width:2px;height:2px;z-index:2147483647';+ document.body.append(parking);++ await act(async () => {+ await userEvent.hover(parking);+ });++ parking.remove();+};+afterEach(async () => {await act(() => root?.unmount());host?.remove();host = null;root = null;+ await parkPointer();});const settle = (ms: number): Promise<void> =>@@ -83,6 +108,28 @@ const render = async (adapter: FeatureHintsAdapter) => {const cardText = (): string =>document.querySelector('[data-scope="hover-card"][data-part="content"]')?.textContent ?? '';+/**+ * Waits for the hover card to actually open, rather than sleeping past its+ * open delay and hoping.+ *+ * The fixed 900ms wait this replaces was comfortably longer than the delay on+ * an idle machine and not always long enough on a loaded CI runner, where the+ * card had not opened yet and every assertion below read an empty string.+ * Polling takes as long as the machine needs and fails loudly if the card+ * never appears.+ */+const waitForCard = async (timeoutMs = 5000): Promise<void> => {+ const deadline = Date.now() + timeoutMs;++ while (cardText() === '') {+ if (Date.now() > deadline) {+ throw new Error(`Timed out after ${timeoutMs}ms waiting for the hint card to open`);+ }++ await settle(16);+ }+};+describe('FeatureHint', () => {it('renders the child untouched and mounts no popper while hints are off', async () => {const trigger = await render({ enabled: false, onDisable: vi.fn() });@@ -108,7 +155,7 @@ describe('FeatureHint', () => {});// Guard against a false pass from an instantly-open card.expect(cardText()).toBe('');- await settle(900);+ await waitForCard();expect(cardText()).toContain('CLIP Skip');expect(cardText()).toContain('How many layers of the CLIP model to skip.');@@ -122,7 +169,7 @@ describe('FeatureHint', () => {await act(async () => {await userEvent.hover(trigger);});- await settle(900);+ await waitForCard();const dismiss = [...document.querySelectorAll('button')].find((button) => button.textContent === "Don't show me these"@@ -142,7 +189,7 @@ describe('FeatureHint', () => {await act(async () => {await userEvent.hover(trigger);});- await settle(900);+ await waitForCard();expect(cardText()).toContain('CLIP Skip');expect(cardText()).not.toContain("Don't show me these");