X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/e7a722835aeda5ebe0eeab2328a7e628927e6416..d92b067614b451c27a8bd702253e87278defa7a3:/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 de1e961c..5cd1545c 100644
--- a/src/views-components/search-bar/search-bar-view.test.tsx
+++ b/src/views-components/search-bar/search-bar-view.test.tsx
@@ -11,7 +11,7 @@ import * as Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
-describe("", () => {
+describe("", () => {
jest.useFakeTimers();
@@ -22,62 +22,23 @@ describe("", () => {
});
describe("on submit", () => {
- it("calls onSearch with initial value passed via props", () => {
- const searchBar = mount( ['test']} />);
- searchBar.find("form").simulate("submit");
- expect(onSearch).toBeCalledWith("initial value");
- });
-
it("calls onSearch with current value", () => {
- const searchBar = mount( ['test']} />);
+ const searchBar = mount();
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( ['test']} />);
- searchBar.find("input").simulate("change", { target: { value: "current value" } });
+ const searchBar = mount();
+ searchBar.find("input").simulate("change", { target: { value: "new value" } });
searchBar.setProps({ value: "new value" });
searchBar.find("form").simulate("submit");
expect(onSearch).toBeCalledWith("new value");
});
it("cancels timeout set on input value change", () => {
- const searchBar = mount( ['test']} />);
+ const searchBar = mount();
searchBar.find("input").simulate("change", { target: { value: "current value" } });
searchBar.find("form").simulate("submit");
jest.runTimersToTime(1000);
@@ -89,15 +50,7 @@ describe("", () => {
describe("on input value change", () => {
it("calls onSearch after default timeout", () => {
- const searchBar = mount( ['test']} />);
+ const searchBar = mount();
searchBar.find("input").simulate("change", { target: { value: "current value" } });
expect(onSearch).not.toBeCalled();
jest.runTimersToTime(DEFAULT_SEARCH_DEBOUNCE);
@@ -105,16 +58,7 @@ describe("", () => {
});
it("calls onSearch after the time specified in props has passed", () => {
- const searchBar = mount( ['test']} />);
+ const searchBar = mount();
searchBar.find("input").simulate("change", { target: { value: "current value" } });
jest.runTimersToTime(1000);
expect(onSearch).not.toBeCalled();
@@ -123,16 +67,7 @@ describe("", () => {
});
it("calls onSearch only once after no change happened during the specified time", () => {
- const searchBar = mount( ['test']} />);
+ const searchBar = mount();
searchBar.find("input").simulate("change", { target: { value: "current value" } });
jest.runTimersToTime(500);
searchBar.find("input").simulate("change", { target: { value: "changed value" } });
@@ -141,16 +76,7 @@ describe("", () => {
});
it("calls onSearch again after the specified time has passed since previous call", () => {
- const searchBar = mount( ['test']} />);
+ const searchBar = mount();
searchBar.find("input").simulate("change", { target: { value: "current value" } });
jest.runTimersToTime(500);
searchBar.find("input").simulate("change", { target: { value: "intermediate value" } });
@@ -164,3 +90,14 @@ describe("", () => {
});
});
});
+
+const mockSearchProps = () => ({
+ currentView: '',
+ open: true,
+ onSetView: jest.fn(),
+ openView: jest.fn(),
+ loseView: jest.fn(),
+ closeView: jest.fn(),
+ saveQuery: jest.fn(),
+ loadQueries: () => ['test']
+});
\ No newline at end of file