Skip to content

Commit c8f34bb

Browse files
authored
Test enabling deadline change buttons (#5508)
1 parent 4180229 commit c8f34bb

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

site/src/components/WorkspaceScheduleButton/WorkspaceScheduleButton.test.tsx

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import { screen } from "@testing-library/react"
12
import dayjs from "dayjs"
23
import utc from "dayjs/plugin/utc"
4+
import { render } from "testHelpers/renderHelpers"
35
import * as TypesGen from "../../api/typesGenerated"
46
import * as Mocks from "../../testHelpers/entities"
5-
import { canEditDeadline } from "./WorkspaceScheduleButton"
7+
import {
8+
canEditDeadline,
9+
WorkspaceScheduleButton,
10+
} from "./WorkspaceScheduleButton"
611

712
dayjs.extend(utc)
813

@@ -24,4 +29,60 @@ describe("WorkspaceScheduleButton", () => {
2429
expect(canEditDeadline(workspace)).toBeTruthy()
2530
})
2631
})
32+
describe("enabling plus and minus buttons", () => {
33+
it("should enable plus and minus buttons when deadline can be changed in either direction", async () => {
34+
render(
35+
<WorkspaceScheduleButton
36+
workspace={Mocks.MockWorkspace}
37+
onDeadlineMinus={jest.fn()}
38+
onDeadlinePlus={jest.fn()}
39+
maxDeadlineDecrease={4}
40+
maxDeadlineIncrease={4}
41+
canUpdateWorkspace
42+
/>,
43+
)
44+
const plusButton = await screen.findByLabelText("Add hours to deadline")
45+
const minusButton = await screen.findByLabelText(
46+
"Subtract hours from deadline",
47+
)
48+
expect(plusButton).toBeEnabled()
49+
expect(minusButton).toBeEnabled()
50+
})
51+
it("should disable plus button when deadline can't be extended", async () => {
52+
render(
53+
<WorkspaceScheduleButton
54+
workspace={Mocks.MockWorkspace}
55+
onDeadlineMinus={jest.fn()}
56+
onDeadlinePlus={jest.fn()}
57+
maxDeadlineDecrease={4}
58+
maxDeadlineIncrease={0}
59+
canUpdateWorkspace
60+
/>,
61+
)
62+
const plusButton = await screen.findByLabelText("Add hours to deadline")
63+
const minusButton = await screen.findByLabelText(
64+
"Subtract hours from deadline",
65+
)
66+
expect(plusButton).toBeDisabled()
67+
expect(minusButton).toBeEnabled()
68+
})
69+
it("should disable minus button when deadline can't be reduced", async () => {
70+
render(
71+
<WorkspaceScheduleButton
72+
workspace={Mocks.MockWorkspace}
73+
onDeadlineMinus={jest.fn()}
74+
onDeadlinePlus={jest.fn()}
75+
maxDeadlineDecrease={0}
76+
maxDeadlineIncrease={4}
77+
canUpdateWorkspace
78+
/>,
79+
)
80+
const plusButton = await screen.findByLabelText("Add hours to deadline")
81+
const minusButton = await screen.findByLabelText(
82+
"Subtract hours from deadline",
83+
)
84+
expect(plusButton).toBeEnabled()
85+
expect(minusButton).toBeDisabled()
86+
})
87+
})
2788
})

0 commit comments

Comments
 (0)