1
+ import { screen } from "@testing-library/react"
1
2
import dayjs from "dayjs"
2
3
import utc from "dayjs/plugin/utc"
4
+ import { render } from "testHelpers/renderHelpers"
3
5
import * as TypesGen from "../../api/typesGenerated"
4
6
import * as Mocks from "../../testHelpers/entities"
5
- import { canEditDeadline } from "./WorkspaceScheduleButton"
7
+ import {
8
+ canEditDeadline ,
9
+ WorkspaceScheduleButton ,
10
+ } from "./WorkspaceScheduleButton"
6
11
7
12
dayjs . extend ( utc )
8
13
@@ -24,4 +29,60 @@ describe("WorkspaceScheduleButton", () => {
24
29
expect ( canEditDeadline ( workspace ) ) . toBeTruthy ( )
25
30
} )
26
31
} )
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
+ } )
27
88
} )
0 commit comments