🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import {
createPeekPanelStore,
PEEK_DEFAULT_WIDTH_FRACTION,
PEEK_MAX_DEFAULT_WIDTH_PX,
PEEK_MAX_WIDGET_WIDTH_FRACTION,
PEEK_MIN_WIDTH_FRACTION,
resolveDefaultWidthFraction,
resolveEffectiveWidthFraction,
selectDraftExpanded,
selectWidgetWidth,
} from "@/src/components/table/peek/store/peekPanelStore";
const STORAGE_KEY = "peekViewWidthFraction";
const pct = (fraction: number) => `${fraction * 100}vw`;
// jsdom's default innerWidth is 1024; override per-test to exercise the
// viewport-aware default, then restore.
function withViewportWidth(width: number, run: () => void) {
const original = window.innerWidth;
Object.defineProperty(window, "innerWidth", {
value: width,
configurable: true,
writable: true,
});
try {
run();
} finally {
Object.defineProperty(window, "innerWidth", {
value: original,
configurable: true,
writable: true,
});
}
}
describe("peekPanelStore", () => {
beforeEach(() => window.localStorage.clear());
afterEach(() => window.localStorage.clear());
it("defaults to the widget width, not resizing or expanded", () => {
const store = createPeekPanelStore();
const state = store.getState();
expect(state.isResizing).toBe(false);
expect(state.draftExpanded).toBe(false);
expect(state.widthFraction).toBeCloseTo(PEEK_DEFAULT_WIDTH_FRACTION);
expect(selectWidgetWidth(state)).toBe(pct(PEEK_DEFAULT_WIDTH_FRACTION));
});
describe("default width caps px growth on wide screens (LFE-10601)", () => {
it("keeps 50vw on a normal laptop where 50vw is under the px cap", () => {
withViewportWidth(1440, () => {
expect(resolveDefaultWidthFraction()).toBeCloseTo(
PEEK_DEFAULT_WIDTH_FRACTION,
);
expect(createPeekPanelStore().getState().widthFraction).toBeCloseTo(
PEEK_DEFAULT_WIDTH_FRACTION,
);
});
});
it("trims the fraction on a wide screen so the peek stays near the px cap", () => {
// 3000px: 50vw = 1500px > cap → fraction shrinks so width ≈ cap.
withViewportWidth(3000, () => {
const fraction = resolveDefaultWidthFraction();
expect(fraction).toBeLessThan(PEEK_DEFAULT_WIDTH_FRACTION);
expect(fraction * 3000).toBeCloseTo(PEEK_MAX_DEFAULT_WIDTH_PX, 0);
expect(createPeekPanelStore().getState().widthFraction).toBeCloseTo(
fraction,
);
});
});
it("never falls below the drag minimum, even on an ultra-wide screen", () => {
withViewportWidth(6000, () => {
expect(resolveDefaultWidthFraction()).toBeCloseTo(
PEEK_MIN_WIDTH_FRACTION,
);
});
});
it("a saved preference always wins over the viewport-aware default", () => {
withViewportWidth(3000, () => {
window.localStorage.setItem(STORAGE_KEY, "0.5");
expect(createPeekPanelStore().getState().widthFraction).toBeCloseTo(
0.5,
);
});
});
});
it("reads and clamps the persisted width on creation", () => {
window.localStorage.setItem(STORAGE_KEY, "0.7");
expect(createPeekPanelStore().getState().widthFraction).toBeCloseTo(0.7);
window.localStorage.setItem(STORAGE_KEY, "5");
expect(createPeekPanelStore().getState().widthFraction).toBeCloseTo(
PEEK_MAX_WIDGET_WIDTH_FRACTION,
);
});
it("fits a local default without replacing other views' preference, then retains an explicit resize", () => {
window.localStorage.setItem(STORAGE_KEY, "0.7");
const localKey = "peek-width-topics";
const store = createPeekPanelStore({ widthStorageKey: localKey });
store.getState().actions.setDefaultWidth(0.3);
expect(selectWidgetWidth(store.getState())).toBe("30vw");
store.getState().actions.setDefaultWidth(0.96);
expect(selectWidgetWidth(store.getState())).toBe("96vw");
store.getState().actions.setDefaultWidth(0.35);
expect(selectWidgetWidth(store.getState())).toBe("35vw");
expect(window.localStorage.getItem(STORAGE_KEY)).toBe("0.7");
expect(window.localStorage.getItem(localKey)).toBeNull();
store.getState().actions.commitWidth(0.55);
store.getState().actions.setDefaultWidth(0.32);
expect(selectWidgetWidth(store.getState())).toBe(pct(0.55));
expect(window.localStorage.getItem(localKey)).toBe("0.55");
expect(window.localStorage.getItem(STORAGE_KEY)).toBe("0.7");
const reopened = createPeekPanelStore({ widthStorageKey: localKey });
reopened.getState().actions.setDefaultWidth(0.32);
expect(reopened.getState().widthFraction).toBe(0.55);
});
it("sizes a scoped peek's inner layout from its live width instead of the shared preference", () => {
withViewportWidth(1600, () => {
window.localStorage.setItem(STORAGE_KEY, "0.4");
const store = createPeekPanelStore({
widthStorageKey: "peek-width-topics",
allowLayoutWidths: true,
});
store.getState().actions.setDefaultWidth(1000 / 1600);
expect(
resolveEffectiveWidthFraction({
widgetWidthFraction: store.getState().widthFraction,
}) * window.innerWidth,
).toBe(1000);
expect(resolveEffectiveWidthFraction() * window.innerWidth).toBe(640);
});
});
it("caps widget and expanded layout widths at the sidebar edge", () => {
withViewportWidth(1600, () => {
expect(
resolveEffectiveWidthFraction({
widgetWidthFraction: 0.96,
sidebarOffsetPx: 240,
}) * window.innerWidth,
).toBe(1360);
expect(
resolveEffectiveWidthFraction({
widgetWidthFraction: 0.5,
isExpanded: true,
sidebarOffsetPx: 240,
}) * window.innerWidth,
).toBe(1360);
expect(
resolveEffectiveWidthFraction({
isExpanded: true,
sidebarOffsetPx: 1800,
}),
).toBe(0);
});
});
it("returns to a narrow layout width without reversing keyboard or drag resizing", () => {
const store = createPeekPanelStore({
widthStorageKey: "peek-width-topics",
});
const { actions } = store.getState();
actions.setDefaultWidth(0.35);
actions.nudgeWidth("shrink");
expect(store.getState().widthFraction).toBeCloseTo(0.35);
actions.nudgeWidth("grow");
actions.nudgeWidth("shrink");
expect(store.getState().widthFraction).toBeCloseTo(0.35);
actions.setDraftFraction(0.36);
expect(store.getState().draftFraction).toBeCloseTo(0.36);
actions.commitWidth(0.36);
expect(store.getState().widthFraction).toBeCloseTo(0.36);
const reopened = createPeekPanelStore({
widthStorageKey: "peek-width-topics",
allowLayoutWidths: true,
});
reopened.getState().actions.setDefaultWidth(0.45);
expect(reopened.getState().widthFraction).toBeCloseTo(0.36);
reopened.getState().actions.nudgeWidth("shrink");
expect(reopened.getState().widthFraction).toBeCloseTo(0.36);
});
it("does not shrink a wide layout width when asked to grow", () => {
const store = createPeekPanelStore({
widthStorageKey: "peek-width-topics",
});
const { actions } = store.getState();
actions.setDefaultWidth(0.96);
actions.nudgeWidth("grow");
expect(store.getState().widthFraction).toBeCloseTo(0.96);
actions.nudgeWidth("shrink");
expect(store.getState().widthFraction).toBeCloseTo(0.91);
actions.setDraftFraction(0.93);
expect(store.getState().draftFraction).toBeCloseTo(0.93);
actions.commitWidth(0.93);
const reopened = createPeekPanelStore({
widthStorageKey: "peek-width-topics",
allowLayoutWidths: true,
});
expect(reopened.getState().widthFraction).toBeCloseTo(0.93);
});
it("commitWidth clamps, persists, and clears the draft", () => {
const store = createPeekPanelStore();
store.getState().actions.setDraftExpanded();
store.getState().actions.commitWidth(0.72);
const state = store.getState();
expect(state.widthFraction).toBeCloseTo(0.72);
expect(state.draftFraction).toBeNull();
expect(state.draftExpanded).toBe(false);
expect(window.localStorage.getItem(STORAGE_KEY)).toBe("0.72");
});
it("setDraftFraction drives the live widget width (and clears draftExpanded)", () => {
const store = createPeekPanelStore();
store.getState().actions.setDraftExpanded();
store.getState().actions.setDraftFraction(0.42);
const state = store.getState();
expect(state.draftExpanded).toBe(false);
expect(selectWidgetWidth(state)).toBe(pct(0.42));
// The committed width preference is untouched until pointer-up.
expect(state.widthFraction).toBeCloseTo(PEEK_DEFAULT_WIDTH_FRACTION);
});
it("setDraftExpanded previews expansion without persisting a width", () => {
const store = createPeekPanelStore();
store.getState().actions.setDraftExpanded();
expect(selectDraftExpanded(store.getState())).toBe(true);
expect(store.getState().draftFraction).toBeNull();
expect(window.localStorage.getItem(STORAGE_KEY)).toBeNull();
});
it("nudgeWidth grows/shrinks within bounds and persists", () => {
window.localStorage.setItem(STORAGE_KEY, "0.5");
const store = createPeekPanelStore();
store.getState().actions.nudgeWidth("grow");
expect(store.getState().widthFraction).toBeCloseTo(0.55);
expect(window.localStorage.getItem(STORAGE_KEY)).toBe("0.55");
store.getState().actions.nudgeWidth("shrink");
expect(store.getState().widthFraction).toBeCloseTo(0.5);
});
it("nudgeWidth never shrinks below the minimum", () => {
window.localStorage.setItem(STORAGE_KEY, String(PEEK_MIN_WIDTH_FRACTION));
const store = createPeekPanelStore();
store.getState().actions.nudgeWidth("shrink");
expect(store.getState().widthFraction).toBeCloseTo(PEEK_MIN_WIDTH_FRACTION);
});
it("cancelResize abandons the draft without committing a width", () => {
window.localStorage.setItem(STORAGE_KEY, "0.5");
const store = createPeekPanelStore();
store.getState().actions.setResizing(true);
store.getState().actions.setDraftFraction(0.8);
store.getState().actions.cancelResize();
const state = store.getState();
expect(state.draftFraction).toBeNull();
expect(state.draftExpanded).toBe(false);
expect(state.isResizing).toBe(false);
expect(state.widthFraction).toBeCloseTo(0.5);
expect(window.localStorage.getItem(STORAGE_KEY)).toBe("0.5");
});
});