refactor(B166): endurece e2e (poll determinístico) e clamp exato após revisão

This commit is contained in:
Francisco Solla 2026-08-08 16:04:54 -03:00
parent 2ca1afa6a7
commit 441c8d1156
3 changed files with 21 additions and 8 deletions

View file

@ -44,7 +44,7 @@ export const clearSavedChatWidthPx = (): void => {
} }
const clamp = (value: number, min: number, max: number): number => const clamp = (value: number, min: number, max: number): number =>
Math.min(Math.max(value, min), Math.max(min, max)) Math.min(Math.max(value, min), max)
/** Default open width: 25% of the group, capped at `CHAT_DEFAULT_MAX_PX`. */ /** Default open width: 25% of the group, capped at `CHAT_DEFAULT_MAX_PX`. */
export const defaultChatWidthPx = (groupWidthPx: number): number => export const defaultChatWidthPx = (groupWidthPx: number): number =>
@ -52,7 +52,9 @@ export const defaultChatWidthPx = (groupWidthPx: number): number =>
/** /**
* Width for the next open: the remembered choice wins (even above the cap), * Width for the next open: the remembered choice wins (even above the cap),
* otherwise the capped 25% default. Always bounded to `[CHAT_MIN_PX, group]`. * otherwise the capped 25% default. Bounded to `CHAT_MIN_PX` and to the group
* itself — a group narrower than the floor (degenerate layout) yields the
* group width, and the library re-clamps the rendered panel at its `minSize`.
*/ */
export const resolveChatPanelWidthPx = (groupWidthPx: number, savedPx: number | null): number => export const resolveChatPanelWidthPx = (groupWidthPx: number, savedPx: number | null): number =>
savedPx === null ? defaultChatWidthPx(groupWidthPx) : clamp(savedPx, CHAT_MIN_PX, groupWidthPx) savedPx === null ? defaultChatWidthPx(groupWidthPx) : clamp(savedPx, CHAT_MIN_PX, groupWidthPx)

View file

@ -29,6 +29,7 @@ const panelWidth = (panel: Locator) => panel.evaluate((element) => element.clien
const dragSeparatorBy = async (page: Page, deltaX: number) => { const dragSeparatorBy = async (page: Page, deltaX: number) => {
const separator = chatSeparator(page) const separator = chatSeparator(page)
await expect(separator).toBeVisible()
const box = (await separator.boundingBox())! const box = (await separator.boundingBox())!
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2) await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2)
await page.mouse.down() await page.mouse.down()
@ -65,12 +66,14 @@ test.describe('B166 — largura padrão do chat Sollinha com teto no desktop', (
const resizedWidth = await panelWidth(panel) const resizedWidth = await panelWidth(panel)
// The chosen size was saved locally: a page reload reopens at it, not at // The chosen size was saved locally: a page reload reopens at it, not at
// the capped default. // the capped default. Poll against the dragged size (the raw 25% first
// paint would already pass a bare ">360" gate, so wait for the restore).
await page.reload() await page.reload()
await expect(panel).toBeVisible() await expect(panel).toBeVisible()
await expect.poll(() => panelWidth(panel)).toBeGreaterThan(360) await expect
.poll(async () => Math.abs((await panelWidth(panel)) - resizedWidth))
.toBeLessThanOrEqual(4)
const restoredWidth = await panelWidth(panel) const restoredWidth = await panelWidth(panel)
expect(Math.abs(restoredWidth - resizedWidth)).toBeLessThanOrEqual(4)
// Reopening via the header button (acceptance 1 — "pelo botão") restores // Reopening via the header button (acceptance 1 — "pelo botão") restores
// the same remembered width instead of a fresh cap. // the same remembered width instead of a fresh cap.
@ -83,8 +86,8 @@ test.describe('B166 — largura padrão do chat Sollinha com teto no desktop', (
.getByRole('button', { name: 'Sollinha — Assistente virtual' }) .getByRole('button', { name: 'Sollinha — Assistente virtual' })
.filter({ visible: true }) .filter({ visible: true })
.click() .click()
await expect.poll(() => panelWidth(panel)).toBeGreaterThan(360) await expect
const buttonOpenWidth = await panelWidth(panel) .poll(async () => Math.abs((await panelWidth(panel)) - restoredWidth))
expect(Math.abs(buttonOpenWidth - restoredWidth)).toBeLessThanOrEqual(4) .toBeLessThanOrEqual(4)
}) })
}) })

View file

@ -59,6 +59,10 @@ describe('defaultChatWidthPx', () => {
expect(defaultChatWidthPx(1000)).toBe(CHAT_MIN_PX) expect(defaultChatWidthPx(1000)).toBe(CHAT_MIN_PX)
expect(defaultChatWidthPx(700)).toBe(CHAT_MIN_PX) expect(defaultChatWidthPx(700)).toBe(CHAT_MIN_PX)
}) })
it('yields the group width for a group narrower than the floor', () => {
expect(defaultChatWidthPx(200)).toBe(200)
})
}) })
describe('resolveChatPanelWidthPx', () => { describe('resolveChatPanelWidthPx', () => {
@ -78,4 +82,8 @@ describe('resolveChatPanelWidthPx', () => {
it('clamps a saved choice below the floor up to CHAT_MIN_PX', () => { it('clamps a saved choice below the floor up to CHAT_MIN_PX', () => {
expect(resolveChatPanelWidthPx(1920, 150)).toBe(CHAT_MIN_PX) expect(resolveChatPanelWidthPx(1920, 150)).toBe(CHAT_MIN_PX)
}) })
it('yields the group width for a saved choice on a group narrower than the floor', () => {
expect(resolveChatPanelWidthPx(200, 520)).toBe(200)
})
}) })