X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3a530766c12a5677e6b5f8c54cd3a61f8e6934b4..6887b04c343ddb0966415456774717cb38835fea:/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 a983a409..ba70f752 100644
--- a/src/components/search-input/search-input.test.tsx
+++ b/src/components/search-input/search-input.test.tsx
@@ -2,11 +2,10 @@
//
// SPDX-License-Identifier: AGPL-3.0
-import * as React from "react";
+import React from "react";
import { mount, configure } from "enzyme";
import { SearchInput, DEFAULT_SEARCH_DEBOUNCE } from "./search-input";
-
-import * as Adapter from 'enzyme-adapter-react-16';
+import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
@@ -22,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");
@@ -43,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);
@@ -55,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);
@@ -63,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();
@@ -72,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" } });
@@ -81,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" } });
@@ -96,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);
+ });
+ });
});