Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Format
  • Loading branch information
presleyp committed Aug 24, 2022
commit 8b88265d617c8a398e1a348168f82580d1c5bf4d
25 changes: 16 additions & 9 deletions site/src/components/Navbar/Navbar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
import { render, MockEntitlementsWithAuditLog, MockMemberPermissions, MockUser } from "testHelpers/renderHelpers"
import { server } from "testHelpers/server"
import { screen } from "@testing-library/react"
import { Navbar } from "./Navbar"
import { rest } from "msw"
import {
MockEntitlementsWithAuditLog,
MockMemberPermissions,
MockUser,
render,
} from "testHelpers/renderHelpers"
import { server } from "testHelpers/server"
import { Navbar } from "./Navbar"

describe("Navbar", () => {
it("shows Audit Log link when permitted and entitled", () => {
it("shows Audit Log link when permitted and entitled", async () => {
server.use(
rest.get("/api/entitlements", (req, res, ctx) => {
return res(ctx.status(200), ctx.json(MockEntitlementsWithAuditLog))
}),
)
render(<Navbar />)
expect(screen.getByText("Audit Log"))
const link = await screen.findByText("Audit Log")
expect(link).toBeDefined()
})

it("does not show Audit Log link when not entitled", () => {
server.use()
render(<Navbar />)
expect(screen.queryByText("Audit Log")).not.toBeDefined()
const link = screen.getByText("Audit Log")
expect(link).not.toBeDefined()
})

it("does not show Audit Log link when not permitted via role", () => {
server.use(
server.use(
rest.post(`/api/v2/users/${MockUser.id}/authorization`, async (req, res, ctx) => {
return res(ctx.status(200), ctx.json(MockMemberPermissions))
}),
)
render(<Navbar />)
expect(screen.queryByText("Audit Log")).not.toBeDefined()
const link = screen.getByText("Audit Log")
expect(link).not.toBeDefined()
})
})