LibreChat/e2e/specs/mock/scenarios/sidebar-focus.spec.ts
Marco Beretta c380c9e5d5
🧪 test: Stabilize the Sidebar Focus and Fold Tree Scenarios (#18030)
- sidebar-focus: an installed clock runs until paused, so pausing at the
  test process's "now" could land behind it and Playwright refused with
  "Cannot fast-forward to the past". The clock now starts at a known time
  and pauses a few seconds after it.
- fold-tree: the hover ran about 15 ms after the fold reported expanded,
  while its height was still animating. Rows moved under the still
  pointer and the fold, by design, lit the row now under it. The fold is
  hovered only once nothing in the transcript moves, and the test checks
  which row is lit before measuring the route.
2026-11-10 15:01:01 -05:00

28 lines
1.3 KiB
TypeScript

import { expect, test } from '@playwright/test';
import { NEW_CHAT_PATH } from '../helpers';
/** Resize from desktop to exercise the fallback before the drawer animator owns opening. */
test('opening the sidebar preserves focus moved during its delay @scenario:sidebar-preserves-deliberate-focus', async ({
page,
}) => {
await page.setViewportSize({ width: 1280, height: 800 });
await page.addInitScript(() => localStorage.setItem('unifiedSidebarExpanded', 'false'));
await page.goto(NEW_CHAT_PATH);
await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible();
await page.setViewportSize({ width: 390, height: 844 });
const opener = page.getByTestId('header-open-sidebar-button');
await expect(opener).toBeVisible();
/** An installed clock keeps running until paused, so pausing "now" can land behind it. */
const start = Date.now();
await page.clock.install({ time: start });
await page.clock.pauseAt(start + 5_000);
await opener.click();
await page.clock.runFor(100);
const close = page.getByTestId('close-sidebar-button');
await expect(close).toBeVisible();
const newChat = page.locator('#mobile-drawer').getByTestId('nav-new-chat-fab');
await newChat.focus();
await expect(newChat).toBeFocused();
await page.clock.runFor(300);
await expect(newChat).toBeFocused();
});