🧪 test: Scroll UI-Scale Conversation Rows Into View (#17188)

This commit is contained in:
Dustin Healy 2026-10-16 12:52:23 -07:00 • committed by GitHub
parent 73847f2db5
commit f64b967943
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 81 additions and 7 deletions

View file

@ -81,6 +81,38 @@ export async function deleteConversations(conversationIds: string[]): Promise<vo
});
}
/** Seed sidebar projects and return their IDs for targeted cleanup. */
export async function seedProjects(userEmail: string, names: string[]): Promise<string[]> {
return withMongo(async (db) => {
const user = await resolveUserId(db, userEmail);
const now = new Date();
const result = await db.collection('chatprojects').insertMany(
names.map((name) => ({
name,
user,
description: '',
instructions: '',
contextRevision: 0,
file_ids: [],
conversationCount: 0,
lastConversationAt: null,
lastConversationId: null,
createdAt: now,
updatedAt: now,
})),
);
return Object.values(result.insertedIds).map((id) => id.toHexString());
});
}
export async function deleteProjects(projectIds: string[]): Promise<void> {
await withMongo((db) =>
db
.collection('chatprojects')
.deleteMany({ _id: { $in: projectIds.map((id) => new ObjectId(id)) } }),
);
}
export interface SeedMessage {
messageId: string;
parentMessageId: string;

View file

@ -2,7 +2,13 @@ import { randomUUID } from 'crypto';
import { expect, test } from '@playwright/test';
import type { Locator, Page } from '@playwright/test';
import { getE2EUser } from '../../../setup/user';
import { clearUserConversations, deleteConversations, seedConversations } from '../db';
import {
clearUserConversations,
deleteConversations,
deleteProjects,
seedConversations,
seedProjects,
} from '../db';
import {
BASE_FONT_PX,
MAX_SCALE,
@ -208,16 +214,23 @@ test.describe('UI scale layout', () => {
}) => {
const user = getE2EUser();
const conversationIds = [randomUUID(), randomUUID(), randomUUID()];
const now = Date.now();
await page.setViewportSize({ width: 1280, height: 720 });
await clearUserConversations(user.email);
await seedConversations(
user.email,
conversationIds.map((conversationId, index) => ({
conversationId,
title: `Scaled row ${index + 1}`,
updatedAt: new Date(),
updatedAt: new Date(now + index * 1000),
})),
);
const projectIds = await seedProjects(
user.email,
Array.from({ length: 8 }, (_, index) => `Scale project ${index + 1}`),
);
try {
await page.goto('/c/new', { timeout: 10000 });
/* Below the drawer breakpoint the list lives in a drawer that is not
@ -228,8 +241,18 @@ test.describe('UI scale layout', () => {
await withStoredScale(page, MAX_SCALE);
await page.reload({ timeout: 15000 });
firstRow = await conversationRow(page, 'Scaled row 1');
await accountButton(page);
await expectRootFontPx(page, unscaledFont * MAX_SCALE);
const offscreenRow = page
.getByTestId('convo-item')
.filter({ hasText: 'Scaled row 1' })
.first();
await expect(offscreenRow).toBeVisible();
await expect(
offscreenRow,
'expanded projects should push the scaled conversation below the viewport',
).not.toBeInViewport();
firstRow = await conversationRow(page, 'Scaled row 1');
const scaled = await box(firstRow);
/* The rows are measured into a CellMeasurerCache; a cache that is not
@ -241,7 +264,7 @@ test.describe('UI scale layout', () => {
);
expect(clipped, 'the scaled row clips its own content').toBe(false);
} finally {
await deleteConversations(conversationIds);
await Promise.all([deleteConversations(conversationIds), deleteProjects(projectIds)]);
}
});
});

View file

@ -57,7 +57,11 @@ export async function expectRootFontPx(page: Page, expected: number) {
* and CSS-visible while translated off-canvas, so "visible" alone can hand back
* a control no one can click.
*/
async function reachable(page: Page, candidates: Locator): Promise<Locator | null> {
async function reachable(
page: Page,
candidates: Locator,
scrollIntoView = false,
): Promise<Locator | null> {
const viewport = page.viewportSize();
if (!viewport) {
return null;
@ -65,7 +69,20 @@ async function reachable(page: Page, candidates: Locator): Promise<Locator | nul
const count = await candidates.count();
for (let index = 0; index < count; index++) {
const candidate = candidates.nth(index);
const bounds = await candidate.boundingBox();
let bounds = await candidate.boundingBox();
/* A rendered conversation can sit below Projects. Only scroll candidates
in the open sidebar, never the rail translated off-canvas. */
if (
scrollIntoView &&
bounds &&
bounds.width > 0 &&
bounds.height > 0 &&
bounds.x + bounds.width > 0 &&
bounds.x < viewport.width
) {
await candidate.scrollIntoViewIfNeeded();
bounds = await candidate.boundingBox();
}
/* Intersection, not containment: the off-canvas rail sits entirely beside
the viewport, while an on-screen control may legitimately bleed a pixel. */
if (
@ -95,12 +112,13 @@ async function reachableInSidebar(
page: Page,
candidates: Locator,
label: string,
scrollIntoView = false,
): Promise<Locator> {
let found: Locator | null = null;
await expect
.poll(
async () => {
found = await reachable(page, candidates);
found = await reachable(page, candidates, scrollIntoView);
if (found) {
return true;
}
@ -137,6 +155,7 @@ export async function conversationRow(page: Page, title: string): Promise<Locato
page,
page.locator('[data-testid="convo-item"]').filter({ hasText: title }),
`the conversation row "${title}"`,
true,
);
}