From c8f34bbad745bc5ec4af6f862794ac4c2a4df64f Mon Sep 17 00:00:00 2001 From: Presley Pizzo <1290996+presleyp@users.noreply.github.com> Date: Thu, 22 Dec 2022 13:47:07 -0500 Subject: [PATCH] Test enabling deadline change buttons (#5508) --- .../WorkspaceScheduleButton.test.tsx | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.test.tsx b/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.test.tsx index 5ee401f7be..8e504bfa11 100644 --- a/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.test.tsx +++ b/site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.test.tsx @@ -1,8 +1,13 @@ +import { screen } from "@testing-library/react" import dayjs from "dayjs" import utc from "dayjs/plugin/utc" +import { render } from "testHelpers/renderHelpers" import * as TypesGen from "../../api/typesGenerated" import * as Mocks from "../../testHelpers/entities" -import { canEditDeadline } from "./WorkspaceScheduleButton" +import { + canEditDeadline, + WorkspaceScheduleButton, +} from "./WorkspaceScheduleButton" dayjs.extend(utc) @@ -24,4 +29,60 @@ describe("WorkspaceScheduleButton", () => { expect(canEditDeadline(workspace)).toBeTruthy() }) }) + describe("enabling plus and minus buttons", () => { + it("should enable plus and minus buttons when deadline can be changed in either direction", async () => { + render( + , + ) + const plusButton = await screen.findByLabelText("Add hours to deadline") + const minusButton = await screen.findByLabelText( + "Subtract hours from deadline", + ) + expect(plusButton).toBeEnabled() + expect(minusButton).toBeEnabled() + }) + it("should disable plus button when deadline can't be extended", async () => { + render( + , + ) + const plusButton = await screen.findByLabelText("Add hours to deadline") + const minusButton = await screen.findByLabelText( + "Subtract hours from deadline", + ) + expect(plusButton).toBeDisabled() + expect(minusButton).toBeEnabled() + }) + it("should disable minus button when deadline can't be reduced", async () => { + render( + , + ) + const plusButton = await screen.findByLabelText("Add hours to deadline") + const minusButton = await screen.findByLabelText( + "Subtract hours from deadline", + ) + expect(plusButton).toBeEnabled() + expect(minusButton).toBeDisabled() + }) + }) })