Skip to content
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
BrunoQuaresma committed May 25, 2022
commit f63f04c902e80704e18382243f6d69d288ec5ec6
7 changes: 7 additions & 0 deletions site/src/__mocks__/react-markdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react"

const ReactMarkdown: React.FC = ({ children }) => {
return <div data-testid="markdown">{children}</div>
}

export default ReactMarkdown
3 changes: 3 additions & 0 deletions site/src/components/TemplateStats/TemplateStats.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { makeStyles } from "@material-ui/core/styles"
import dayjs from "dayjs"
import relativeTime from "dayjs/plugin/relativeTime"
import React from "react"
import { Template, TemplateVersion } from "../../api/typesGenerated"
import { CardRadius, MONOSPACE_FONT_FAMILY } from "../../theme/constants"

dayjs.extend(relativeTime)

const Language = {
usedByLabel: "Used by",
activeVersionLabel: "Active version",
Expand Down
13 changes: 13 additions & 0 deletions site/src/pages/TemplatePage/TemplatePage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { screen } from "@testing-library/react"
import React from "react"
import { MockTemplate, MockWorkspaceResource, renderWithAuth } from "../../testHelpers/renderHelpers"
import { TemplatePage } from "./TemplatePage"

describe("TemplatePage", () => {
it("shows the template name, readme and resources", async () => {
renderWithAuth(<TemplatePage />, { route: `/templates/${MockTemplate.id}`, path: "/templates/:template" })
await screen.findByText(MockTemplate.name)
screen.getByTestId("markdown")
screen.getByText(MockWorkspaceResource.name)
})
})
3 changes: 3 additions & 0 deletions site/src/testHelpers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const handlers = [
rest.get("/api/v2/templateversions/:templateVersionId/schema", async (req, res, ctx) => {
return res(ctx.status(200), ctx.json([]))
}),
rest.get("/api/v2/templateversions/:templateVersionId/resources", async (req, res, ctx) => {
return res(ctx.status(200), ctx.json([M.MockWorkspaceResource, M.MockWorkspaceResource2]))
}),

// users
rest.get("/api/v2/users", async (req, res, ctx) => {
Expand Down