1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
7 describe("<SearchBarView />", () => {
14 describe("on input value change", () => {
15 // TODO fix tests and delete beneath one
16 it("fix tests", () => {
18 expect(test).to.equal(1);
20 // it("calls onSearch after default timeout", () => {
21 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" {...mockSearchProps()} />);
22 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
23 // expect(onSearch).not.toBeCalled();
24 // jest.advanceTimersByTime(DEFAULT_SEARCH_DEBOUNCE);
25 // expect(onSearch).toBeCalledWith("current value");
28 // it("calls onSearch after the time specified in props has passed", () => {
29 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" debounce={2000} {...mockSearchProps()} />);
30 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
31 // jest.advanceTimersByTime(1000);
32 // expect(onSearch).not.toBeCalled();
33 // jest.advanceTimersByTime(1000);
34 // expect(onSearch).toBeCalledWith("current value");
37 // it("calls onSearch only once after no change happened during the specified time", () => {
38 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="current value" debounce={1000} {...mockSearchProps()} />);
39 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
40 // jest.advanceTimersByTime(500);
41 // searchBar.find("input").simulate("change", { target: { value: "changed value" } });
42 // jest.advanceTimersByTime(1000);
43 // expect(onSearch).toHaveBeenCalledTimes(1);
46 // it("calls onSearch again after the specified time has passed since previous call", () => {
47 // const searchBar = mount(<SearchBarView onSearch={onSearch} value="latest value" debounce={1000} {...mockSearchProps()} />);
48 // searchBar.find("input").simulate("change", { target: { value: "current value" } });
49 // jest.advanceTimersByTime(500);
50 // searchBar.find("input").simulate("change", { target: { value: "intermediate value" } });
51 // jest.advanceTimersByTime(1000);
52 // expect(onSearch).toBeCalledWith("intermediate value");
53 // searchBar.find("input").simulate("change", { target: { value: "latest value" } });
54 // jest.advanceTimersByTime(1000);
55 // expect(onSearch).toBeCalledWith("latest value");
56 // expect(onSearch).toHaveBeenCalledTimes(2);
62 const mockSearchProps = () => ({
69 saveRecentQuery: jest.fn(),
70 loadRecentQueries: () => ['test'],
72 deleteSavedQuery: jest.fn(),
73 openSearchView: jest.fn(),
74 editSavedQuery: jest.fn(),
75 navigateTo: jest.fn(),
76 searchDataOnEnter: jest.fn()