21720: changed runTimersToTime to advanceTimersByTime
authorLisa Knox <lisaknox83@gmail.com>
Mon, 20 May 2024 16:25:45 +0000 (12:25 -0400)
committerLisa Knox <lisaknox83@gmail.com>
Mon, 20 May 2024 16:25:45 +0000 (12:25 -0400)
Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox@curii.com>

services/workbench2/src/components/search-input/search-input.test.tsx
services/workbench2/src/views-components/auto-logout/auto-logout.test.tsx
services/workbench2/src/views-components/search-bar/search-bar-view.test.tsx

index 213b46404b50cc6baf43c7ea9051b5aa3772c258..ba0f43d8b527ef305debafb57fdd4791a19d166f 100644 (file)
@@ -44,7 +44,7 @@ describe("<SearchInput />", () => {
             const searchInput = mount(<SearchInput selfClearProp="" value="" onSearch={onSearch} debounce={1000} />);
             searchInput.find("input").simulate("change", { target: { value: "current value" } });
             searchInput.find("form").simulate("submit");
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toHaveBeenCalledTimes(1);
             expect(onSearch).toBeCalledWith("current value");
         });
@@ -56,37 +56,37 @@ 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);
+            jest.advanceTimersByTime(DEFAULT_SEARCH_DEBOUNCE);
             expect(onSearch).toBeCalledWith("current value");
         });
 
         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);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).not.toBeCalled();
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toBeCalledWith("current value");
         });
 
         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);
+            jest.advanceTimersByTime(500);
             searchInput.find("input").simulate("change", { target: { value: "changed value" } });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toHaveBeenCalledTimes(1);
         });
 
         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);
+            jest.advanceTimersByTime(500);
             searchInput.find("input").simulate("change", { target: { value: "intermediate value" } });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toBeCalledWith("intermediate value");
             searchInput.find("input").simulate("change", { target: { value: "latest value" } });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toBeCalledWith("latest value");
             expect(onSearch).toHaveBeenCalledTimes(2);
 
@@ -99,18 +99,18 @@ describe("<SearchInput />", () => {
             const searchInput = mount(<SearchInput selfClearProp="abc" value="123" onSearch={onSearch} debounce={1000}/>);
 
             // component should clear value upon creation
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toBeCalledWith("");
             expect(onSearch).toHaveBeenCalledTimes(1);
 
             // component should not clear on same selfClearProp
             searchInput.setProps({ selfClearProp: 'abc' });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toHaveBeenCalledTimes(1);
 
             // component should clear on selfClearProp change
             searchInput.setProps({ selfClearProp: '111' });
-            jest.runTimersToTime(1000);
+            jest.advanceTimersByTime(1000);
             expect(onSearch).toBeCalledWith("");
             expect(onSearch).toHaveBeenCalledTimes(2);
         });
index 28084ed1c15e6c2af148ad0052c1cfe2b62ba3c1..b07e3dccfa059202b3305d7232973dcce9504cb0 100644 (file)
@@ -31,28 +31,28 @@ describe('<AutoLogoutComponent />', () => {
     });
 
     it('should logout after idle timeout', () => {
-        jest.runTimersToTime((sessionIdleTimeout-1)*1000);
+        jest.advanceTimersByTime((sessionIdleTimeout-1)*1000);
         expect(props.doLogout).not.toBeCalled();
-        jest.runTimersToTime(1*1000);
+        jest.advanceTimersByTime(1*1000);
         expect(props.doLogout).toBeCalled();
     });
 
     it('should warn the user previous to close the session', () => {
-        jest.runTimersToTime((sessionIdleTimeout-lastWarningDuration-1)*1000);
+        jest.advanceTimersByTime((sessionIdleTimeout-lastWarningDuration-1)*1000);
         expect(props.doWarn).not.toBeCalled();
-        jest.runTimersToTime(1*1000);
+        jest.advanceTimersByTime(1*1000);
         expect(props.doWarn).toBeCalled();
     });
 
     it('should reset the idle timer when activity event is received', () => {
-        jest.runTimersToTime((sessionIdleTimeout-lastWarningDuration-1)*1000);
+        jest.advanceTimersByTime((sessionIdleTimeout-lastWarningDuration-1)*1000);
         expect(props.doWarn).not.toBeCalled();
         // Simulate activity from other window/tab
         eventListeners.storage({
             key: LAST_ACTIVE_TIMESTAMP,
             newValue: '42' // value currently doesn't matter
         })
-        jest.runTimersToTime(1*1000);
+        jest.advanceTimersByTime(1*1000);
         // Warning should not appear because idle timer was reset
         expect(props.doWarn).not.toBeCalled();
     });
index 2f7ed6569e4b2a724122943269bacc3693b5990e..202050076a6a7e319b2e74c7802714b593da2f62 100644 (file)
@@ -29,37 +29,37 @@ describe("<SearchBarView />", () => {
         //     const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" {...mockSearchProps()} />);
         //     searchBar.find("input").simulate("change", { target: { value: "current value" } });
         //     expect(onSearch).not.toBeCalled();
-        //     jest.runTimersToTime(DEFAULT_SEARCH_DEBOUNCE);
+        //     jest.advanceTimersByTime(DEFAULT_SEARCH_DEBOUNCE);
         //     expect(onSearch).toBeCalledWith("current value");
         // });
 
         // it("calls onSearch after the time specified in props has passed", () => {
         //     const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" debounce={2000} {...mockSearchProps()} />);
         //     searchBar.find("input").simulate("change", { target: { value: "current value" } });
-        //     jest.runTimersToTime(1000);
+        //     jest.advanceTimersByTime(1000);
         //     expect(onSearch).not.toBeCalled();
-        //     jest.runTimersToTime(1000);
+        //     jest.advanceTimersByTime(1000);
         //     expect(onSearch).toBeCalledWith("current value");
         // });
 
         // it("calls onSearch only once after no change happened during the specified time", () => {
         //     const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" debounce={1000} {...mockSearchProps()} />);
         //     searchBar.find("input").simulate("change", { target: { value: "current value" } });
-        //     jest.runTimersToTime(500);
+        //     jest.advanceTimersByTime(500);
         //     searchBar.find("input").simulate("change", { target: { value: "changed value" } });
-        //     jest.runTimersToTime(1000);
+        //     jest.advanceTimersByTime(1000);
         //     expect(onSearch).toHaveBeenCalledTimes(1);
         // });
 
         // it("calls onSearch again after the specified time has passed since previous call", () => {
         //     const searchBar = mount(<SearchBarView onSearch={onSearch} value="latest value" debounce={1000} {...mockSearchProps()} />);
         //     searchBar.find("input").simulate("change", { target: { value: "current value" } });
-        //     jest.runTimersToTime(500);
+        //     jest.advanceTimersByTime(500);
         //     searchBar.find("input").simulate("change", { target: { value: "intermediate value" } });
-        //     jest.runTimersToTime(1000);
+        //     jest.advanceTimersByTime(1000);
         //     expect(onSearch).toBeCalledWith("intermediate value");
         //     searchBar.find("input").simulate("change", { target: { value: "latest value" } });
-        //     jest.runTimersToTime(1000);
+        //     jest.advanceTimersByTime(1000);
         //     expect(onSearch).toBeCalledWith("latest value");
         //     expect(onSearch).toHaveBeenCalledTimes(2);