Skip to content

Commit cb20ccd

Browse files
committed
Fix tests
1 parent fc237a0 commit cb20ccd

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed
Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,54 @@
1-
import { screen } from "@testing-library/react"
1+
import { render, screen, waitFor } from "@testing-library/react"
22
import { rest } from "msw"
33
import {
44
MockEntitlementsWithAuditLog,
55
MockMemberPermissions,
66
MockUser,
7-
render,
87
} from "testHelpers/renderHelpers"
98
import { server } from "testHelpers/server"
10-
import { Navbar } from "./Navbar"
9+
import { App } from "app"
1110

11+
/**
12+
* The LicenseBanner, mounted above the AppRouter, fetches entitlements. Thus, to test their
13+
* effects, we must test at the App level and `waitFor` the fetch to be done.
14+
*/
1215
describe("Navbar", () => {
1316
it("shows Audit Log link when permitted and entitled", async () => {
1417
server.use(
15-
rest.get("/api/entitlements", (req, res, ctx) => {
18+
rest.get("/api/v2/entitlements", (req, res, ctx) => {
1619
return res(ctx.status(200), ctx.json(MockEntitlementsWithAuditLog))
1720
}),
1821
)
19-
render(<Navbar />)
20-
const link = await screen.findByText("Audit")
21-
expect(link).toBeDefined()
22+
render(<App />)
23+
await waitFor(() => {
24+
const link = screen.getByText("Audit")
25+
expect(link).toBeDefined()
26+
})
2227
})
2328

24-
it("does not show Audit Log link when not entitled", () => {
25-
render(<Navbar />)
26-
const link = screen.getByText("Audit")
27-
expect(link).not.toBeDefined()
29+
it("does not show Audit Log link when not entitled", async () => {
30+
render(<App />)
31+
await waitFor(() => {
32+
const link = screen.queryByText("Audit")
33+
expect(link).toBe(null)
34+
})
2835
})
2936

30-
it("does not show Audit Log link when not permitted via role", () => {
37+
it("does not show Audit Log link when not permitted via role", async () => {
3138
server.use(
3239
rest.post(`/api/v2/users/${MockUser.id}/authorization`, async (req, res, ctx) => {
3340
return res(ctx.status(200), ctx.json(MockMemberPermissions))
3441
}),
3542
)
36-
render(<Navbar />)
37-
const link = screen.getByText("Audit")
38-
expect(link).not.toBeDefined()
43+
server.use(
44+
rest.get("/api/v2/entitlements", (req, res, ctx) => {
45+
return res(ctx.status(200), ctx.json(MockEntitlementsWithAuditLog))
46+
}),
47+
)
48+
render(<App />)
49+
await waitFor(() => {
50+
const link = screen.queryByText("Audit")
51+
expect(link).toBe(null)
52+
})
3953
})
4054
})

0 commit comments

Comments
 (0)