|
|
@@ -0,0 +1,60 @@
|
|
|
+/* @vitest-environment node */
|
|
|
+
|
|
|
+import { describe, it, expect } from "vitest";
|
|
|
+import { buildOverviewCards } from "./cardsConfig.js";
|
|
|
+
|
|
|
+describe("lib/frontend/overview/cardsConfig", () => {
|
|
|
+ it("returns 3 cards when user management is not allowed", () => {
|
|
|
+ const cards = buildOverviewCards({
|
|
|
+ explorerHref: "/NL01",
|
|
|
+ searchHref: "/NL01/search",
|
|
|
+ canManageUsers: false,
|
|
|
+ disabledHint: "Bitte zuerst eine gültige Niederlassung wählen.",
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(cards).toHaveLength(3);
|
|
|
+ expect(cards.map((x) => x.key)).toEqual(["explorer", "search", "profile"]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("returns 4 cards when user management is allowed", () => {
|
|
|
+ const cards = buildOverviewCards({
|
|
|
+ explorerHref: "/NL01",
|
|
|
+ searchHref: "/NL01/search",
|
|
|
+ canManageUsers: true,
|
|
|
+ disabledHint: "Bitte zuerst eine gültige Niederlassung wählen.",
|
|
|
+ });
|
|
|
+
|
|
|
+ expect(cards).toHaveLength(4);
|
|
|
+ expect(cards.map((x) => x.key)).toEqual([
|
|
|
+ "explorer",
|
|
|
+ "search",
|
|
|
+ "profile",
|
|
|
+ "users",
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it("uses explorer/search hrefs and assigns disabledHint only to branch cards", () => {
|
|
|
+ const cards = buildOverviewCards({
|
|
|
+ explorerHref: null,
|
|
|
+ searchHref: null,
|
|
|
+ canManageUsers: true,
|
|
|
+ disabledHint: "Bitte zuerst eine gültige Niederlassung wählen.",
|
|
|
+ });
|
|
|
+
|
|
|
+ const byKey = Object.fromEntries(cards.map((card) => [card.key, card]));
|
|
|
+
|
|
|
+ expect(byKey.explorer.href).toBe(null);
|
|
|
+ expect(byKey.search.href).toBe(null);
|
|
|
+ expect(byKey.profile.href).toBe("/profile");
|
|
|
+ expect(byKey.users.href).toBe("/admin/users");
|
|
|
+
|
|
|
+ expect(byKey.explorer.disabledHint).toBe(
|
|
|
+ "Bitte zuerst eine gültige Niederlassung wählen.",
|
|
|
+ );
|
|
|
+ expect(byKey.search.disabledHint).toBe(
|
|
|
+ "Bitte zuerst eine gültige Niederlassung wählen.",
|
|
|
+ );
|
|
|
+ expect(byKey.profile.disabledHint).toBe(null);
|
|
|
+ expect(byKey.users.disabledHint).toBe(null);
|
|
|
+ });
|
|
|
+});
|