Merge branch '21720-material-ui-upgrade'
[arvados.git] / services / workbench2 / src / views-components / search-bar / search-bar-view.cy.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6
7 describe("<SearchBarView />", () => {
8     let onSearch;
9
10     beforeEach(() => {
11         onSearch = cy.stub();
12     });
13
14     describe("on input value change", () => {
15         // TODO fix tests and delete beneath one
16         it("fix tests", () => {
17             const test = 1;
18             expect(test).to.equal(1);
19         });
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");
26         // });
27
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");
35         // });
36
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);
44         // });
45
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);
57
58         // });
59     });
60 });
61
62 const mockSearchProps = () => ({
63     currentView: '',
64     open: true,
65     onSetView: jest.fn(),
66     openView: jest.fn(),
67     loseView: jest.fn(),
68     closeView: jest.fn(),
69     saveRecentQuery: jest.fn(),
70     loadRecentQueries: () => ['test'],
71     saveQuery: jest.fn(),
72     deleteSavedQuery: jest.fn(),
73     openSearchView: jest.fn(),
74     editSavedQuery: jest.fn(),
75     navigateTo: jest.fn(),
76     searchDataOnEnter: jest.fn()
77 });