Test enabling deadline change buttons (#5508)

This commit is contained in:
Presley Pizzo 2022-12-22 13:47:07 -05:00 committed by GitHub
parent 418022943a
commit c8f34bbad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 62 additions and 1 deletions

View File

@ -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(
<WorkspaceScheduleButton
workspace={Mocks.MockWorkspace}
onDeadlineMinus={jest.fn()}
onDeadlinePlus={jest.fn()}
maxDeadlineDecrease={4}
maxDeadlineIncrease={4}
canUpdateWorkspace
/>,
)
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(
<WorkspaceScheduleButton
workspace={Mocks.MockWorkspace}
onDeadlineMinus={jest.fn()}
onDeadlinePlus={jest.fn()}
maxDeadlineDecrease={4}
maxDeadlineIncrease={0}
canUpdateWorkspace
/>,
)
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(
<WorkspaceScheduleButton
workspace={Mocks.MockWorkspace}
onDeadlineMinus={jest.fn()}
onDeadlinePlus={jest.fn()}
maxDeadlineDecrease={0}
maxDeadlineIncrease={4}
canUpdateWorkspace
/>,
)
const plusButton = await screen.findByLabelText("Add hours to deadline")
const minusButton = await screen.findByLabelText(
"Subtract hours from deadline",
)
expect(plusButton).toBeEnabled()
expect(minusButton).toBeDisabled()
})
})
})