1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { mount, configure } from "enzyme";
7 // import { SearchBarView, DEFAULT_SEARCH_DEBOUNCE } from "./search-bar-view";
9 import * as Adapter from 'enzyme-adapter-react-16';
12 configure({ adapter: new Adapter() });
14 describe("<SearchBarView />", () => {
18 let onSearch: () => void;
24 describe("on input value change", () => {
25 // TODO fix tests and delete beneath one
26 it("fix tests", () => {
30 // it("calls onSearch after default timeout", () => {
31 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" {...mockSearchProps()} />);
32 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
33 // expect(onSearch).not.toBeCalled();
34 // jest.runTimersToTime(DEFAULT_SEARCH_DEBOUNCE);
35 // expect(onSearch).toBeCalledWith("current value");
38 // it("calls onSearch after the time specified in props has passed", () => {
39 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" debounce={2000} {...mockSearchProps()} />);
40 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
41 // jest.runTimersToTime(1000);
42 // expect(onSearch).not.toBeCalled();
43 // jest.runTimersToTime(1000);
44 // expect(onSearch).toBeCalledWith("current value");
47 // it("calls onSearch only once after no change happened during the specified time", () => {
48 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" debounce={1000} {...mockSearchProps()} />);
49 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
50 // jest.runTimersToTime(500);
51 // searchBar.find("input").simulate("change", { target: { value: "changed value" } });
52 // jest.runTimersToTime(1000);
53 // expect(onSearch).toHaveBeenCalledTimes(1);
56 // it("calls onSearch again after the specified time has passed since previous call", () => {
57 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="latest value" debounce={1000} {...mockSearchProps()} />);
58 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
59 // jest.runTimersToTime(500);
60 // searchBar.find("input").simulate("change", { target: { value: "intermediate value" } });
61 // jest.runTimersToTime(1000);
62 // expect(onSearch).toBeCalledWith("intermediate value");
63 // searchBar.find("input").simulate("change", { target: { value: "latest value" } });
64 // jest.runTimersToTime(1000);
65 // expect(onSearch).toBeCalledWith("latest value");
66 // expect(onSearch).toHaveBeenCalledTimes(2);
72 const mockSearchProps = () => ({
79 saveRecentQuery: jest.fn(),
80 loadRecentQueries: () => ['test'],
82 deleteSavedQuery: jest.fn(),
83 openSearchView: jest.fn(),
84 editSavedQuery: jest.fn(),
85 navigateTo: jest.fn(),
86 searchDataOnEnter: jest.fn()