1
- import { screen , waitFor , type waitForOptions } from "@testing-library/react" ;
1
+ import { screen , waitFor } from "@testing-library/react" ;
2
2
import userEvent from "@testing-library/user-event" ;
3
3
import * as API from "api/api" ;
4
4
import { Language as FooterFormLanguage } from "components/FormFooter/FormFooter" ;
@@ -103,11 +103,14 @@ const fillAndSubmitForm = async ({
103
103
await user . click ( confirmButton ) ;
104
104
} ;
105
105
106
- const waitForConfig = {
107
- // Test averages about 13 seconds to complete; adding an extra three to
108
- // account for spikes before definitely failing a test
109
- timeout : 16_000 ,
110
- } as const satisfies waitForOptions ;
106
+ function waitForWithCutoff ( callback : ( ) => void | Promise < void > ) {
107
+ return waitFor ( callback , {
108
+ // Test file averages about 13 seconds to complete; adding an extra three
109
+ // seconds to account for spikes before definitely failing a test. Still
110
+ // falls under global config of 20 seconds
111
+ timeout : 16_000 ,
112
+ } ) ;
113
+ }
111
114
112
115
describe ( "TemplateSchedulePage" , ( ) => {
113
116
beforeEach ( ( ) => {
@@ -127,9 +130,8 @@ describe("TemplateSchedulePage", () => {
127
130
} ) ;
128
131
129
132
await fillAndSubmitForm ( validFormValues ) ;
130
- await waitFor (
131
- ( ) => expect ( API . updateTemplateMeta ) . toBeCalledTimes ( 1 ) ,
132
- waitForConfig ,
133
+ await waitForWithCutoff ( ( ) =>
134
+ expect ( API . updateTemplateMeta ) . toBeCalledTimes ( 1 ) ,
133
135
) ;
134
136
} ) ;
135
137
@@ -142,20 +144,19 @@ describe("TemplateSchedulePage", () => {
142
144
} ) ;
143
145
144
146
await fillAndSubmitForm ( validFormValues ) ;
145
- await waitFor (
146
- ( ) => expect ( API . updateTemplateMeta ) . toBeCalledTimes ( 1 ) ,
147
- waitForConfig ,
147
+ await waitForWithCutoff ( ( ) =>
148
+ expect ( API . updateTemplateMeta ) . toBeCalledTimes ( 1 ) ,
148
149
) ;
149
150
150
- await waitFor ( ( ) => {
151
+ await waitForWithCutoff ( ( ) => {
151
152
expect ( API . updateTemplateMeta ) . toBeCalledWith (
152
153
"test-template" ,
153
154
expect . objectContaining ( {
154
155
default_ttl_ms : ( validFormValues . default_ttl_ms || 0 ) * 3600000 ,
155
156
max_ttl_ms : ( validFormValues . max_ttl_ms || 0 ) * 3600000 ,
156
157
} ) ,
157
158
) ;
158
- } , waitForConfig ) ;
159
+ } ) ;
159
160
} ) ;
160
161
161
162
test ( "failure, dormancy, and dormancy auto-deletion converted to and from days" , async ( ) => {
@@ -167,12 +168,11 @@ describe("TemplateSchedulePage", () => {
167
168
} ) ;
168
169
169
170
await fillAndSubmitForm ( validFormValues ) ;
170
- await waitFor (
171
- ( ) => expect ( API . updateTemplateMeta ) . toBeCalledTimes ( 1 ) ,
172
- waitForConfig ,
171
+ await waitForWithCutoff ( ( ) =>
172
+ expect ( API . updateTemplateMeta ) . toBeCalledTimes ( 1 ) ,
173
173
) ;
174
174
175
- await waitFor ( ( ) => {
175
+ await waitForWithCutoff ( ( ) => {
176
176
expect ( API . updateTemplateMeta ) . toBeCalledWith (
177
177
"test-template" ,
178
178
expect . objectContaining ( {
@@ -183,7 +183,7 @@ describe("TemplateSchedulePage", () => {
183
183
( validFormValues . time_til_dormant_autodelete_ms || 0 ) * 86400000 ,
184
184
} ) ,
185
185
) ;
186
- } , waitForConfig ) ;
186
+ } ) ;
187
187
} ) ;
188
188
189
189
it ( "allows a default ttl of 7 days" , ( ) => {
0 commit comments