Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(desktop-app): r2-m1 cover chat-drawer resize pure logic

Diego Zacarias8245ed4edbb3
diff --git a/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.test.ts b/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.test.ts
new file mode 100644
index 000000000..eec48f714
--- /dev/null
+++ b/desktop-app/ui/src/hooks/__tests__/useChatDrawerResize.test.ts
@@ -0,0 +1,73 @@
+import { describe, expect, it } from 'vitest'
+import {
+ CHAT_DRAWER_MIN_WIDTH,
+ clampWidth,
+ computeChatDrawerOverlay,
+ widthForCursor,
+} from '../useChatDrawerResize'
+
+// R2-M1: the drawer resize hook's pure logic (clamp, overlay flip, drag mapping)
+// had no direct coverage — an inverted min/max, a flipped overlay comparison, or a
+// reversed drag direction would leave every DOM-level test green. These pin the
+// three pieces at their boundaries so a sign/comparison mistake turns red.
+
+describe('clampWidth', () => {
+ it('floors a below-minimum request at CHAT_DRAWER_MIN_WIDTH', () => {
+ expect(clampWidth(100, 2000)).toBe(CHAT_DRAWER_MIN_WIDTH) // 340
+ })
+
+ it('returns an in-range request rounded to a whole pixel', () => {
+ expect(clampWidth(500.4, 2000)).toBe(500)
+ expect(clampWidth(400.6, 2000)).toBe(401)
+ })
+
+ it('caps at the absolute ceiling (820) even on a very wide panel', () => {
+ expect(clampWidth(5000, 3000)).toBe(820)
+ })
+
+ it('tightens the dynamic max to panelWidth - margin on a narrow panel', () => {
+ // panelWidth 600 - VIEWPORT_MARGIN 80 = 520, below the 820 absolute ceiling.
+ expect(clampWidth(5000, 600)).toBe(520)
+ })
+
+ it('falls back to the absolute ceiling when the panel is unmeasured (<= 0)', () => {
+ expect(clampWidth(5000, 0)).toBe(820)
+ })
+})
+
+describe('computeChatDrawerOverlay', () => {
+ // embedWidth = panelWidth - drawerWidth - GUTTER_EXTRA(46); overlay when < OVERLAY_EMBED_MIN(460).
+ it('does not overlay when the embed column is exactly at the threshold (460)', () => {
+ // 966 - 460 - 46 = 460 -> not below 460 -> false
+ expect(computeChatDrawerOverlay(966, 460)).toBe(false)
+ })
+
+ it('overlays as soon as the embed column drops one pixel below the threshold', () => {
+ // 965 - 460 - 46 = 459 -> below 460 -> true
+ expect(computeChatDrawerOverlay(965, 460)).toBe(true)
+ })
+
+ it('does not overlay on a wide panel', () => {
+ expect(computeChatDrawerOverlay(2000, 420)).toBe(false)
+ })
+
+ it('overlays on a narrow panel', () => {
+ expect(computeChatDrawerOverlay(800, 420)).toBe(true)
+ })
+})
+
+describe('widthForCursor', () => {
+ // The drawer's right edge is fixed; width = rightEdge - pointerX. A leftward drag
+ // (smaller pointerX) must WIDEN the drawer, a rightward drag must narrow it.
+ it('maps the cursor to rightEdge - pointerX, clamped', () => {
+ expect(widthForCursor(1000, 400, 2000)).toBe(600)
+ })
+
+ it('widens as the cursor moves left (smaller pointerX)', () => {
+ expect(widthForCursor(1000, 300, 2000)).toBeGreaterThan(widthForCursor(1000, 400, 2000))
+ })
+
+ it('narrows toward the minimum as the cursor moves right past the min', () => {
+ expect(widthForCursor(1000, 900, 2000)).toBe(CHAT_DRAWER_MIN_WIDTH) // rightEdge-pointerX = 100 -> 340
+ })
+})
diff --git a/desktop-app/ui/src/hooks/useChatDrawerResize.ts b/desktop-app/ui/src/hooks/useChatDrawerResize.ts
index 274e5f5a4..b9a88debc 100644
--- a/desktop-app/ui/src/hooks/useChatDrawerResize.ts
+++ b/desktop-app/ui/src/hooks/useChatDrawerResize.ts
@@ -40,7 +40,7 @@ function readPanelWidth(ref: RefObject<HTMLElement | null>): number {
}
/** Clamp a requested width to [MIN, dynamicMax], rounded to a whole pixel. */
-function clampWidth(requested: number, panelWidth: number): number {
+export function clampWidth(requested: number, panelWidth: number): number {
const dynamicMax =
panelWidth > 0
? Math.max(
@@ -51,6 +51,23 @@ function clampWidth(requested: number, panelWidth: number): number {
return Math.round(Math.max(CHAT_DRAWER_MIN_WIDTH, Math.min(dynamicMax, requested)))
}
+/** True when the app embed column would fall below the overlay threshold at the
+ * given content-panel and drawer widths — the drawer then floats over the embed
+ * instead of pushing it. Pure decision extracted from `recomputeOverlay` so the
+ * `< OVERLAY_EMBED_MIN` flip is unit-testable at the boundary. */
+export function computeChatDrawerOverlay(panelWidth: number, drawerWidth: number): boolean {
+ const embedWidth = panelWidth - drawerWidth - CHAT_DRAWER_GUTTER_EXTRA
+ return embedWidth < CHAT_DRAWER_OVERLAY_EMBED_MIN
+}
+
+/** Width the drawer should take for a cursor at `pointerX`, given the drawer's
+ * fixed right edge. Leftward drag (smaller `pointerX`) widens, rightward narrows
+ * (`rightEdge - pointerX`); result is clamped to the panel. Extracted so the drag
+ * direction is unit-testable (an inverted mapping would otherwise pass every test). */
+export function widthForCursor(rightEdge: number, pointerX: number, panelWidth: number): number {
+ return clampWidth(rightEdge - pointerX, panelWidth)
+}
+
export type ChatDrawerResize = {
/** Current drawer width in px (session-only state). */
width: number
@@ -83,8 +100,7 @@ export function useChatDrawerResize(
const panelWidth = readPanelWidth(contentPanelRef)
if (panelWidth <= 0) return
const nextWidth = overrideWidth ?? widthRef.current
- const embedWidth = panelWidth - nextWidth - CHAT_DRAWER_GUTTER_EXTRA
- setIsOverlay(embedWidth < CHAT_DRAWER_OVERLAY_EMBED_MIN)
+ setIsOverlay(computeChatDrawerOverlay(panelWidth, nextWidth))
},
[contentPanelRef]
)
@@ -126,7 +142,7 @@ export function useChatDrawerResize(
const apply = () => {
frame = 0
const panelWidth = readPanelWidth(contentPanelRef)
- const next = clampWidth(rightEdge - pointerX, panelWidth)
+ const next = widthForCursor(rightEdge, pointerX, panelWidth)
setWidth(next)
recomputeOverlay(next)
}