[arvados] updated: 2.7.0-6416-g515f96c411

git repository hosting git at public.arvados.org
Wed Apr 17 18:24:36 UTC 2024


Summary of changes:
 .../components/search-input/search-input.test.tsx  | 58 +++++++++++++---------
 1 file changed, 34 insertions(+), 24 deletions(-)

       via  515f96c411358b45a978b6b7c93da860b09ee7d0 (commit)
      from  46605be9b9f2721cc9848323f904fb0ace5a2dbd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 515f96c411358b45a978b6b7c93da860b09ee7d0
Author: Lisa Knox <lisaknox83 at gmail.com>
Date:   Wed Apr 17 14:24:31 2024 -0400

    21037: changed jest timer mocks to settimeouts Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox at curii.com>

diff --git a/services/workbench2/src/components/search-input/search-input.test.tsx b/services/workbench2/src/components/search-input/search-input.test.tsx
index ba70f752b9..de36ae3858 100644
--- a/services/workbench2/src/components/search-input/search-input.test.tsx
+++ b/services/workbench2/src/components/search-input/search-input.test.tsx
@@ -11,6 +11,7 @@ configure({ adapter: new Adapter() });
 
 describe("<SearchInput />", () => {
 
+    // jest.useFakeTimers() applies to all setTimeout functions
     jest.useFakeTimers();
 
     let onSearch: () => void;
@@ -57,39 +58,45 @@ describe("<SearchInput />", () => {
             const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} />);
             searchInput.find("input").simulate("change", { target: { value: "current value" } });
             expect(onSearch).not.toBeCalled();
-            jest.runTimersToTime(DEFAULT_SEARCH_DEBOUNCE);
-            expect(onSearch).toBeCalledWith("current value");
+            setTimeout(() => {
+                expect(onSearch).toBeCalledWith("current value");
+            }, DEFAULT_SEARCH_DEBOUNCE);
         });
 
         it("calls onSearch after the time specified in props has passed", () => {
             const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={2000}/>);
             searchInput.find("input").simulate("change", { target: { value: "current value" } });
-            jest.runTimersToTime(1000);
             expect(onSearch).not.toBeCalled();
-            jest.runTimersToTime(1000);
-            expect(onSearch).toBeCalledWith("current value");
+            setTimeout(() => {
+                expect(onSearch).toBeCalledWith("current value");
+            }, 1000);
         });
 
         it("calls onSearch only once after no change happened during the specified time", () => {
             const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={1000}/>);
             searchInput.find("input").simulate("change", { target: { value: "current value" } });
-            jest.runTimersToTime(500);
-            searchInput.find("input").simulate("change", { target: { value: "changed value" } });
-            jest.runTimersToTime(1000);
-            expect(onSearch).toHaveBeenCalledTimes(1);
+            setTimeout(() => {
+                searchInput.find("input").simulate("change", { target: { value: "changed value" } });
+            }, 500);
+            setTimeout(() => {
+                expect(onSearch).toHaveBeenCalledTimes(1);
+            }, 1000);
         });
 
         it("calls onSearch again after the specified time has passed since previous call", () => {
             const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={1000}/>);
             searchInput.find("input").simulate("change", { target: { value: "current value" } });
-            jest.runTimersToTime(500);
-            searchInput.find("input").simulate("change", { target: { value: "intermediate value" } });
-            jest.runTimersToTime(1000);
-            expect(onSearch).toBeCalledWith("intermediate value");
+            setTimeout(() => {
+                searchInput.find("input").simulate("change", { target: { value: "intermediate value" } });
+            }, 500);
+            setTimeout(() => {
+                expect(onSearch).toBeCalledWith("intermediate value");
+            }, 1000);
             searchInput.find("input").simulate("change", { target: { value: "latest value" } });
-            jest.runTimersToTime(1000);
-            expect(onSearch).toBeCalledWith("latest value");
-            expect(onSearch).toHaveBeenCalledTimes(2);
+            setTimeout(() => {
+                expect(onSearch).toBeCalledWith("latest value");
+                expect(onSearch).toHaveBeenCalledTimes(2);
+            }, 1000);
 
         });
 
@@ -100,20 +107,23 @@ describe("<SearchInput />", () => {
             const searchInput = mount(<SearchInput selfClearProp="abc" value="123" onSearch={onSearch} debounce={1000}/>);
 
             // component should clear value upon creation
-            jest.runTimersToTime(1000);
-            expect(onSearch).toBeCalledWith("");
-            expect(onSearch).toHaveBeenCalledTimes(1);
+            setTimeout(() => {
+                expect(onSearch).toBeCalledWith("");
+                expect(onSearch).toHaveBeenCalledTimes(1);
+            }, 1000);
 
             // component should not clear on same selfClearProp
             searchInput.setProps({ selfClearProp: 'abc' });
-            jest.runTimersToTime(1000);
-            expect(onSearch).toHaveBeenCalledTimes(1);
+            setTimeout(() => {
+                expect(onSearch).toHaveBeenCalledTimes(1);
+            }, 1000);
 
             // component should clear on selfClearProp change
             searchInput.setProps({ selfClearProp: '111' });
-            jest.runTimersToTime(1000);
-            expect(onSearch).toBeCalledWith("");
-            expect(onSearch).toHaveBeenCalledTimes(2);
+            setTimeout(() => {
+                expect(onSearch).toBeCalledWith("");
+                expect(onSearch).toHaveBeenCalledTimes(2);
+            }, 1000);
         });
     });
 });

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list