Let a plugin add links to the profile menu, and list the setting conflict kind
CI / full-gate (push) Failing after 1m17s
CI / full-gate (push) Failing after 1m17s
This commit is contained in:
@@ -87,3 +87,29 @@ test("shellUser derives the profile from the real user; anonymous → Guest", ()
|
||||
assert.deepEqual(shellUser(null), { email: "", initials: "G", name: "Guest" });
|
||||
assert.deepEqual(shellUser({ email: "ada@example.com", id: "u1", permissions: [] }), { email: "ada@example.com", initials: "AD", name: "ada" });
|
||||
});
|
||||
|
||||
const account: Plugin = {
|
||||
apiVersion: "1.0.0", id: "account",
|
||||
profileMenu: [
|
||||
{ href: "/account/settings", icon: "i-user", label: "account.settings", session: true },
|
||||
{ href: "/account/billing", label: "account.billing", permission: "billing:read" },
|
||||
{ href: "/account/help", label: "Help", public: true },
|
||||
],
|
||||
};
|
||||
const entries = (opts: { permissions?: string[]; signedIn?: boolean }): { href: string; label: string }[] =>
|
||||
buildPluginChrome({
|
||||
localeHref: (href) => `${href}?locale=sv-SE`,
|
||||
menu: DEFAULT_MENU,
|
||||
plugins: [account],
|
||||
translatorFor: () => (key) => (key === "account.settings" ? "Inställningar" : key),
|
||||
...(opts.signedIn === false ? {} : { user: { email: "ada@x.io", id: "u1", permissions: opts.permissions ?? [] } }),
|
||||
}).user.menu!.map(({ href, label }) => ({ href, label }));
|
||||
|
||||
test("profile menu entries are gated like nav nodes, translated by their plugin and carry the locale", () => {
|
||||
assert.deepEqual(entries({}), [
|
||||
{ href: "/account/settings?locale=sv-SE", label: "Inställningar" },
|
||||
{ href: "/account/help?locale=sv-SE", label: "Help" },
|
||||
]);
|
||||
assert.deepEqual(entries({ permissions: ["billing:read"] }).map((e) => e.label), ["Inställningar", "account.billing", "Help"]);
|
||||
assert.deepEqual(entries({ signedIn: false }).map((e) => e.label), []); // an anonymous visitor has no profile menu
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user