Files
coder/site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx
T
Kira Pilot f13632cea8 feat: add impending deletion filter to workspaces page (#7860)
* add workspace deletion dialog

* add deleting_by query param

* added test

* filtering on workspaces to be deleted

* cleaned up form

* added story

* added banner filter

* PR feedback

* fix lint and stories

* PR feedback

* added enterprise test

* added unit tests in search_test.go

* remove unused fn

* unstaged changes
2023-06-12 11:55:51 -07:00

45 lines
1.4 KiB
TypeScript

import { screen } from "@testing-library/react"
import { rest } from "msw"
import * as CreateDayString from "utils/createDayString"
import { MockWorkspace, MockWorkspacesResponse } from "testHelpers/entities"
import { history, renderWithAuth } from "testHelpers/renderHelpers"
import { server } from "testHelpers/server"
import WorkspacesPage from "./WorkspacesPage"
import { i18n } from "i18n"
const { t } = i18n
describe("WorkspacesPage", () => {
beforeEach(() => {
history.replace("/workspaces")
// Mocking the dayjs module within the createDayString file
const mock = jest.spyOn(CreateDayString, "createDayString")
mock.mockImplementation(() => "a minute ago")
})
it("renders an empty workspaces page", async () => {
// Given
server.use(
rest.get("/api/v2/workspaces", async (req, res, ctx) => {
return res(ctx.status(200), ctx.json({ workspaces: [], count: 0 }))
}),
)
// When
renderWithAuth(<WorkspacesPage />)
// Then
const text = t("emptyCreateWorkspaceMessage", { ns: "workspacesPage" })
await screen.findByText(text)
})
it("renders a filled workspaces page", async () => {
renderWithAuth(<WorkspacesPage />)
await screen.findByText(`${MockWorkspace.name}1`)
const templateDisplayNames = await screen.findAllByText(
`${MockWorkspace.template_display_name}`,
)
expect(templateDisplayNames).toHaveLength(MockWorkspacesResponse.count)
})
})