X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/00ddf216e1a5046a858b1c8b49f0e967404474ca..e7a722835aeda5ebe0eeab2328a7e628927e6416:/src/views-components/search-bar/search-bar-view.test.tsx

diff --git a/src/views-components/search-bar/search-bar-view.test.tsx b/src/views-components/search-bar/search-bar-view.test.tsx
index 843374b9..de1e961c 100644
--- a/src/views-components/search-bar/search-bar-view.test.tsx
+++ b/src/views-components/search-bar/search-bar-view.test.tsx
@@ -8,6 +8,7 @@ import { SearchBarView, DEFAULT_SEARCH_DEBOUNCE } from "./search-bar-view";
 
 import * as Adapter from 'enzyme-adapter-react-16';
 
+
 configure({ adapter: new Adapter() });
 
 describe("<SearchBar />", () => {
@@ -22,20 +23,44 @@ describe("<SearchBar />", () => {
 
     describe("on submit", () => {
         it("calls onSearch with initial value passed via props", () => {
-            const searchBar = mount(<SearchBarView value="initial value" onSearch={onSearch} currentView='' open={true} onSetView={jest.fn()} openView={jest.fn()} closeView={jest.fn()} />);
+            const searchBar = mount(<SearchBarView value="initial value"
+                onSearch={onSearch}
+                currentView=''
+                open={true}
+                onSetView={jest.fn()}
+                openView={jest.fn()}
+                closeView={jest.fn()}
+                saveQuery={jest.fn()}
+                loadQueries={() => ['test']} />);
             searchBar.find("form").simulate("submit");
             expect(onSearch).toBeCalledWith("initial value");
         });
 
         it("calls onSearch with current value", () => {
-            const searchBar = mount(<SearchBarView value="" onSearch={onSearch} currentView='' open={true} onSetView={jest.fn()} openView={jest.fn()} closeView={jest.fn()} />);
+            const searchBar = mount(<SearchBarView value=""
+                onSearch={onSearch}
+                currentView=''
+                open={true}
+                onSetView={jest.fn()}
+                openView={jest.fn()}
+                closeView={jest.fn()}
+                saveQuery={jest.fn()}
+                loadQueries={() => ['test']} />);
             searchBar.find("input").simulate("change", { target: { value: "current value" } });
             searchBar.find("form").simulate("submit");
             expect(onSearch).toBeCalledWith("current value");
         });
 
         it("calls onSearch with new value passed via props", () => {
-            const searchBar = mount(<SearchBarView value="" onSearch={onSearch} currentView='' open={true} onSetView={jest.fn()} openView={jest.fn()} closeView={jest.fn()} />);
+            const searchBar = mount(<SearchBarView value=""
+                onSearch={onSearch}
+                currentView=''
+                open={true}
+                onSetView={jest.fn()}
+                openView={jest.fn()}
+                closeView={jest.fn()}
+                saveQuery={jest.fn()}
+                loadQueries={() => ['test']} />);
             searchBar.find("input").simulate("change", { target: { value: "current value" } });
             searchBar.setProps({ value: "new value" });
             searchBar.find("form").simulate("submit");
@@ -43,10 +68,19 @@ describe("<SearchBar />", () => {
         });
 
         it("cancels timeout set on input value change", () => {
-            const searchBar = mount(<SearchBarView value="" onSearch={onSearch} debounce={1000} currentView='' open={true} onSetView={jest.fn()} openView={jest.fn()} closeView={jest.fn()} />);
+            const searchBar = mount(<SearchBarView value=""
+                onSearch={onSearch}
+                debounce={1000}
+                currentView=''
+                open={true}
+                onSetView={jest.fn()}
+                openView={jest.fn()}
+                closeView={jest.fn()}
+                saveQuery={jest.fn()}
+                loadQueries={() => ['test']} />);
             searchBar.find("input").simulate("change", { target: { value: "current value" } });
             searchBar.find("form").simulate("submit");
-            jest.advanceTimersByTime(1000);
+            jest.runTimersToTime(1000);
             expect(onSearch).toHaveBeenCalledTimes(1);
             expect(onSearch).toBeCalledWith("current value");
         });
@@ -55,40 +89,75 @@ describe("<SearchBar />", () => {
 
     describe("on input value change", () => {
         it("calls onSearch after default timeout", () => {
-            const searchBar = mount(<SearchBarView value="" onSearch={onSearch} currentView='' open={true} onSetView={jest.fn()} openView={jest.fn()} closeView={jest.fn()} />);
+            const searchBar = mount(<SearchBarView value=""
+                onSearch={onSearch}
+                currentView=''
+                open={true}
+                onSetView={jest.fn()}
+                openView={jest.fn()}
+                closeView={jest.fn()}
+                saveQuery={jest.fn()}
+                loadQueries={() => ['test']} />);
             searchBar.find("input").simulate("change", { target: { value: "current value" } });
             expect(onSearch).not.toBeCalled();
-            jest.advanceTimersByTime(DEFAULT_SEARCH_DEBOUNCE);
+            jest.runTimersToTime(DEFAULT_SEARCH_DEBOUNCE);
             expect(onSearch).toBeCalledWith("current value");
         });
 
         it("calls onSearch after the time specified in props has passed", () => {
-            const searchBar = mount(<SearchBarView value="" onSearch={onSearch} debounce={2000} currentView='' open={true} onSetView={jest.fn()} openView={jest.fn()} closeView={jest.fn()} />);
+            const searchBar = mount(<SearchBarView value=""
+                onSearch={onSearch}
+                debounce={2000}
+                currentView=''
+                open={true}
+                onSetView={jest.fn()}
+                openView={jest.fn()}
+                closeView={jest.fn()}
+                saveQuery={jest.fn()}
+                loadQueries={() => ['test']} />);
             searchBar.find("input").simulate("change", { target: { value: "current value" } });
-            jest.advanceTimersByTime(1000);
+            jest.runTimersToTime(1000);
             expect(onSearch).not.toBeCalled();
-            jest.advanceTimersByTime(1000);
+            jest.runTimersToTime(1000);
             expect(onSearch).toBeCalledWith("current value");
         });
 
         it("calls onSearch only once after no change happened during the specified time", () => {
-            const searchBar = mount(<SearchBarView value="" onSearch={onSearch} debounce={1000} currentView='' open={true} onSetView={jest.fn()} openView={jest.fn()} closeView={jest.fn()} />);
+            const searchBar = mount(<SearchBarView value=""
+                onSearch={onSearch}
+                debounce={1000}
+                currentView=''
+                open={true}
+                onSetView={jest.fn()}
+                openView={jest.fn()}
+                closeView={jest.fn()}
+                saveQuery={jest.fn()}
+                loadQueries={() => ['test']} />);
             searchBar.find("input").simulate("change", { target: { value: "current value" } });
-            jest.advanceTimersByTime(500);
+            jest.runTimersToTime(500);
             searchBar.find("input").simulate("change", { target: { value: "changed value" } });
-            jest.advanceTimersByTime(1000);
+            jest.runTimersToTime(1000);
             expect(onSearch).toHaveBeenCalledTimes(1);
         });
 
         it("calls onSearch again after the specified time has passed since previous call", () => {
-            const searchBar = mount(<SearchBarView value="" onSearch={onSearch} debounce={1000} currentView='' open={true} onSetView={jest.fn()} openView={jest.fn()} closeView={jest.fn()} />);
+            const searchBar = mount(<SearchBarView value=""
+                onSearch={onSearch}
+                debounce={1000}
+                currentView=''
+                open={true}
+                onSetView={jest.fn()}
+                openView={jest.fn()}
+                closeView={jest.fn()}
+                saveQuery={jest.fn()}
+                loadQueries={() => ['test']} />);
             searchBar.find("input").simulate("change", { target: { value: "current value" } });
-            jest.advanceTimersByTime(500);
+            jest.runTimersToTime(500);
             searchBar.find("input").simulate("change", { target: { value: "intermediate value" } });
-            jest.advanceTimersByTime(1000);
+            jest.runTimersToTime(1000);
             expect(onSearch).toBeCalledWith("intermediate value");
             searchBar.find("input").simulate("change", { target: { value: "latest value" } });
-            jest.advanceTimersByTime(1000);
+            jest.runTimersToTime(1000);
             expect(onSearch).toBeCalledWith("latest value");
             expect(onSearch).toHaveBeenCalledTimes(2);
 
