Skip to content

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.

test(webv2): adapt browser tests to Vitest 5, Chakra 3.37 and router 1.170

Josh Corbett016dfc40edaa
diff --git a/invokeai/frontend/webv2/src/app/AccountLifecycleCoordinator.browser.test.tsx b/invokeai/frontend/webv2/src/app/AccountLifecycleCoordinator.browser.test.tsx
index b0a98ff792..996c5ad552 100644
--- a/invokeai/frontend/webv2/src/app/AccountLifecycleCoordinator.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/app/AccountLifecycleCoordinator.browser.test.tsx
@@ -211,7 +211,9 @@ describe('authenticated route account lifecycle', () => {
sessionStore.setSnapshot(signedInSession(1));
const { router } = await import('./router');
- await router.load();
+ // The provider drives this load. It installs the router's transition hook
+ // and leaves it in place on unmount, so a pre-render `router.load()` on the
+ // router the previous test rendered would wait for a commit that never comes.
host = document.createElement('div');
document.body.append(host);
root = createRoot(host);
@@ -219,9 +221,9 @@ describe('authenticated route account lifecycle', () => {
root?.render(<RouterProvider router={router} />);
});
+ await expect.poll(() => host?.querySelector('[data-testid="authenticated-runtime"]')).not.toBeNull();
const initialPath = router.state.location.pathname;
const initialRuntime = host.querySelector<HTMLElement>('[data-testid="authenticated-runtime"]');
- expect(initialRuntime).not.toBeNull();
await act(() => {
sessionStore.setSnapshot(signedInSession(2));
diff --git a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx
index 7013052cc2..0dcd17da16 100644
--- a/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/image-actions/ImageContextMenu.browser.test.tsx
@@ -97,7 +97,18 @@ const settleUntil = async (isSettled: () => boolean, description: string, timeou
const pickQuickItem = async (label: string): Promise<void> => {
const target = document.querySelector<HTMLElement>(`[aria-label="${label}"]`);
expect(target).not.toBeNull();
- await interact(() => target!.dispatchEvent(new PointerEvent('pointermove', { bubbles: true, pointerType: 'mouse' })));
+ // zag only treats a move as a real hover when the pointer position changes,
+ // so approach the item's center from one pixel away instead of a static point.
+ const rect = target!.getBoundingClientRect();
+ const clientX = rect.left + rect.width / 2;
+ const clientY = rect.top + rect.height / 2;
+ await interact(() => {
+ for (const x of [clientX - 1, clientX]) {
+ target!.dispatchEvent(
+ new PointerEvent('pointermove', { bubbles: true, clientX: x, clientY, pointerType: 'mouse' })
+ );
+ }
+ });
// zag applies `data-highlighted` asynchronously and ignores a click on an unhighlighted item, so
// a fixed wait here silently dropped the click whenever the machine needed longer than it --
// the action mock simply recorded no call, and only under CI load.
diff --git a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.browser.test.tsx
index f515d2ecac..244fd02e26 100644
--- a/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/settings/SettingsDialogHost.browser.test.tsx
@@ -93,7 +93,7 @@ it('keeps a named modal through loading, failure, retry, and closing before rest
expect(isHotkeyModalLayerActive()).toBe(true);
await act(() => initialLoad.reject(new Error('Settings chunk unavailable')));
- await expect.element(page.getByRole('alert')).toHaveTextContent(i18n.t('settingsDialog.loadFailed'));
+ await expect.element(page.getByRole('alert')).toMatchTextContent(i18n.t('settingsDialog.loadFailed'));
await expect.element(page.getByRole('dialog', { name: 'Settings', exact: true })).toBeVisible();
const retry = page.getByRole('button', { name: i18n.t('common.retry'), exact: true });
await expect.element(retry).toBeEnabled();
diff --git a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetManagerDialogBody.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetManagerDialogBody.browser.test.tsx
index 933280515c..660252e445 100644
--- a/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetManagerDialogBody.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/shell/topbar/LayoutPresetManagerDialogBody.browser.test.tsx
@@ -116,6 +116,9 @@ describe('LayoutPresetManagerDialogBody', () => {
it('reorders presets from a focused row handle with the keyboard', async () => {
await renderManager();
+ // The dialog places its initial focus asynchronously after mount; focusing
+ // the handle before that lands would be undone by it.
+ await expect.poll(() => document.querySelector('[role="dialog"]')?.contains(document.activeElement)).toBe(true);
const handle = dragHandle('Custom');
expect(handle).not.toBeNull();
handle!.focus();