File tree Expand file tree Collapse file tree 3 files changed +13
-13
lines changed
pages/UserSettingsPage/SchedulePage Expand file tree Collapse file tree 3 files changed +13
-13
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import MenuItem from "@mui/material/MenuItem";
14
14
import { Stack } from "components/Stack/Stack" ;
15
15
import { timeZones , getPreferredTimezone } from "utils/timeZones" ;
16
16
import { Alert } from "components/Alert/Alert" ;
17
- import { timeToCron , quietHoursDisplay } from "utils/schedule" ;
17
+ import { timeToCron , quietHoursDisplay , validTime } from "utils/schedule" ;
18
18
19
19
export interface ScheduleFormValues {
20
20
time : string ;
@@ -25,7 +25,7 @@ const validationSchema = Yup.object({
25
25
time : Yup . string ( )
26
26
. ensure ( )
27
27
. test ( "is-time-string" , "Time must be in HH:mm format." , ( value ) => {
28
- if ( ! / ^ [ 0 - 9 ] [ 0 - 9 ] : [ 0 - 9 ] [ 0 - 9 ] $ / . test ( value ) ) {
28
+ if ( ! validTime ( value ) ) {
29
29
return false ;
30
30
}
31
31
const parts = value . split ( ":" ) ;
@@ -116,13 +116,6 @@ export const ScheduleForm: FC<React.PropsWithChildren<ScheduleFormProps>> = ({
116
116
</ TextField >
117
117
</ Stack >
118
118
119
- < TextField
120
- disabled
121
- fullWidth
122
- label = "Cron schedule"
123
- value = { timeToCron ( form . values . time , form . values . timezone ) }
124
- />
125
-
126
119
< TextField
127
120
disabled
128
121
fullWidth
Original file line number Diff line number Diff line change @@ -86,12 +86,8 @@ describe("SchedulePage", () => {
86
86
) ,
87
87
) ;
88
88
89
- const expectedCronSchedule = `CRON_TZ=${ test . timezone } ${ test . minute } ${ test . hour } * * *` ;
90
89
renderWithAuth ( < SchedulePage /> ) ;
91
90
await fillForm ( test ) ;
92
- const cron = screen . getByLabelText ( "Cron schedule" ) ;
93
- expect ( cron . getAttribute ( "value" ) ) . toEqual ( expectedCronSchedule ) ;
94
-
95
91
await submitForm ( ) ;
96
92
const successMessage = await screen . findByText (
97
93
"Schedule updated successfully" ,
Original file line number Diff line number Diff line change @@ -156,7 +156,14 @@ export const getMaxDeadlineChange = (
156
156
extremeDeadline : dayjs . Dayjs ,
157
157
) : number => Math . abs ( deadline . diff ( extremeDeadline , "hours" ) ) ;
158
158
159
+ export const validTime = ( time : string ) : boolean => {
160
+ return / ^ [ 0 - 9 ] [ 0 - 9 ] : [ 0 - 9 ] [ 0 - 9 ] $ / . test ( time ) ;
161
+ } ;
162
+
159
163
export const timeToCron = ( time : string , tz ?: string ) => {
164
+ if ( ! validTime ( time ) ) {
165
+ throw new Error ( `Invalid time: ${ time } ` ) ;
166
+ }
160
167
const [ HH , mm ] = time . split ( ":" ) ;
161
168
let prefix = "" ;
162
169
if ( tz ) {
@@ -170,6 +177,10 @@ export const quietHoursDisplay = (
170
177
tz : string ,
171
178
now : Date | undefined ,
172
179
) : string => {
180
+ if ( ! validTime ( time ) ) {
181
+ return "Invalid time" ;
182
+ }
183
+
173
184
// The cron-parser package doesn't accept a timezone in the cron string, but
174
185
// accepts it as an option.
175
186
const cron = timeToCron ( time ) ;
You can’t perform that action at this time.
0 commit comments