-
Notifications
You must be signed in to change notification settings - Fork 939
feat: Add audit logs filtering to the UI #4120
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
00a9636
feat: Add audit logs filtering to the UI
BrunoQuaresma 4e05902
Merge branch 'main' of github.com:coder/coder into bq/add-audit-filter
BrunoQuaresma 1de3114
Fix count and minor adjustments
BrunoQuaresma 05408d5
Add base docs
BrunoQuaresma 6a31a61
Add docs to the filters
BrunoQuaresma 51bf940
Reorder preset filters
BrunoQuaresma 7756dfc
Fix format
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import { fireEvent, screen } from "@testing-library/react" | ||
import { Language as AuditTooltipLanguage } from "components/Tooltips/AuditHelpTooltip" | ||
import { Language as TooltipLanguage } from "components/Tooltips/HelpTooltip/HelpTooltip" | ||
import { MockAuditLog, MockAuditLog2, render } from "testHelpers/renderHelpers" | ||
import { screen, waitFor } from "@testing-library/react" | ||
import userEvent from "@testing-library/user-event" | ||
import * as API from "api/api" | ||
import { | ||
history, | ||
MockAuditLog, | ||
MockAuditLog2, | ||
render, | ||
waitForLoaderToBeRemoved, | ||
} from "testHelpers/renderHelpers" | ||
import * as CreateDayString from "util/createDayString" | ||
import AuditPage from "./AuditPage" | ||
import { Language as AuditViewLanguage } from "./AuditPageView" | ||
|
||
describe("AuditPage", () => { | ||
beforeEach(() => { | ||
|
@@ -13,18 +18,6 @@ describe("AuditPage", () => { | |
mock.mockImplementation(() => "a minute ago") | ||
}) | ||
|
||
it("renders a page with a title and subtitle", async () => { | ||
// When | ||
render(<AuditPage />) | ||
|
||
// Then | ||
await screen.findByText(AuditViewLanguage.title) | ||
await screen.findByText(AuditViewLanguage.subtitle) | ||
const tooltipIcon = await screen.findByRole("button", { name: TooltipLanguage.ariaLabel }) | ||
fireEvent.mouseOver(tooltipIcon) | ||
expect(await screen.findByText(AuditTooltipLanguage.title)).toBeInTheDocument() | ||
}) | ||
|
||
it("shows the audit logs", async () => { | ||
// When | ||
render(<AuditPage />) | ||
|
@@ -33,4 +26,40 @@ describe("AuditPage", () => { | |
await screen.findByTestId(`audit-log-row-${MockAuditLog.id}`) | ||
screen.getByTestId(`audit-log-row-${MockAuditLog2.id}`) | ||
}) | ||
|
||
describe("Filtering", () => { | ||
it("filters by typing", async () => { | ||
const getAuditLogsSpy = jest | ||
.spyOn(API, "getAuditLogs") | ||
.mockResolvedValue({ audit_logs: [MockAuditLog] }) | ||
|
||
render(<AuditPage />) | ||
await waitForLoaderToBeRemoved() | ||
|
||
// Reset spy so we can focus on the call with the filter | ||
getAuditLogsSpy.mockReset() | ||
|
||
const filterField = screen.getByLabelText("Filter") | ||
const query = "resource_type:workspace action:create" | ||
await userEvent.type(filterField, query) | ||
|
||
await waitFor(() => | ||
expect(getAuditLogsSpy).toBeCalledWith({ limit: 25, offset: 0, q: query }), | ||
) | ||
}) | ||
|
||
it("filters by URL", async () => { | ||
const getAuditLogsSpy = jest | ||
.spyOn(API, "getAuditLogs") | ||
.mockResolvedValue({ audit_logs: [MockAuditLog] }) | ||
|
||
const query = "resource_type:workspace action:create" | ||
history.push(`/audit?filter=${encodeURIComponent(query)}`) | ||
render(<AuditPage />) | ||
|
||
await waitForLoaderToBeRemoved() | ||
|
||
expect(getAuditLogsSpy).toBeCalledWith({ limit: 25, offset: 0, q: query }) | ||
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. nice tests 👏🏼 |
||
}) | ||
}) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bpmct I would appreciate your help with this doc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well for now! Sorry I missed it