import { describe, it, expect, vi } from "vitest"; import { mount } from "@vue/test-utils"; import MetadataInspector from "../MetadataInspector.vue"; describe("MetadataInspector", () => { it("renders one row per flattened leaf", () => { const w = mount(MetadataInspector, { props: { data: { kind: "action.completed", envelope: { messageId: "m1" } } }, }); const rows = w.findAll('[data-testid="meta-row"]'); expect(rows).toHaveLength(2); expect(w.text()).toContain("envelope.messageId"); expect(w.text()).toContain("m1"); }); it("shows an empty hint for an empty object", () => { const w = mount(MetadataInspector, { props: { data: {} } }); expect(w.find('[data-testid="meta-empty"]').exists()).toBe(true); }); it("copies a value to the clipboard on row click", async () => { const writeText = vi.fn().mockResolvedValue(undefined); vi.stubGlobal("navigator", { clipboard: { writeText } }); const w = mount(MetadataInspector, { props: { data: { id: "abc" } } }); await w.get('[data-testid="meta-row"]').trigger("click"); expect(writeText).toHaveBeenCalledWith("abc"); vi.unstubAllGlobals(); }); it("copies the whole payload as JSON from the header", async () => { const writeText = vi.fn().mockResolvedValue(undefined); vi.stubGlobal("navigator", { clipboard: { writeText } }); const w = mount(MetadataInspector, { props: { data: { a: 1 }, label: "Span" } }); await w.get('[data-testid="meta-copy-all"]').trigger("click"); expect(writeText).toHaveBeenCalledWith(JSON.stringify({ a: 1 }, null, 2)); vi.unstubAllGlobals(); }); });