Files
OmniRoute/tests/unit/shared/json-tree-expand-store.test.ts
Markus Hartung 5684589ce7 feat(dashboard): collapsible JSON tree viewer for request/response payloads (#11703)
Resynced onto the release tip. Two fixes applied during boarding: (1) the branch forked before the recent optionalDependencies placement of @huggingface/transformers and onnxruntime-node — its own diff re-added both into "dependencies" as duplicates alongside the real new dependency (react18-json-view); removed the duplicates, ran npm install to sync the lockfile. (2) config/quality/dependency-allowlist.json referenced the wrong package name (react-json-view-lite, an earlier iteration per the PR body) — the code actually imports react18-json-view; fixed the allowlist entry to match. RequestLoggerDetail.tsx crossed its frozen file-size cap (1018->1111); rebaselined with a note — the PR does split out the new logic (RequestLoggerDetail.sections.tsx, JsonTreeExpandControls.tsx, useTimestampTitles.ts, jsonTreeExpandStore.ts, all well under cap), the growth here is irreducible wiring. typecheck:core, check:dashboard-typecheck, check:file-size, check-deps all green after resync; 8/8 vitest + 11/11 native tests pass. Nice, well-structured 6-commit feature with full i18n and good test coverage. Thanks!
2026-08-30 04:26:15 -03:00

58 lines
2.4 KiB
TypeScript

import assert from "node:assert/strict";
import test, { beforeEach } from "node:test";
import useJsonTreeExpandStore, {
DEFAULT_JSON_TREE_EXPAND_LEVEL,
} from "../../../src/store/jsonTreeExpandStore.ts";
// Regression guard: collapse/expand-level controls track one level per
// section (sectionId), not one global level for the whole page -- different
// payload/stream boxes carry "interesting" data at different nesting depths.
// Level is 0-indexed to match react-json-view-lite's own
// shouldExpandNode(level) convention: 0 means nothing is expanded.
function reset() {
useJsonTreeExpandStore.setState({ levels: {} });
}
beforeEach(reset);
test("an unset section defaults to the default expand level", () => {
assert.equal(useJsonTreeExpandStore.getState().levels.openaiRequest, undefined);
});
test("collapseAll sets only the given section's level to 0", () => {
useJsonTreeExpandStore.getState().collapseAll("openaiRequest");
assert.equal(useJsonTreeExpandStore.getState().levels.openaiRequest, 0);
assert.equal(useJsonTreeExpandStore.getState().levels.providerRequest, undefined);
});
test("expandAll sets only the given section's level to the max depth", () => {
useJsonTreeExpandStore.getState().expandAll("openaiRequest");
assert.equal(useJsonTreeExpandStore.getState().levels.openaiRequest, 64);
assert.equal(useJsonTreeExpandStore.getState().levels.providerRequest, undefined);
});
test("collapseOneLevel decrements from the default and clamps at 0, independently per section", () => {
const { collapseOneLevel } = useJsonTreeExpandStore.getState();
collapseOneLevel("openaiRequest");
assert.equal(
useJsonTreeExpandStore.getState().levels.openaiRequest,
DEFAULT_JSON_TREE_EXPAND_LEVEL - 1
);
assert.equal(useJsonTreeExpandStore.getState().levels.providerRequest, undefined);
collapseOneLevel("openaiRequest");
collapseOneLevel("openaiRequest");
collapseOneLevel("openaiRequest");
assert.equal(useJsonTreeExpandStore.getState().levels.openaiRequest, 0);
});
test("expandOneLevel increments and clamps at the max, independently per section", () => {
useJsonTreeExpandStore.setState({ levels: { openaiRequest: 63 } });
const { expandOneLevel } = useJsonTreeExpandStore.getState();
expandOneLevel("openaiRequest");
assert.equal(useJsonTreeExpandStore.getState().levels.openaiRequest, 64);
expandOneLevel("openaiRequest");
assert.equal(useJsonTreeExpandStore.getState().levels.openaiRequest, 64);
});