File size: 1,443 Bytes
f778c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Pending pairing render tests cover crash-safety for malformed pairing-list scalars.
import { describe, expect, it } from "vitest";
import { parsePairingList } from "../../shared/node-list-parse.js";
import { renderPendingPairingRequestsTable } from "./pairing-render.js";

const theme = {
  heading: (text: string) => text,
  warn: (text: string) => text,
  muted: (text: string) => text,
};

describe("cli/nodes-cli/pairing-render", () => {
  it("renders pending rows parsed from malformed scalars without throwing", () => {
    // node.pair.list rows are blind-cast from the pairing file; non-string requestId/nodeId/
    // displayName/remoteIp once crashed the renderer's .trim()/sanitizeTerminalText calls.
    const { pending } = parsePairingList({
      pending: [{ requestId: 7, nodeId: {}, displayName: 42, remoteIp: 99, ts: 1 }],
    });

    expect(() =>
      renderPendingPairingRequestsTable({ pending, now: 1000, tableWidth: 80, theme }),
    ).not.toThrow();
  });

  it("keeps a valid pending label after normalization", () => {
    const { pending } = parsePairingList({
      pending: [
        { requestId: "r1", nodeId: "n1", displayName: "Phone", remoteIp: "10.0.0.1", ts: 1 },
      ],
    });

    const { table } = renderPendingPairingRequestsTable({
      pending,
      now: 1000,
      tableWidth: 80,
      theme,
    });
    expect(table).toContain("Phone");
    expect(table).toContain("10.0.0.1");
  });
});