Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/test/stored-login.test.mjs
iris 78e063e78c swarm ui: the login button's wording is a tested function
The label that switches between log in and log in again moves next to the
stored login's other wording, so it has a test.
2026-11-15 16:13:15 +01:00

43 lines
1.5 KiB
JavaScript

// The stored claude login's routes and wording. Run by `npm test`, which Node
// runs with its built-in test runner and type stripping, so the `.ts` module
// is imported as it is.
import assert from "node:assert/strict";
import { test } from "node:test";
import {
deleteMessage,
deleteStoredLoginPath,
loginButtonLabel,
storedAtMs,
storedLoginPath,
} from "../src/agent/claude-login/StoredLogin.ts";
test("the routes name the agent, escaped", () => {
assert.equal(storedLoginPath("atlas"), "/api/agents/atlas/claude-login");
assert.equal(
deleteStoredLoginPath("atlas"),
"/api/agents/atlas/claude-login/stored",
);
assert.equal(storedLoginPath("a/b"), "/api/agents/a%2Fb/claude-login");
});
test("the time the store gives is read as an instant, or as nothing", () => {
assert.equal(
storedAtMs({ stored_at: "2026-11-09T20:00:00.123456789Z" }),
Date.parse("2026-11-09T20:00:00.123Z"),
);
assert.equal(storedAtMs({ stored_at: null }), null);
assert.equal(storedAtMs({ stored_at: "not a time" }), null);
});
test("the delete's confirmation names the agent", () => {
assert.match(deleteMessage("atlas"), /stored claude login for atlas/);
assert.match(deleteMessage("atlas"), /logged out within 5 minutes/);
});
test("the login button says log in until a login is stored, then log in again", () => {
assert.equal(loginButtonLabel({ stored_at: null }), "log in");
assert.equal(
loginButtonLabel({ stored_at: "2026-11-10T12:00:00Z" }),
"log in again",
);
});