X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/38d27e9783f7f760cee84cc225e86144069848c4..ddfb91e9eee0902fba8b972e2724b2eb4707654a:/src/components/search-input/search-input.test.tsx diff --git a/src/components/search-input/search-input.test.tsx b/src/components/search-input/search-input.test.tsx index 90c52b76..ba70f752 100644 --- a/src/components/search-input/search-input.test.tsx +++ b/src/components/search-input/search-input.test.tsx @@ -21,20 +21,20 @@ describe("", () => { describe("on submit", () => { it("calls onSearch with initial value passed via props", () => { - const searchInput = mount(); + const searchInput = mount(); searchInput.find("form").simulate("submit"); expect(onSearch).toBeCalledWith("initial value"); }); it("calls onSearch with current value", () => { - const searchInput = mount(); + const searchInput = mount(); searchInput.find("input").simulate("change", { target: { value: "current value" } }); searchInput.find("form").simulate("submit"); expect(onSearch).toBeCalledWith("current value"); }); it("calls onSearch with new value passed via props", () => { - const searchInput = mount(); + const searchInput = mount(); searchInput.find("input").simulate("change", { target: { value: "current value" } }); searchInput.setProps({value: "new value"}); searchInput.find("form").simulate("submit"); @@ -42,7 +42,7 @@ describe("", () => { }); it("cancels timeout set on input value change", () => { - const searchInput = mount(); + const searchInput = mount(); searchInput.find("input").simulate("change", { target: { value: "current value" } }); searchInput.find("form").simulate("submit"); jest.runTimersToTime(1000); @@ -54,7 +54,7 @@ describe("", () => { describe("on input value change", () => { it("calls onSearch after default timeout", () => { - const searchInput = mount(); + const searchInput = mount(); searchInput.find("input").simulate("change", { target: { value: "current value" } }); expect(onSearch).not.toBeCalled(); jest.runTimersToTime(DEFAULT_SEARCH_DEBOUNCE); @@ -62,7 +62,7 @@ describe("", () => { }); it("calls onSearch after the time specified in props has passed", () => { - const searchInput = mount(); + const searchInput = mount(); searchInput.find("input").simulate("change", { target: { value: "current value" } }); jest.runTimersToTime(1000); expect(onSearch).not.toBeCalled(); @@ -71,7 +71,7 @@ describe("", () => { }); it("calls onSearch only once after no change happened during the specified time", () => { - const searchInput = mount(); + const searchInput = mount(); searchInput.find("input").simulate("change", { target: { value: "current value" } }); jest.runTimersToTime(500); searchInput.find("input").simulate("change", { target: { value: "changed value" } }); @@ -80,7 +80,7 @@ describe("", () => { }); it("calls onSearch again after the specified time has passed since previous call", () => { - const searchInput = mount(); + const searchInput = mount(); searchInput.find("input").simulate("change", { target: { value: "current value" } }); jest.runTimersToTime(500); searchInput.find("input").simulate("change", { target: { value: "intermediate value" } }); @@ -95,4 +95,25 @@ describe("", () => { }); + describe("on input target change", () => { + it("clears the input value on selfClearProp change", () => { + const searchInput = mount(); + + // component should clear value upon creation + jest.runTimersToTime(1000); + expect(onSearch).toBeCalledWith(""); + expect(onSearch).toHaveBeenCalledTimes(1); + + // component should not clear on same selfClearProp + searchInput.setProps({ selfClearProp: 'abc' }); + jest.runTimersToTime(1000); + expect(onSearch).toHaveBeenCalledTimes(1); + + // component should clear on selfClearProp change + searchInput.setProps({ selfClearProp: '111' }); + jest.runTimersToTime(1000); + expect(onSearch).toBeCalledWith(""); + expect(onSearch).toHaveBeenCalledTimes(2); + }); + }); });