Administration used to open on its first section. It opens on a grid of cards now: users, domains, messages waiting in the delivery queue, server memory, and the last 24 hours' received and sent. Each card is there only when the role holds what its number needs -- a count is a query, the metric history a query and a get -- so a helpdesk role that reads accounts and domains sees those two cards and nothing about the server. What the cards count is whatever Stalwart answers for the signed-in account, which scopes a tenant administrator's accounts, domains and queue to the tenancy. The metric history has no tenant in it, and Stalwart's Tenant Administrator role does not hold it, so a tenant's dashboard is users, domains and pending. The history is Enterprise-only and switched off by default. A server that refuses it leaves those cards off; one that records nothing says so rather than showing zeroes. Received and sent add up the queue counters Stalwart's own dashboard uses, filtered with the comparison names the live server accepts (a bare timestamp is unsupportedFilter). The column count follows the number of cards so rows stay even, and falls back by the grid's own width rather than the window's. The server's test for whether an account is offered Administration matches the client's again, now that a count is enough. The mock answers the queue and an hourly history ending in the current hour; MOCK_METRICS=off refuses the history as Community does, a tenant administrator gets the queue, and helpdesk reads domains, as the demo's does. ROADMAP and FEATURES said reporting and queues were out of scope; they say the dashboard reads a handful of numbers and that managing queues, logs and settings stays out. KNOWN-ISSUES records what was settled on the live server and what was only read from source. Fourteen new strings, in all nine catalogues.
61 lines
2.5 KiB
TypeScript
61 lines
2.5 KiB
TypeScript
import { act } from "react";
|
|
import { createRoot, type Root } from "react-dom/client";
|
|
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
import { Router } from "wouter";
|
|
import { memoryLocation } from "wouter/memory-location";
|
|
import { useSession } from "@/store/session";
|
|
import type { JmapSession } from "@/jmap/types";
|
|
import { AdminNav } from "../AdminNav";
|
|
|
|
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
const signIn = (permissions: string[]) =>
|
|
useSession.setState({ session: { capabilities: {}, accounts: {}, primaryAccounts: {}, username: "[email protected]", ihasmail: { permissions } } as unknown as JmapSession });
|
|
|
|
/** The folder pane's list of Administration sections: only what the role can read. */
|
|
describe("the Administration list in the folder pane", () => {
|
|
let host: HTMLDivElement;
|
|
let root: Root;
|
|
const render = async (path: string) => {
|
|
const { hook } = memoryLocation({ path });
|
|
await act(async () => {
|
|
root.render(<Router hook={hook}><AdminNav /></Router>);
|
|
});
|
|
};
|
|
beforeEach(() => {
|
|
host = document.createElement("div");
|
|
document.body.appendChild(host);
|
|
root = createRoot(host);
|
|
});
|
|
afterEach(async () => {
|
|
await act(async () => root.unmount());
|
|
host.remove();
|
|
});
|
|
|
|
it("lists each readable section under its group and marks the open one", async () => {
|
|
signIn(["sysAccountQuery", "sysAccountGet", "sysDomainQuery", "sysDomainGet"]);
|
|
await render("/admin/domains/d1");
|
|
expect([...host.querySelectorAll(".nav-section")].map((e) => e.textContent)).toEqual(["Overview", "Directory", "Mail"]);
|
|
expect(host.querySelector(".nav-item.active")?.textContent).toBe("Domains");
|
|
});
|
|
|
|
it("treats a bare /admin as the dashboard, which is what the page opens", async () => {
|
|
signIn(["sysAccountQuery", "sysAccountGet", "sysDomainQuery", "sysDomainGet"]);
|
|
await render("/admin");
|
|
expect(host.querySelector(".nav-item.active")?.textContent).toBe("Dashboard");
|
|
});
|
|
|
|
it("leaves out what the role cannot read", async () => {
|
|
signIn(["sysDomainQuery", "sysDomainGet"]);
|
|
await render("/admin/accounts");
|
|
expect(host.textContent).not.toContain("Accounts");
|
|
expect(host.querySelector(".nav-item.active")?.textContent).toBe("Dashboard");
|
|
});
|
|
|
|
it("offers the dashboard alone to a role that can only count", async () => {
|
|
signIn(["sysQueuedMessageQuery"]);
|
|
await render("/admin");
|
|
expect([...host.querySelectorAll(".nav-item")].map((e) => e.textContent)).toEqual(["Dashboard"]);
|
|
});
|
|
});
|