1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { mount, configure } from "enzyme";
7 import Adapter from 'enzyme-adapter-react-16';
10 configure({ adapter: new Adapter() });
12 describe("<SearchBarView />", () => {
16 let onSearch: () => void;
22 describe("on input value change", () => {
23 // TODO fix tests and delete beneath one
24 it("fix tests", () => {
28 // it("calls onSearch after default timeout", () => {
29 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" {...mockSearchProps()} />);
30 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
31 // expect(onSearch).not.toBeCalled();
32 // jest.advanceTimersByTime(DEFAULT_SEARCH_DEBOUNCE);
33 // expect(onSearch).toBeCalledWith("current value");
36 // it("calls onSearch after the time specified in props has passed", () => {
37 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" debounce={2000} {...mockSearchProps()} />);
38 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
39 // jest.advanceTimersByTime(1000);
40 // expect(onSearch).not.toBeCalled();
41 // jest.advanceTimersByTime(1000);
42 // expect(onSearch).toBeCalledWith("current value");
45 // it("calls onSearch only once after no change happened during the specified time", () => {
46 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" debounce={1000} {...mockSearchProps()} />);
47 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
48 // jest.advanceTimersByTime(500);
49 // searchBar.find("input").simulate("change", { target: { value: "changed value" } });
50 // jest.advanceTimersByTime(1000);
51 // expect(onSearch).toHaveBeenCalledTimes(1);
54 // it("calls onSearch again after the specified time has passed since previous call", () => {
55 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="latest value" debounce={1000} {...mockSearchProps()} />);
56 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
57 // jest.advanceTimersByTime(500);
58 // searchBar.find("input").simulate("change", { target: { value: "intermediate value" } });
59 // jest.advanceTimersByTime(1000);
60 // expect(onSearch).toBeCalledWith("intermediate value");
61 // searchBar.find("input").simulate("change", { target: { value: "latest value" } });
62 // jest.advanceTimersByTime(1000);
63 // expect(onSearch).toBeCalledWith("latest value");
64 // expect(onSearch).toHaveBeenCalledTimes(2);
70 const mockSearchProps = () => ({
77 saveRecentQuery: jest.fn(),
78 loadRecentQueries: () => ['test'],
80 deleteSavedQuery: jest.fn(),
81 openSearchView: jest.fn(),
82 editSavedQuery: jest.fn(),
83 navigateTo: jest.fn(),
84 searchDataOnEnter: jest.fn()