import { describe, expect, it } from "vitest"; import { buildStructuredInspectorSections } from "./structured-inspector"; describe("structured inspector sections", () => { it("renders hash entries as field/value rows", () => { expect( buildStructuredInspectorSections({ metadata: { key_type: "hash" }, data: { kind: "hash", entries: [ { field: { kind: "string", value: "region" }, value: { kind: "string", value: "eu-west-1" }, }, ], }, }), ).toEqual([ { id: "hash", title: "1 field", summary: "Live HGETALL output rendered as field/value rows.", primaryLabel: "Field", secondaryLabel: "Value", rows: [ { id: "hash-0", primary: "region", secondary: "eu-west-1", }, ], }, ]); }); it("renders sorted sets and stream entries with readable secondary detail", () => { expect( buildStructuredInspectorSections({ metadata: { key_type: "stream" }, data: { kind: "stream", entries: [ { id: "1711642800000-0", fields: [ { field: { kind: "string", value: "event" }, value: { kind: "string", value: "ttl-updated" }, }, { field: { kind: "string", value: "payload" }, value: { kind: "binary", bytes: [1, 2, 3, 4] }, }, ], }, ], }, }), ).toEqual([ { id: "stream", title: "1 entry", summary: "Live XRANGE output rendered as stream entries with inline field payloads.", primaryLabel: "Entry", secondaryLabel: "Fields", rows: [ { id: "1711642800000-0", primary: "1711642800000-0", secondary: "2 fields", detailLines: ["event = ttl-updated", "payload = [binary 4 bytes]"], }, ], }, ]); }); it("keeps string and missing payloads on the existing textarea path", () => { expect( buildStructuredInspectorSections({ metadata: { key_type: "string" }, data: { kind: "string", value: { kind: "string", value: "hello" }, }, }), ).toEqual([]); expect( buildStructuredInspectorSections({ metadata: { key_type: "string" }, data: { kind: "missing", }, }), ).toEqual([]); }); });