- Notifications
You must be signed in to change notification settings - Fork928
test: add an e2e audit logs test#12868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { expect, test } from "@playwright/test"; | ||
import { | ||
createTemplate, | ||
createWorkspace, | ||
requiresEnterpriseLicense, | ||
} from "../helpers"; | ||
import { beforeCoderTest } from "../hooks"; | ||
test.beforeEach(({ page }) => beforeCoderTest(page)); | ||
test("inspecting and filtering audit logs", async ({ page }) => { | ||
requiresEnterpriseLicense(); | ||
const userName = "admin"; | ||
// Do some stuff that should show up in the audit logs | ||
const templateName = await createTemplate(page); | ||
const workspaceName = await createWorkspace(page, templateName); | ||
// Go to the audit history | ||
await page.goto("/audit"); | ||
// Make sure those things we did all actually show up | ||
await expect(page.getByText(`${userName} logged in`)).toBeVisible(); | ||
await expect( | ||
page.getByText(`${userName} created template ${templateName}`), | ||
).toBeVisible(); | ||
await expect( | ||
page.getByText(`${userName} created workspace ${workspaceName}`), | ||
).toBeVisible(); | ||
await expect( | ||
page.getByText(`${userName} started workspace ${workspaceName}`), | ||
).toBeVisible(); | ||
// Make sure we can inspect the details of the log item | ||
const createdWorkspace = page.locator(".MuiTableRow-root", { | ||
hasText: `${userName} created workspace ${workspaceName}`, | ||
}); | ||
Comment on lines +35 to +37 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't fully understand this code, but I'm a little worried. If I'm understanding it right, the code is basically grabbing an element via the CSS class it gets from MUI, and then asserting it has the specific content? I don't know how stable MUI class names are, but is there any way we can update this to be a role-based selector? Assuming MUI doesn't mess up their table semantics,this element should have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'll double check, but I didn't notice a role, and I generally prefer those. but also MUI's classes names are a documented part of their public API, so it should be safe to depend on. | ||
await createdWorkspace.getByLabel("open-dropdown").click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Is this a label that we're visibly showing in the UI? The hyphen makes it look like an implementation detail There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. It's an | ||
await expect( | ||
createdWorkspace.getByText(`automatic_updates: "never"`), | ||
).toBeVisible(); | ||
await expect( | ||
createdWorkspace.getByText(`name: "${workspaceName}"`), | ||
).toBeVisible(); | ||
const startedWorkspaceMessage = `${userName} started workspace ${workspaceName}`; | ||
const loginMessage = `${userName} logged in`; | ||
// Filter by resource type | ||
await page.getByText("All resource types").click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Not fully sure what element this is, but could the selector be updated to have a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. there are multiple buttons on the page though. those roles would be ambiguous. | ||
await page.getByRole("menu").getByText("Workspace Build").click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Could this be turned into awaitpage.getByRole("menu",{name:"Workspace Build"}).click(); ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. no, this is descending into the menu, and getting by text inside of it to click a specific option. that would just get the whole menu. | ||
// Our workspace build should be visible | ||
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible(); | ||
// Logins should no longer be visible | ||
await expect(page.getByText(loginMessage)).not.toBeVisible(); | ||
// Clear filters, everything should be visible again | ||
await page.getByLabel("Clear filter").click(); | ||
await expect(page.getByText(startedWorkspaceMessage)).toBeVisible(); | ||
await expect(page.getByText(loginMessage)).toBeVisible(); | ||
// Filter by action type | ||
await page.getByText("All actions").click(); | ||
Member
| ||
await page.getByRole("menu").getByText("Login").click(); | ||
// Logins should be visible | ||
await expect(page.getByText(loginMessage)).toBeVisible(); | ||
// Our workspace build should no longer be visible | ||
await expect(page.getByText(startedWorkspaceMessage)).not.toBeVisible(); | ||
}); |