17
17
*/
18
18
import { describe , test , expect , testing } from '@gsa/testing' ;
19
19
20
- import Date from 'gmp/models/date' ;
21
-
22
- import { render , fireEvent } from 'web/utils/testing' ;
20
+ import MomentDate from 'gmp/models/date' ;
21
+ import { render , screen , fireEvent } from 'web/utils/testing' ;
23
22
24
23
import StartTimeSelection from '../startendtimeselection' ;
25
24
26
- describe ( 'StartTimeSelection tests' , ( ) => {
27
- test ( 'should render' , ( ) => {
28
- const timezone = 'CET' ;
29
- const startDate = Date ( '2019-01-01T12:00Z' ) . tz ( timezone ) ;
30
- const endDate = Date ( '2019-01-01T13:00Z' ) . tz ( timezone ) ;
25
+ const timezone = 'CET' ;
26
+ const startDate = MomentDate ( '2019-01-01T12:00Z' ) . tz ( timezone ) ;
27
+ const endDate = MomentDate ( '2019-01-01T13:00Z' ) . tz ( timezone ) ;
31
28
32
- const handleChange = testing . fn ( ) ;
29
+ const handleChange = testing . fn ( ) ;
33
30
31
+ describe ( 'StartTimeSelection tests' , ( ) => {
32
+ test ( 'should render correct dates' , ( ) => {
34
33
const { element} = render (
35
34
< StartTimeSelection
36
35
timezone = { timezone }
@@ -40,16 +39,34 @@ describe('StartTimeSelection tests', () => {
40
39
/> ,
41
40
) ;
42
41
43
- expect ( element ) . toBeInTheDocument ( ) ;
42
+ expect ( element ) . toBeVisible ( ) ;
43
+
44
+ const checkElementVisibilityAndContent = (
45
+ labelText ,
46
+ buttonName ,
47
+ buttonContent ,
48
+ ) => {
49
+ const label = screen . getByLabelText ( labelText ) ;
50
+ expect ( label ) . toBeVisible ( ) ;
51
+
52
+ const button = screen . getByRole ( 'button' , { name : buttonName } ) ;
53
+ expect ( button ) . toBeVisible ( ) ;
54
+ expect ( button ) . toHaveTextContent ( buttonContent ) ;
55
+ } ;
56
+
57
+ checkElementVisibilityAndContent (
58
+ 'Start Time' ,
59
+ 'Jan 01, 2019, 01:00:00 PM' ,
60
+ 'Jan 01, 2019, 01:00:00 PM' ,
61
+ ) ;
62
+ checkElementVisibilityAndContent (
63
+ 'End Time' ,
64
+ 'Jan 01, 2019, 02:00:00 PM' ,
65
+ 'Jan 01, 2019, 02:00:00 PM' ,
66
+ ) ;
44
67
} ) ;
45
68
46
69
test ( 'should display timezone' , ( ) => {
47
- const timezone = 'CET' ;
48
- const startDate = Date ( '2019-01-01T12:00Z' ) . tz ( timezone ) ;
49
- const endDate = Date ( '2019-01-01T13:00Z' ) . tz ( timezone ) ;
50
-
51
- const handleChange = testing . fn ( ) ;
52
-
53
70
const { getByTestId} = render (
54
71
< StartTimeSelection
55
72
timezone = { timezone }
@@ -63,109 +80,8 @@ describe('StartTimeSelection tests', () => {
63
80
64
81
expect ( elem ) . toHaveTextContent ( timezone ) ;
65
82
} ) ;
66
-
67
- test ( 'should allow to change start time hour' , ( ) => {
68
- const timezone = 'CET' ;
69
- const startDate = Date ( '2019-01-01T12:00Z' ) . tz ( timezone ) ;
70
- const newStartDate = Date ( '2019-01-01T01:00Z' ) . tz ( timezone ) ;
71
- const endDate = Date ( '2019-01-01T13:00Z' ) . tz ( timezone ) ;
72
-
73
- const handleChange = testing . fn ( ) ;
74
-
75
- const { getByName, getByTestId} = render (
76
- < StartTimeSelection
77
- timezone = { timezone }
78
- startDate = { startDate }
79
- endDate = { endDate }
80
- onChanged = { handleChange }
81
- /> ,
82
- ) ;
83
-
84
- const input = getByName ( 'startHour' ) ;
85
- fireEvent . change ( input , { target : { value : '2' } } ) ;
86
-
87
- const button = getByTestId ( 'update-button' ) ;
88
- fireEvent . click ( button ) ;
89
-
90
- // eslint-disable-next-line prefer-destructuring
91
- const args = handleChange . mock . calls [ 0 ] [ 0 ] ;
92
-
93
- expect ( handleChange ) . toHaveBeenCalledTimes ( 1 ) ;
94
- expect ( newStartDate . isSame ( args . startDate ) ) . toEqual ( true ) ;
95
- expect ( endDate . isSame ( args . endDate ) ) . toEqual ( true ) ;
96
- } ) ;
97
-
98
- test ( 'should allow to change start time minute' , ( ) => {
99
- const timezone = 'CET' ;
100
- const startDate = Date ( '2019-01-01T12:00Z' ) . tz ( timezone ) ;
101
- const newStartDate = Date ( '2019-01-01T12:10Z' ) . tz ( timezone ) ;
102
- const endDate = Date ( '2019-01-01T13:00Z' ) . tz ( timezone ) ;
103
-
104
- const handleChange = testing . fn ( ) ;
105
-
106
- const { getByName, getByTestId} = render (
107
- < StartTimeSelection
108
- timezone = { timezone }
109
- startDate = { startDate }
110
- endDate = { endDate }
111
- onChanged = { handleChange }
112
- /> ,
113
- ) ;
114
-
115
- const input = getByName ( 'startMinute' ) ;
116
- fireEvent . change ( input , { target : { value : '10' } } ) ;
117
-
118
- const button = getByTestId ( 'update-button' ) ;
119
- fireEvent . click ( button ) ;
120
-
121
- // eslint-disable-next-line prefer-destructuring
122
- const args = handleChange . mock . calls [ 0 ] [ 0 ] ;
123
-
124
- expect ( handleChange ) . toHaveBeenCalledTimes ( 1 ) ;
125
- expect ( newStartDate . isSame ( args . startDate ) ) . toEqual ( true ) ;
126
- expect ( endDate . isSame ( args . endDate ) ) . toEqual ( true ) ;
127
- } ) ;
128
-
129
- test ( 'should allow to change end time hour' , ( ) => {
130
- const timezone = 'CET' ;
131
- const startDate = Date ( '2019-01-01T12:00Z' ) . tz ( timezone ) ;
132
- const endDate = Date ( '2019-01-01T13:00Z' ) . tz ( timezone ) ;
133
- const newEndDate = Date ( '2019-01-01T14:00Z' ) . tz ( timezone ) ;
134
-
135
- const handleChange = testing . fn ( ) ;
136
-
137
- const { getByName, getByTestId} = render (
138
- < StartTimeSelection
139
- timezone = { timezone }
140
- startDate = { startDate }
141
- endDate = { endDate }
142
- onChanged = { handleChange }
143
- /> ,
144
- ) ;
145
-
146
- const input = getByName ( 'endHour' ) ;
147
- fireEvent . change ( input , { target : { value : '15' } } ) ;
148
-
149
- const button = getByTestId ( 'update-button' ) ;
150
- fireEvent . click ( button ) ;
151
-
152
- // eslint-disable-next-line prefer-destructuring
153
- const args = handleChange . mock . calls [ 0 ] [ 0 ] ;
154
-
155
- expect ( handleChange ) . toHaveBeenCalledTimes ( 1 ) ;
156
- expect ( startDate . isSame ( args . startDate ) ) . toEqual ( true ) ;
157
- expect ( newEndDate . isSame ( args . endDate ) ) . toEqual ( true ) ;
158
- } ) ;
159
-
160
- test ( 'should allow to change end time minute' , ( ) => {
161
- const timezone = 'CET' ;
162
- const startDate = Date ( '2019-01-01T12:00Z' ) . tz ( timezone ) ;
163
- const endDate = Date ( '2019-01-01T13:00Z' ) . tz ( timezone ) ;
164
- const newEndDate = Date ( '2019-01-01T13:15Z' ) . tz ( timezone ) ;
165
-
166
- const handleChange = testing . fn ( ) ;
167
-
168
- const { getByName, getByTestId} = render (
83
+ test ( 'Update button click event' , ( ) => {
84
+ const { getByTestId} = render (
169
85
< StartTimeSelection
170
86
timezone = { timezone }
171
87
startDate = { startDate }
@@ -174,17 +90,9 @@ describe('StartTimeSelection tests', () => {
174
90
/> ,
175
91
) ;
176
92
177
- const input = getByName ( 'endMinute' ) ;
178
- fireEvent . change ( input , { target : { value : '15' } } ) ;
179
-
180
- const button = getByTestId ( 'update-button' ) ;
181
- fireEvent . click ( button ) ;
182
-
183
- // eslint-disable-next-line prefer-destructuring
184
- const args = handleChange . mock . calls [ 0 ] [ 0 ] ;
93
+ const updateButton = getByTestId ( 'update-button' ) ;
94
+ fireEvent . click ( updateButton ) ;
185
95
186
96
expect ( handleChange ) . toHaveBeenCalledTimes ( 1 ) ;
187
- expect ( startDate . isSame ( args . startDate ) ) . toEqual ( true ) ;
188
- expect ( newEndDate . isSame ( args . endDate ) ) . toEqual ( true ) ;
189
97
} ) ;
190
98
} ) ;
0 commit comments