mirror of
https://github.com/coder/coder.git
synced 2026-10-25 09:42:55 +08:00
* got links working * added translations * fixed translation * added translation for unavailable ip * added support for group, template, user links * cleaned up string * added deleted label * querying for workspace id * remove prints * fix/write tests * PR feedback pt 1 * PR feedback part 2
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import {
|
|
MockAuditLog,
|
|
MockAuditLogWithWorkspaceBuild,
|
|
} from "testHelpers/entities"
|
|
import { AuditLogDescription } from "./AuditLogDescription"
|
|
import { render } from "../../testHelpers/renderHelpers"
|
|
import { screen } from "@testing-library/react"
|
|
|
|
const getByTextContent = (text: string) => {
|
|
return screen.getByText((_, element) => {
|
|
const hasText = (element: Element | null) => element?.textContent === text
|
|
const elementHasText = hasText(element)
|
|
const childrenDontHaveText = Array.from(element?.children || []).every(
|
|
(child) => !hasText(child),
|
|
)
|
|
return elementHasText && childrenDontHaveText
|
|
})
|
|
}
|
|
describe("AuditLogDescription", () => {
|
|
it("renders the correct string for a workspace create audit log", async () => {
|
|
render(<AuditLogDescription auditLog={MockAuditLog} />)
|
|
|
|
expect(
|
|
getByTextContent("TestUser created workspace bruno-dev"),
|
|
).toBeDefined()
|
|
})
|
|
|
|
it("renders the correct string for a workspace_build stop audit log", async () => {
|
|
render(<AuditLogDescription auditLog={MockAuditLogWithWorkspaceBuild} />)
|
|
|
|
expect(
|
|
getByTextContent("TestUser stopped build for workspace test2"),
|
|
).toBeDefined()
|
|
})
|
|
|
|
it("renders the correct string for a workspace_build audit log with a duplicate word", async () => {
|
|
const AuditLogWithRepeat = {
|
|
...MockAuditLogWithWorkspaceBuild,
|
|
additional_fields: {
|
|
workspaceName: "workspace",
|
|
},
|
|
}
|
|
render(<AuditLogDescription auditLog={AuditLogWithRepeat} />)
|
|
|
|
expect(
|
|
getByTextContent("TestUser stopped build for workspace workspace"),
|
|
).toBeDefined()
|
|
})
|
|
})
|