mirror of
https://github.com/MeshCore-Beacon/beacon-web.git
synced 2026-10-17 22:09:56 +00:00
Atlas cards now use the Signal tab StatCard tiles, shared Card, badges, action buttons, IATA chips and search bar. Polling moves to TanStack Query with the app retry policy, pauses while rate-limited, and recovers a pin whose server ID changed by its full public key. Search results show a key prefix and explain short or non-hex input; heard-by states which packet it counts. Sparkline component removed in favour of the stats one.
76 lines
2.9 KiB
TypeScript
76 lines
2.9 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { TABS, parseEnvList, filterEnabledTabs, parseEnvBool, selectableThemes } from "../../src/lib/constants";
|
|
|
|
describe("parseEnvList", () => {
|
|
it("returns [] for undefined or empty", () => {
|
|
expect(parseEnvList(undefined)).toEqual([]);
|
|
expect(parseEnvList("")).toEqual([]);
|
|
});
|
|
|
|
it("splits, trims, and drops empty entries", () => {
|
|
expect(parseEnvList("Map,Nodes")).toEqual(["Map", "Nodes"]);
|
|
expect(parseEnvList(" Map , Nodes ,, ")).toEqual(["Map", "Nodes"]);
|
|
});
|
|
});
|
|
|
|
describe("filterEnabledTabs", () => {
|
|
it("returns all tabs (order preserved) when nothing is disabled", () => {
|
|
expect(filterEnabledTabs(TABS, undefined)).toEqual([...TABS]);
|
|
expect(filterEnabledTabs(TABS, "")).toEqual([...TABS]);
|
|
});
|
|
|
|
it("excludes named tabs case-insensitively", () => {
|
|
expect(filterEnabledTabs(TABS, "map,nodes")).toEqual([
|
|
"Packets", "Channels", "Observers", "Routes", "Traces", "Analytics", "MyAtlas",
|
|
]);
|
|
expect(filterEnabledTabs(TABS, "MAP , NODES")).toEqual([
|
|
"Packets", "Channels", "Observers", "Routes", "Traces", "Analytics", "MyAtlas",
|
|
]);
|
|
});
|
|
|
|
it("ignores unknown tab names", () => {
|
|
expect(filterEnabledTabs(TABS, "bogus")).toEqual([...TABS]);
|
|
});
|
|
|
|
it("can disable every tab", () => {
|
|
expect(filterEnabledTabs(TABS, TABS.join(","))).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe("parseEnvBool", () => {
|
|
it("is true for common truthy strings (case-insensitive)", () => {
|
|
for (const v of ["1", "true", "TRUE", "Yes", "on", " on "]) expect(parseEnvBool(v)).toBe(true);
|
|
});
|
|
|
|
it("is false for unset, empty, sentinel, or other values", () => {
|
|
for (const v of [undefined, "", "0", "false", "no", "__VITE_SKIP_SPLASH__"]) expect(parseEnvBool(v)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("selectableThemes", () => {
|
|
const THEMES = [
|
|
{ id: "neutral-blue", name: "Neutral Blue" },
|
|
{ id: "teal", name: "Teal" },
|
|
{ id: "meshmapper_dark", name: "MeshMapper Dark", hidden: true },
|
|
{ id: "meshmapper_light", name: "MeshMapper Light", hidden: true },
|
|
];
|
|
|
|
it("shows all non-hidden themes when no allowlist is set", () => {
|
|
expect(selectableThemes(THEMES, new Set()).map((t) => t.id)).toEqual(["neutral-blue", "teal"]);
|
|
});
|
|
|
|
it("shows ONLY the allowlisted themes when set (exclusive), including hidden ones", () => {
|
|
const ids = selectableThemes(THEMES, new Set(["meshmapper_dark", "meshmapper_light"])).map((t) => t.id);
|
|
expect(ids).toEqual(["meshmapper_dark", "meshmapper_light"]);
|
|
});
|
|
|
|
it("allowlist excludes non-listed defaults", () => {
|
|
expect(selectableThemes(THEMES, new Set(["teal"])).map((t) => t.id)).toEqual(["teal"]);
|
|
});
|
|
|
|
it("matches allowlist ids case-insensitively", () => {
|
|
const themes = [{ id: "MeshMapper_Dark", hidden: true }];
|
|
expect(selectableThemes(themes, new Set(["meshmapper_dark"])).map((t) => t.id)).toEqual(["MeshMapper_Dark"]);
|
|
});
|
|
});
|