LibreChat/e2e/specs/mock/scenarios/welcome-backdrop.spec.ts
Marco Beretta 6cacfb0007
Some checks failed
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Backend Unit Tests / backend (push) Blocked by required conditions
Channel Gateway / gateway (push) Waiting to run
Codegraph E2E Vote Gate / Gate (push) Waiting to run
Codegraph E2E Votes / vote (shard 1/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 10/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 2/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 3/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 4/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 5/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 6/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 7/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 8/10) (push) Waiting to run
Codegraph E2E Votes / vote (shard 9/10) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/chat (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Frontend Unit Tests / frontend (push) Blocked by required conditions
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Waiting to run
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Blocked by required conditions
Playwright E2E Tests / Codegraph select (push) Waiting to run
Playwright E2E Tests / Shard timings (push) Waiting to run
Playwright E2E Tests / e2e () (push) Blocked by required conditions
Playwright E2E Tests / MCP list_changed (replica count 1) (push) Blocked by required conditions
Playwright E2E Tests / MCP list_changed (replica count 2) (push) Blocked by required conditions
Playwright E2E Tests / MCP Apps (browser and server) (push) Waiting to run
Playwright E2E Tests / e2e (push) Blocked by required conditions
Playwright Shard Timings / Record shard timings (push) Waiting to run
Sync README Translations / Test Translation Helpers (push) Has been cancelled
Sync README Translations / Translate README (push) Has been cancelled
🖼️ feat: Let a Theme Ask for a Welcome Backdrop (#18125)
Add theme-selected welcome backdrops and focus the composer when the welcome greeting settles. Preserve popup and touch-device focus behavior, with acceptance coverage for themes, focus, and composer layout.
2026-11-14 22:59:26 +01:00

145 lines
5.9 KiB
TypeScript

import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse';
import { NEW_CHAT_PATH, mockReply, sendMessage } from '../helpers';
/**
* The welcome screen's backdrop is a theme's to ask for and the build's to provide. The
* composer band on the welcome screen is transparent so a backdrop can show through it,
* which must leave a theme without one looking as it did; a theme that asks for a backdrop
* this build does not register keeps the plain surface. The greeting's settled cue hands a
* fine-pointer composer the caret, once per visit.
*/
test.describe.configure({ timeout: 90_000 });
test.use({ viewport: { width: 1280, height: 800 } });
const COMPOSER = '#prompt-textarea';
const BAND = '[data-composer-band]';
const GREETING_SETTLED = 'librechat:welcome-greeting-settled';
type ThemeChoice = 'clickhouse' | 'default';
/** Seeds the theme before the app reads it and counts the greeting cue. */
async function openWelcome(page: Page, theme: ThemeChoice) {
const mode = test.info().project.use.colorScheme === 'dark' ? 'dark' : 'light';
await page.addInitScript(
({ definition, theme, mode, cue }) => {
localStorage.setItem('color-theme', mode);
localStorage.removeItem('theme-colors');
localStorage.removeItem('theme-name');
if (theme === 'clickhouse') {
localStorage.setItem('theme-definition', JSON.stringify(definition));
localStorage.setItem('theme-source', 'definition');
} else {
localStorage.removeItem('theme-definition');
localStorage.removeItem('theme-source');
}
const probe = window as unknown as { __settled: number[] };
probe.__settled = [];
window.addEventListener(cue, () => probe.__settled.push(performance.now()));
},
{ definition: clickHouseTheme, theme, mode, cue: GREETING_SETTLED },
);
await page.goto(NEW_CHAT_PATH, { timeout: 15000 });
await expect(page.locator(COMPOSER)).toBeVisible({ timeout: 30000 });
}
const settledCount = (page: Page) =>
page.evaluate(() => (window as unknown as { __settled: number[] }).__settled.length);
async function waitForSettled(page: Page) {
await expect.poll(() => settledCount(page), { timeout: 20000 }).toBeGreaterThan(0);
}
/** The colour that shows behind the band: its own background, else the nearest ancestor's. */
function surfaceBehindBand(page: Page) {
return page.locator(BAND).evaluate((band) => {
for (let node: Element | null = band; node; node = node.parentElement) {
const color = getComputedStyle(node).backgroundColor;
if (color !== 'rgba(0, 0, 0, 0)' && color !== 'transparent') {
return color;
}
}
return getComputedStyle(document.body).backgroundColor;
});
}
/** The band is transparent on the welcome screen, and what shows through it is the
* surface the conversation's own band paints. */
async function expectBandKeepsTheSurface(page: Page, theme: ThemeChoice) {
await openWelcome(page, theme);
await expect(page.locator(BAND)).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)');
const onWelcome = await surfaceBehindBand(page);
await sendMessage(page, `Backdrop surface check ${theme}`);
await expect(mockReply(page)).toBeVisible({ timeout: 30000 });
await expect.poll(() => surfaceBehindBand(page)).toBe(onWelcome);
}
test.describe('welcome backdrop', () => {
test('the welcome composer sits on the surface a conversation paints @scenario:welcome-band-keeps-the-page-surface', async ({
page,
}) => {
await expectBandKeepsTheSurface(page, 'default');
});
test('the welcome composer sits on the ClickHouse surface a conversation paints @scenario:welcome-band-keeps-the-clickhouse-surface', async ({
page,
}) => {
await expectBandKeepsTheSurface(page, 'clickhouse');
});
test('a theme asking for a backdrop the build does not register keeps the plain surface @scenario:unregistered-backdrop-keeps-the-plain-surface', async ({
page,
}) => {
const errors: string[] = [];
page.on('pageerror', (error) => errors.push(error.message));
await openWelcome(page, 'clickhouse');
expect(
await page.evaluate(() =>
getComputedStyle(document.documentElement)
.getPropertyValue('--theme-welcome-backdrop')
.trim(),
),
).toBe('dots');
await expect(page.locator('main canvas')).toHaveCount(0);
expect(errors).toEqual([]);
});
test('the settled greeting hands the composer the caret on a fine pointer @scenario:greeting-hands-the-composer-focus', async ({
page,
}) => {
await openWelcome(page, 'default');
/** Nothing holds focus before the cue, so the composer may claim it. */
const blurredAt = await page.evaluate(() => {
(document.activeElement as HTMLElement | null)?.blur();
return performance.now();
});
await waitForSettled(page);
const settledAt = await page.evaluate(
() => (window as unknown as { __settled: number[] }).__settled[0],
);
expect(settledAt).toBeGreaterThan(blurredAt);
const touchFirst = await page.evaluate(
() => matchMedia('(pointer: coarse)').matches || !matchMedia('(hover: hover)').matches,
);
await expect
.poll(() => page.evaluate((selector) => document.activeElement?.matches(selector), COMPOSER))
.toBe(!touchFirst);
});
test('the screen comes alive once, not again when the title changes @scenario:greeting-cue-fires-once-per-visit', async ({
page,
}) => {
await openWelcome(page, 'default');
await waitForSettled(page);
expect(await settledCount(page)).toBe(1);
/** A temporary chat retitles the welcome screen, which animates the new title. */
await page.getByRole('button', { name: 'Temporary Chat' }).first().click();
await expect(page.locator('main .split-parent')).toContainText('Temporary Chat');
await page.waitForTimeout(2500);
expect(await settledCount(page)).toBe(1);
});
});