Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbfbabe1

Browse files
committed
Format and fix tests
1 parent848732a commitbfbabe1

File tree

3 files changed

+80
-77
lines changed

3 files changed

+80
-77
lines changed

‎site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import{
2+
getValidationSchema,
23
Language,
34
ttlShutdownAt,
4-
getValidationSchema,
55
WorkspaceScheduleFormValues,
66
}from"./WorkspaceScheduleForm"
77
import{zones}from"./zones"
@@ -21,7 +21,7 @@ const valid: WorkspaceScheduleFormValues = {
2121
}
2222

2323
describe("validationSchema",()=>{
24-
it("allows everything to be falsy",()=>{
24+
it("allows everything to be falsy when switches are off",()=>{
2525
constvalues:WorkspaceScheduleFormValues={
2626
sunday:false,
2727
monday:false,
@@ -35,7 +35,7 @@ describe("validationSchema", () => {
3535
timezone:"",
3636
ttl:0,
3737
}
38-
constvalidate=()=>getValidationSchema(true,true).validateSync(values)
38+
constvalidate=()=>getValidationSchema(false,false).validateSync(values)
3939
expect(validate).not.toThrow()
4040
})
4141

@@ -48,7 +48,7 @@ describe("validationSchema", () => {
4848
expect(validate).toThrow()
4949
})
5050

51-
it("disallows all days-of-week to be false whenstartTime isset",()=>{
51+
it("disallows all days-of-week to be false whenauto-start isenabled",()=>{
5252
constvalues:WorkspaceScheduleFormValues={
5353
...valid,
5454
sunday:false,
@@ -59,11 +59,11 @@ describe("validationSchema", () => {
5959
friday:false,
6060
saturday:false,
6161
}
62-
constvalidate=()=>getValidationSchema(true,true).validateSync(values)
62+
constvalidate=()=>getValidationSchema(true,false).validateSync(values)
6363
expect(validate).toThrowError(Language.errorNoDayOfWeek)
6464
})
6565

66-
it("disallows empty startTime whenat least one dayisset",()=>{
66+
it("disallows empty startTime whenauto-startisenabled",()=>{
6767
constvalues:WorkspaceScheduleFormValues={
6868
...valid,
6969
sunday:false,
@@ -75,7 +75,7 @@ describe("validationSchema", () => {
7575
saturday:false,
7676
startTime:"",
7777
}
78-
constvalidate=()=>getValidationSchema(true,true).validateSync(values)
78+
constvalidate=()=>getValidationSchema(true,false).validateSync(values)
7979
expect(validate).toThrowError(Language.errorNoTime)
8080
})
8181

‎site/src/components/WorkspaceScheduleForm/WorkspaceScheduleForm.tsx

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { AutoStart } from "pages/WorkspaceSchedulePage/schedule"
2121
import{AutoStop}from"pages/WorkspaceSchedulePage/ttl"
2222
import{FC}from"react"
2323
import*asYupfrom"yup"
24-
import{OptionalObjectSchema}from"yup/lib/object"
2524
import{getFormHelpersWithError}from"../../util/formUtils"
2625
import{FormFooter}from"../FormFooter/FormFooter"
2726
import{FullPageForm}from"../FullPageForm/FullPageForm"
@@ -92,83 +91,84 @@ export interface WorkspaceScheduleFormValues {
9291
}
9392

9493
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
95-
exportconstgetValidationSchema=(autoStartEnabled:boolean,autoStopEnabled:boolean)=>(Yup.object({
96-
sunday:Yup.boolean(),
97-
monday:Yup.boolean().test("at-least-one-day",Language.errorNoDayOfWeek,function(value){
98-
constparent=this.parentasWorkspaceScheduleFormValues
99-
100-
if(!autoStartEnabled){
101-
returntrue
102-
}else{
103-
return![
104-
parent.sunday,
105-
value,
106-
parent.tuesday,
107-
parent.wednesday,
108-
parent.thursday,
109-
parent.friday,
110-
parent.saturday,
111-
].every((day)=>day===false)
112-
}
113-
}),
114-
tuesday:Yup.boolean(),
115-
wednesday:Yup.boolean(),
116-
thursday:Yup.boolean(),
117-
friday:Yup.boolean(),
118-
saturday:Yup.boolean(),
94+
exportconstgetValidationSchema=(autoStartEnabled:boolean,autoStopEnabled:boolean)=>
95+
Yup.object({
96+
sunday:Yup.boolean(),
97+
monday:Yup.boolean().test("at-least-one-day",Language.errorNoDayOfWeek,function(value){
98+
constparent=this.parentasWorkspaceScheduleFormValues
11999

120-
startTime:Yup.string()
121-
.ensure()
122-
.test("required-if-auto-start",Language.errorNoTime,function(value){
123-
if(autoStartEnabled){
124-
returnvalue!==""
125-
}else{
100+
if(!autoStartEnabled){
126101
returntrue
127-
}
128-
})
129-
.test("is-time-string",Language.errorTime,(value)=>{
130-
if(value===""){
131-
returntrue
132-
}elseif(!/^[0-9][0-9]:[0-9][0-9]$/.test(value)){
133-
returnfalse
134102
}else{
135-
constparts=value.split(":")
136-
constHH=Number(parts[0])
137-
constmm=Number(parts[1])
138-
returnHH>=0&&HH<=23&&mm>=0&&mm<=59
103+
return![
104+
parent.sunday,
105+
value,
106+
parent.tuesday,
107+
parent.wednesday,
108+
parent.thursday,
109+
parent.friday,
110+
parent.saturday,
111+
].every((day)=>day===false)
139112
}
140113
}),
141-
timezone:Yup.string()
142-
.ensure()
143-
.test("is-timezone",Language.errorTimezone,function(value){
144-
constparent=this.parentasWorkspaceScheduleFormValues
114+
tuesday:Yup.boolean(),
115+
wednesday:Yup.boolean(),
116+
thursday:Yup.boolean(),
117+
friday:Yup.boolean(),
118+
saturday:Yup.boolean(),
145119

146-
if(!parent.startTime){
147-
returntrue
148-
}else{
149-
// Unfortunately, there's not a good API on dayjs at this time for
150-
// evaluating a timezone. Attempt to parse today in the supplied timezone
151-
// and return as valid if the function doesn't throw.
152-
try{
153-
dayjs.tz(dayjs(),value)
120+
startTime:Yup.string()
121+
.ensure()
122+
.test("required-if-auto-start",Language.errorNoTime,function(value){
123+
if(autoStartEnabled){
124+
returnvalue!==""
125+
}else{
154126
returntrue
155-
}catch(e){
127+
}
128+
})
129+
.test("is-time-string",Language.errorTime,(value)=>{
130+
if(value===""){
131+
returntrue
132+
}elseif(!/^[0-9][0-9]:[0-9][0-9]$/.test(value)){
156133
returnfalse
134+
}else{
135+
constparts=value.split(":")
136+
constHH=Number(parts[0])
137+
constmm=Number(parts[1])
138+
returnHH>=0&&HH<=23&&mm>=0&&mm<=59
157139
}
158-
}
159-
}),
160-
ttl:Yup.number()
161-
.integer()
162-
.min(0)
163-
.max(24*7/* 7 days */)
164-
.test("positive-if-auto-stop",Language.errorNoStop,(value)=>{
165-
if(autoStopEnabled){
166-
return!!value
167-
}else{
168-
returntrue
169-
}
170-
}),
171-
}))
140+
}),
141+
timezone:Yup.string()
142+
.ensure()
143+
.test("is-timezone",Language.errorTimezone,function(value){
144+
constparent=this.parentasWorkspaceScheduleFormValues
145+
146+
if(!parent.startTime){
147+
returntrue
148+
}else{
149+
// Unfortunately, there's not a good API on dayjs at this time for
150+
// evaluating a timezone. Attempt to parse today in the supplied timezone
151+
// and return as valid if the function doesn't throw.
152+
try{
153+
dayjs.tz(dayjs(),value)
154+
returntrue
155+
}catch(e){
156+
returnfalse
157+
}
158+
}
159+
}),
160+
ttl:Yup.number()
161+
.integer()
162+
.min(0)
163+
.max(24*7/* 7 days */)
164+
.test("positive-if-auto-stop",Language.errorNoStop,(value)=>{
165+
if(autoStopEnabled){
166+
return!!value
167+
}else{
168+
returntrue
169+
}
170+
}),
171+
})
172172

173173
exportconstWorkspaceScheduleForm:FC<WorkspaceScheduleFormProps>=({
174174
submitScheduleError,

‎site/src/pages/WorkspaceSchedulePage/WorkspaceSchedulePage.test.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import{
2+
formValuesToAutoStartRequest,
3+
formValuesToTTLRequest,
4+
}from"pages/WorkspaceSchedulePage/formToRequest"
15
import{AutoStart,scheduleToAutoStart}from"pages/WorkspaceSchedulePage/schedule"
26
import{AutoStop,ttlMsToAutoStop}from"pages/WorkspaceSchedulePage/ttl"
37
import*asTypesGenfrom"../../api/typesGenerated"
48
import{WorkspaceScheduleFormValues}from"../../components/WorkspaceScheduleForm/WorkspaceScheduleForm"
5-
import{formValuesToAutoStartRequest,formValuesToTTLRequest}from"pages/WorkspaceSchedulePage/formToRequest"
69

710
constvalidValues:WorkspaceScheduleFormValues={
811
sunday:false,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp