Skip to content

Commit ced3fd1

Browse files
add debounced FormText handling in jests that set values for it
1 parent 7203100 commit ced3fd1

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

client/src/components/Workflow/Editor/Forms/FormOutputLabel.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mount } from "@vue/test-utils";
2+
import flushPromises from "flush-promises";
23
import { createPinia, PiniaVuePlugin, setActivePinia } from "pinia";
34
import { getLocalVue } from "tests/jest/helpers";
45

@@ -45,6 +46,13 @@ describe("FormOutputLabel", () => {
4546
stepStore = useWorkflowStepStore("mock-workflow");
4647
stepStore.addStep(stepOne);
4748
stepStore.addStep(stepTwo);
49+
50+
// Use fake timers for debounced `FormText`
51+
jest.useFakeTimers();
52+
});
53+
54+
afterEach(() => {
55+
jest.useRealTimers();
4856
});
4957

5058
it("check initial value and value change", async () => {
@@ -54,13 +62,25 @@ describe("FormOutputLabel", () => {
5462
expect(title.text()).toBe("Label for: 'output-name'");
5563
const input = wrapper.find("input");
5664
const inputOther = wrapperOther.find("input");
65+
5766
await input.setValue("new-label");
67+
jest.runAllTimers();
68+
await flushPromises();
69+
5870
expect(wrapper.find(".ui-form-error").exists()).toBe(false);
5971
expect(wrapperOther.find(".ui-form-error").exists()).toBe(false);
72+
6073
await inputOther.setValue("other-label");
74+
jest.runAllTimers();
75+
await flushPromises();
76+
6177
expect(wrapper.find(".ui-form-error").exists()).toBe(false);
6278
expect(wrapperOther.find(".ui-form-error").exists()).toBe(false);
79+
6380
await input.setValue("other-label");
81+
jest.runAllTimers();
82+
await flushPromises();
83+
6484
expect(wrapper.find(".ui-form-error").text()).toBe("Duplicate output label 'other-label' will be ignored.");
6585
expect(wrapperOther.find(".ui-form-error").exists()).toBe(false);
6686
expect(stepStore.workflowOutputs["new-label"].outputName).toBe("output-name");

client/src/components/admin/Notifications/BroadcastForm.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ describe("BroadcastForm.vue", () => {
8080
await wrapper.find("#broadcast-action-link-link-0").setValue("https://test.link");
8181
}
8282

83+
// Wait for `FormInput` debounce to complete
84+
jest.runAllTimers();
85+
await flushPromises();
86+
8387
expectSubmitButton(wrapper, true);
8488

8589
await wrapper.find(SUBMIT_BUTTON_SELECTOR).trigger("click");
@@ -90,6 +94,14 @@ describe("BroadcastForm.vue", () => {
9094
expect(mockRouter.push).toHaveBeenCalledWith("/admin/notifications");
9195
}
9296

97+
beforeEach(() => {
98+
jest.useFakeTimers();
99+
});
100+
101+
afterEach(() => {
102+
jest.useRealTimers();
103+
});
104+
93105
it("should render form with empty fields and submit button disabled", async () => {
94106
const { wrapper } = await mountBroadcastForm();
95107

0 commit comments

Comments
 (0)