swarm-ui: test which entries the egress card lists and the swarm-wide add body
This commit is contained in:
parent
ad76e7e937
commit
7122a3a36d
3 changed files with 30 additions and 3 deletions
|
|
@ -83,3 +83,12 @@ export function entryBody(
|
||||||
const name = domain.trim();
|
const name = domain.trim();
|
||||||
return forSwarm ? { domain: name } : { domain: name, agent };
|
return forSwarm ? { domain: name } : { domain: name, agent };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The entries that hold for every agent, which the swarm page's egress card
|
||||||
|
* lists: not an agent's own, and not an automatic one (kept by the controller
|
||||||
|
* from an environment or account, so nothing to remove).
|
||||||
|
*/
|
||||||
|
export function swarmWideEntries(entries: AllowedDomain[]): AllowedDomain[] {
|
||||||
|
return entries.filter((e) => e.agent === undefined && e.derived !== true);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { useState } from "preact/hooks";
|
||||||
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
|
import { ApiErrorPanel } from "@hive/shared/api-error-panel.js";
|
||||||
import { Badge } from "@hive/shared/badge.js";
|
import { Badge } from "@hive/shared/badge.js";
|
||||||
import { AddForm } from "../../agent/detail/AllowedDomains.js";
|
import { AddForm } from "../../agent/detail/AllowedDomains.js";
|
||||||
|
import { swarmWideEntries } from "../../agent/detail/allowed-domains.js";
|
||||||
import { useAllowedDomains } from "../../agent/detail/useAllowedDomains.js";
|
import { useAllowedDomains } from "../../agent/detail/useAllowedDomains.js";
|
||||||
import { Button } from "../../ui/button/Button.js";
|
import { Button } from "../../ui/button/Button.js";
|
||||||
import { LazyDisclosure } from "../../ui/disclosure/LazyDisclosure.js";
|
import { LazyDisclosure } from "../../ui/disclosure/LazyDisclosure.js";
|
||||||
|
|
@ -44,9 +45,7 @@ function EgressBody() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const swarmWide = entries.filter(
|
const swarmWide = swarmWideEntries(entries);
|
||||||
(e) => e.agent === undefined && e.derived !== true,
|
|
||||||
);
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{errorPanel}
|
{errorPanel}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { test } from "node:test";
|
||||||
import {
|
import {
|
||||||
allowedSummary,
|
allowedSummary,
|
||||||
entryGroups,
|
entryGroups,
|
||||||
|
swarmWideEntries,
|
||||||
entriesFor,
|
entriesFor,
|
||||||
entryBody,
|
entryBody,
|
||||||
} from "../src/agent/detail/allowed-domains.ts";
|
} from "../src/agent/detail/allowed-domains.ts";
|
||||||
|
|
@ -85,3 +86,21 @@ test("entries are grouped by source, empty sources left out", () => {
|
||||||
);
|
);
|
||||||
assert.deepEqual(entryGroups([]), []);
|
assert.deepEqual(entryGroups([]), []);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("the egress card lists only the entries that hold for every agent", () => {
|
||||||
|
const entries = [
|
||||||
|
{ domain: "crates.io" },
|
||||||
|
{ domain: "docs.rs", agent: "iris" },
|
||||||
|
{ domain: "api.example.com", derived: true },
|
||||||
|
{ domain: "github.com" },
|
||||||
|
];
|
||||||
|
assert.deepEqual(
|
||||||
|
swarmWideEntries(entries).map((e) => e.domain),
|
||||||
|
["crates.io", "github.com"],
|
||||||
|
);
|
||||||
|
assert.deepEqual(swarmWideEntries([]), []);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("an add from the swarm page, with no agent, is a swarm-wide entry", () => {
|
||||||
|
assert.deepEqual(entryBody("github.com", true, ""), { domain: "github.com" });
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue