mirror of https://github.com/coder/coder.git
Test enabling deadline change buttons (#5508)
This commit is contained in:
parent
418022943a
commit
c8f34bbad7
|
@ -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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue