Skip to content

Commit 959f5fc

Browse files
committed
refactor: clean up waitFor cut-off logic
1 parent 56873b8 commit 959f5fc

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

site/src/pages/TemplateSettingsPage/TemplateSchedulePage/TemplateSchedulePage.test.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { screen, waitFor, type waitForOptions } from "@testing-library/react";
1+
import { screen, waitFor } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
33
import * as API from "api/api";
44
import { Language as FooterFormLanguage } from "components/FormFooter/FormFooter";
@@ -103,11 +103,14 @@ const fillAndSubmitForm = async ({
103103
await user.click(confirmButton);
104104
};
105105

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+
}
111114

112115
describe("TemplateSchedulePage", () => {
113116
beforeEach(() => {
@@ -127,9 +130,8 @@ describe("TemplateSchedulePage", () => {
127130
});
128131

129132
await fillAndSubmitForm(validFormValues);
130-
await waitFor(
131-
() => expect(API.updateTemplateMeta).toBeCalledTimes(1),
132-
waitForConfig,
133+
await waitForWithCutoff(() =>
134+
expect(API.updateTemplateMeta).toBeCalledTimes(1),
133135
);
134136
});
135137

@@ -142,20 +144,19 @@ describe("TemplateSchedulePage", () => {
142144
});
143145

144146
await fillAndSubmitForm(validFormValues);
145-
await waitFor(
146-
() => expect(API.updateTemplateMeta).toBeCalledTimes(1),
147-
waitForConfig,
147+
await waitForWithCutoff(() =>
148+
expect(API.updateTemplateMeta).toBeCalledTimes(1),
148149
);
149150

150-
await waitFor(() => {
151+
await waitForWithCutoff(() => {
151152
expect(API.updateTemplateMeta).toBeCalledWith(
152153
"test-template",
153154
expect.objectContaining({
154155
default_ttl_ms: (validFormValues.default_ttl_ms || 0) * 3600000,
155156
max_ttl_ms: (validFormValues.max_ttl_ms || 0) * 3600000,
156157
}),
157158
);
158-
}, waitForConfig);
159+
});
159160
});
160161

161162
test("failure, dormancy, and dormancy auto-deletion converted to and from days", async () => {
@@ -167,12 +168,11 @@ describe("TemplateSchedulePage", () => {
167168
});
168169

169170
await fillAndSubmitForm(validFormValues);
170-
await waitFor(
171-
() => expect(API.updateTemplateMeta).toBeCalledTimes(1),
172-
waitForConfig,
171+
await waitForWithCutoff(() =>
172+
expect(API.updateTemplateMeta).toBeCalledTimes(1),
173173
);
174174

175-
await waitFor(() => {
175+
await waitForWithCutoff(() => {
176176
expect(API.updateTemplateMeta).toBeCalledWith(
177177
"test-template",
178178
expect.objectContaining({
@@ -183,7 +183,7 @@ describe("TemplateSchedulePage", () => {
183183
(validFormValues.time_til_dormant_autodelete_ms || 0) * 86400000,
184184
}),
185185
);
186-
}, waitForConfig);
186+
});
187187
});
188188

189189
it("allows a default ttl of 7 days", () => {

0 commit comments

Comments
 (0)