mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-13 08:05:19 +09:00
test(dashboard): wait out the tenant list before pinning the picker to non-admin pages
The admin assertion looked for "No tenants found", which the picker only renders once an empty tenant list has arrived. With the list still in flight the picker says "Loading tenants…" instead, so the assertion passed whether or not the picker was there -- restoring the unconditional subtitle left the suite green. Give the provider a tenant list, wait out the loading branch, and match the picker's own label on a route that has no "Tenant" text of its own, plus the other direction: the picker still renders outside admin. Assisted-by: LLM Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
1 parent
00e074a77a
commit
e2eac93704
1 file changed
+28
-8
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeAll } from "vitest"
|
||||
import { screen } from "@testing-library/react"
|
||||
import { screen, waitFor } from "@testing-library/react"
|
||||
import { useLocation } from "react-router"
|
||||
import {
|
||||
K8sClient,
|
||||
@@ -15,14 +15,14 @@ function LocationProbe() {
|
||||
return <div data-testid="location">{pathname}</div>
|
||||
}
|
||||
|
||||
function makeClient(): K8sClient {
|
||||
function makeClient(tenants: unknown[] = []): K8sClient {
|
||||
const client = new K8sClient()
|
||||
vi.spyOn(client, "list").mockImplementation(async (_g, _v, plural) => {
|
||||
return {
|
||||
apiVersion: "v1",
|
||||
kind: `${plural}List`,
|
||||
metadata: {},
|
||||
items: [],
|
||||
items: plural === "tenantnamespaces" ? tenants : [],
|
||||
} as K8sList<unknown>
|
||||
})
|
||||
vi.spyOn(client, "getApiGroups").mockResolvedValue({
|
||||
@@ -113,11 +113,31 @@ describe("runtime config", () => {
|
||||
})
|
||||
|
||||
describe("shell subtitle", () => {
|
||||
it("hides the tenant picker in the admin portal", async () => {
|
||||
const client = makeClient()
|
||||
renderWithK8sProvider(<App />, { client, initialRoute: "/admin/tenants" })
|
||||
// The picker only renders its "Tenant /" label once a tenant list has
|
||||
// arrived; asserting against an empty list passes whether or not the picker
|
||||
// is there, because its empty and loading branches say something else.
|
||||
// The picker labels itself "Tenant"; the admin route is Modules rather than
|
||||
// the tenant list, whose own "Tenant" create button would match too.
|
||||
const TENANTS = ["tenant-acme", "tenant-globex"].map((name) => ({
|
||||
apiVersion: "core.cozystack.io/v1alpha1",
|
||||
kind: "TenantNamespace",
|
||||
metadata: { name, labels: {} },
|
||||
}))
|
||||
|
||||
expect(await screen.findByRole("heading", { name: "Tenants" })).toBeTruthy()
|
||||
expect(screen.queryByText("No tenants found")).toBeNull()
|
||||
it("hides the tenant picker in the admin portal", async () => {
|
||||
const client = makeClient(TENANTS)
|
||||
renderWithK8sProvider(<App />, { client, initialRoute: "/admin/modules" })
|
||||
|
||||
// The picker's first render says "Loading tenants…"; wait that out, or the
|
||||
// absence below passes only because the list had not arrived yet.
|
||||
await waitFor(() => expect(screen.queryByText("Loading tenants…")).toBeNull())
|
||||
expect(screen.queryByText("Tenant", { exact: true })).toBeNull()
|
||||
})
|
||||
|
||||
it("still shows the tenant picker outside the admin portal", async () => {
|
||||
const client = makeClient(TENANTS)
|
||||
renderWithK8sProvider(<App />, { client, initialRoute: "/console" })
|
||||
|
||||
expect(await screen.findByText("Tenant", { exact: true })).toBeTruthy()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user