Skip to content
This repository was archived by the owner on Jun 26, 2026. It is now read-only.

Commit b06c208

Browse files
committed
test(console): replace setTimeout flushes with waitFor in sidebar gate tests
The deny and error cases flushed with an arbitrary setTimeout before asserting the gated entry was absent, which is timing-dependent and can pass while the SSAR query is still in flight. Wait on the SSAR request having fired plus the entry being absent so the assertion is settled and meaningful. Address review feedback on apps/console/src/routes/sidebar-sections.test.tsx. Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent f90314b commit b06c208

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

‎apps/console/src/routes/sidebar-sections.test.tsx‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ describe("useConsoleSidebarSections — Cluster Usage gate", () => {
8585
const { result } = renderHook(() => useConsoleSidebarSections(), {
8686
wrapper: makeWrapper(client),
8787
})
88-
// Wait for the SSAR query to settle so the absence is real.
88+
// Wait until the SSAR request has actually fired (so the absence is the
89+
// result of a deny, not of the query still being in flight) and the
90+
// gated entry is not present.
8991
await waitFor(() => {
90-
const adminSection = result.current.find((s) => s.title === "Administration")
91-
expect(adminSection).toBeDefined()
92+
expect(client.create).toHaveBeenCalled()
93+
expect(findItem(result.current, "Cluster Usage")).toBeUndefined()
9294
})
93-
// Need an explicit settle window for the SSAR query.
94-
await new Promise((r) => setTimeout(r, 0))
95-
expect(findItem(result.current, "Cluster Usage")).toBeUndefined()
9695
})
9796

9897
it("hides the Cluster Usage entry while SSAR is still loading (no flicker)", () => {
@@ -108,7 +107,11 @@ describe("useConsoleSidebarSections — Cluster Usage gate", () => {
108107
const { result } = renderHook(() => useConsoleSidebarSections(), {
109108
wrapper: makeWrapper(client),
110109
})
111-
await new Promise((r) => setTimeout(r, 10))
112-
expect(findItem(result.current, "Cluster Usage")).toBeUndefined()
110+
// Wait until the failing SSAR request has fired and settled; the gated
111+
// entry must stay absent rather than relying on an arbitrary delay.
112+
await waitFor(() => {
113+
expect(client.create).toHaveBeenCalled()
114+
expect(findItem(result.current, "Cluster Usage")).toBeUndefined()
115+
})
113116
})
114117
})

0 commit comments

Comments
 (0)