Skip to content
Merged
Show file tree
Hide file tree
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
Integration test
  • Loading branch information
presleyp committed Aug 24, 2022
commit 8fdc83431cf7acd1be7dbc0defdb441ca2d99ef8
33 changes: 33 additions & 0 deletions site/src/components/Navbar/Navbar.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { render, MockEntitlementsWithAuditLog, MockMemberPermissions } from "testHelpers/renderHelpers"
import { server } from "testHelpers/server"
import { screen } from "@testing-library/react"
import { Navbar } from "./Navbar"
import { rest } from "msw"

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

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

it("does not show Audit Log link when not permitted via role", () => {
server.use(
rest.post("/api/v2/users/:userId/authorization", async (req, res, ctx) => {
return res(ctx.status(200), ctx.json(MockMemberPermissions))
}),
)
render(<Navbar />)
expect(screen.queryByText("Audit Log")).not.toBeDefined()
})
})
15 changes: 15 additions & 0 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export function assignableRole(role: TypesGen.Role, assignable: boolean): TypesG
}
}

export const MockMemberPermissions = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be helpful to convey permissions in name i.e. MockMemberWithoutAuditLogPermissions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added comments, does that help?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does! Thank you!

viewAuditLog: false
}

export const MockUser: TypesGen.User = {
id: "test-user",
username: "TestUser",
Expand Down Expand Up @@ -659,3 +663,14 @@ export const MockEntitlementsWithWarnings: TypesGen.Entitlements = {
},
},
}

export const MockEntitlementsWithAuditLog: TypesGen.Entitlements = {
warnings: [],
has_license: true,
features: {
audit_log: {
enabled: true,
entitlement: "entitled",
},
},
}