diff --git a/src/lib/sollinhaChatPanelWidth.ts b/src/lib/sollinhaChatPanelWidth.ts index f263cdf6..8758f48d 100644 --- a/src/lib/sollinhaChatPanelWidth.ts +++ b/src/lib/sollinhaChatPanelWidth.ts @@ -44,7 +44,7 @@ export const clearSavedChatWidthPx = (): void => { } 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`. */ 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), - * 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 => savedPx === null ? defaultChatWidthPx(groupWidthPx) : clamp(savedPx, CHAT_MIN_PX, groupWidthPx) diff --git a/tests/e2e/campaignSollinhaWidth.e2e.spec.ts b/tests/e2e/campaignSollinhaWidth.e2e.spec.ts index 0aa6df28..0c848098 100644 --- a/tests/e2e/campaignSollinhaWidth.e2e.spec.ts +++ b/tests/e2e/campaignSollinhaWidth.e2e.spec.ts @@ -29,6 +29,7 @@ const panelWidth = (panel: Locator) => panel.evaluate((element) => element.clien const dragSeparatorBy = async (page: Page, deltaX: number) => { const separator = chatSeparator(page) + await expect(separator).toBeVisible() const box = (await separator.boundingBox())! await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2) 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) // 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 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) - expect(Math.abs(restoredWidth - resizedWidth)).toBeLessThanOrEqual(4) // Reopening via the header button (acceptance 1 — "pelo botão") restores // 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' }) .filter({ visible: true }) .click() - await expect.poll(() => panelWidth(panel)).toBeGreaterThan(360) - const buttonOpenWidth = await panelWidth(panel) - expect(Math.abs(buttonOpenWidth - restoredWidth)).toBeLessThanOrEqual(4) + await expect + .poll(async () => Math.abs((await panelWidth(panel)) - restoredWidth)) + .toBeLessThanOrEqual(4) }) }) diff --git a/tests/unit/sollinhaChatPanelWidth.unit.spec.ts b/tests/unit/sollinhaChatPanelWidth.unit.spec.ts index 71ce2233..9dd27730 100644 --- a/tests/unit/sollinhaChatPanelWidth.unit.spec.ts +++ b/tests/unit/sollinhaChatPanelWidth.unit.spec.ts @@ -59,6 +59,10 @@ describe('defaultChatWidthPx', () => { expect(defaultChatWidthPx(1000)).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', () => { @@ -78,4 +82,8 @@ describe('resolveChatPanelWidthPx', () => { it('clamps a saved choice below the floor up to 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) + }) })