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
Add comments and try shorter timeout
  • Loading branch information
presleyp committed Aug 25, 2022
commit a26786ed727f49f5beb11fe1221d54f9e0db5b0c
38 changes: 26 additions & 12 deletions site/src/components/Navbar/Navbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,55 @@ import { server } from "testHelpers/server"
*/
describe("Navbar", () => {
it("shows Audit Log link when permitted and entitled", async () => {
// set entitlements to allow audit log
server.use(
rest.get("/api/v2/entitlements", (req, res, ctx) => {
return res(ctx.status(200), ctx.json(MockEntitlementsWithAuditLog))
}),
)
render(<App />)
await waitFor(() => {
const link = screen.getByText(Language.users) // TODO change after debugging
expect(link).toBeDefined()
}, { timeout: 10000 })
await waitFor(
() => {
const link = screen.getByText(Language.audit)
expect(link).toBeDefined()
},
{ timeout: 5000 },
)
})

it("does not show Audit Log link when not entitled", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Reading this code, how does one know Audit Log link is not entitled? Is it due to the lack of the mocked request or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the default handler in handlers.ts returns empty license data, as if you're an OSS user.

// by default, user is an Admin with permission to see the audit log,
// but is unlicensed so not entitled to see the audit log
render(<App />)
await waitFor(() => {
const link = screen.queryByText(Language.audit)
expect(link).toBe(null)
})
await waitFor(
() => {
const link = screen.queryByText(Language.audit)
expect(link).toBe(null)
},
{ timeout: 5000 },
)
})

it("does not show Audit Log link when not permitted via role", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with this test. How does one know that a member is not permitted? I see MockMemberPermissions but hard to tell from code what role is being given or why they don't have permission.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Member role does not have auditing permissions.

// set permissions to Member (can't audit)
server.use(
rest.post(`/api/v2/users/${MockUser.id}/authorization`, async (req, res, ctx) => {
return res(ctx.status(200), ctx.json(MockMemberPermissions))
}),
)
// set entitlements to allow audit log
server.use(
rest.get("/api/v2/entitlements", (req, res, ctx) => {
return res(ctx.status(200), ctx.json(MockEntitlementsWithAuditLog))
}),
)
render(<App />)
await waitFor(() => {
const link = screen.queryByText(Language.audit)
expect(link).toBe(null)
})
await waitFor(
() => {
const link = screen.queryByText(Language.audit)
expect(link).toBe(null)
},
{ timeout: 5000 },
)
})
})