|
1 | 1 | import { describe, it, expect, vi, beforeAll } from "vitest" |
2 | | -import { screen } from "@testing-library/react" |
| 2 | +import { fireEvent, screen } from "@testing-library/react" |
3 | 3 | import userEvent from "@testing-library/user-event" |
4 | 4 | import { |
5 | 5 | K8sClient, |
@@ -182,6 +182,35 @@ describe("TenantsPage under a visible root", () => { |
182 | 182 | // from itself and leave nothing. |
183 | 183 | const SELF_ROOT = [tn("tenant-whmcs", [])] |
184 | 184 |
|
| 185 | +describe("TenantsPage cross-tenant link", () => { |
| 186 | + // The href carries the tenant, so the tab that opens resolves on its own. |
| 187 | + // The click handler exists only to spare the tab that navigates a render |
| 188 | + // against the previous tenant — a ctrl-click is not that tab. |
| 189 | + it("does not switch the current tenant on a ctrl-click", async () => { |
| 190 | + localStorage.setItem(SELECTED_TENANT_KEY, "root") |
| 191 | + |
| 192 | + renderWithK8sProvider( |
| 193 | + <TenantProvider> |
| 194 | + <TenantsPage /> |
| 195 | + </TenantProvider>, |
| 196 | + { client: makeClient(ROOT_VISIBLE), initialRoute: "/admin/tenants" }, |
| 197 | + ) |
| 198 | + |
| 199 | + // "eu" hangs under acme, so a plain click here would move the selection |
| 200 | + // off root and the assertion below could not tell the two apart. |
| 201 | + const link = await screen.findByRole("link", { name: "eu" }) |
| 202 | + // jsdom cannot follow an href, and a ctrl-click is exactly the case |
| 203 | + // react-router leaves to the browser. Swallow the default so the run does |
| 204 | + // not carry a "navigation to another Document" line; the handler under |
| 205 | + // test has already run by then, since React's own listener sits on the |
| 206 | + // container and this one is on the anchor. |
| 207 | + link.addEventListener("click", (e) => e.preventDefault()) |
| 208 | + fireEvent.click(link, { ctrlKey: true }) |
| 209 | + |
| 210 | + expect(localStorage.getItem(SELECTED_TENANT_KEY)).toBe("root") |
| 211 | + }) |
| 212 | +}) |
| 213 | + |
185 | 214 | describe("TenantsPage self-referential root", () => { |
186 | 215 | it("names the CR of a root that is not tenant-root", async () => { |
187 | 216 | localStorage.setItem(SELECTED_TENANT_KEY, "whmcs") |
|
0 commit comments