1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { configure, shallow, mount } from "enzyme";
7 import { WithStyles } from "@material-ui/core";
8 import Adapter from "enzyme-adapter-react-16";
9 import { TreeItem, TreeItemStatus } from '../tree/tree';
10 import { FileTreeData } from '../file-tree/file-tree-data';
11 import { CollectionFileType } from "../../models/collection-file";
12 import { CollectionPanelFilesComponent, CollectionPanelFilesProps, CssRules } from './collection-panel-files2';
13 import { SearchInput } from '../search-input/search-input';
15 configure({ adapter: new Adapter() });
17 jest.mock('components/file-tree/file-tree', () => ({
18 FileTree: () => 'FileTree',
21 describe('<CollectionPanelFiles />', () => {
22 let props: CollectionPanelFilesProps & WithStyles<CssRules>;
26 classes: {} as Record<CssRules, string>,
31 onUploadDataClick: jest.fn(),
32 onSearchChange: jest.fn(),
33 onItemMenuOpen: jest.fn(),
34 onOptionsMenuOpen: jest.fn(),
35 onSelectionToggle: jest.fn(),
36 onCollapseToggle: jest.fn(),
37 onFileClick: jest.fn(),
38 loadFilesFunc: jest.fn(),
43 it('renders properly', () => {
45 const wrapper = shallow(<CollectionPanelFilesComponent {...props} />);
48 expect(wrapper).not.toBeUndefined();
51 it('filters out files', () => {
53 const searchPhrase = 'test';
54 const items: Array<TreeItem<FileTreeData>> = [
58 type: CollectionFileType.DIRECTORY,
64 status: TreeItemStatus.LOADED,
69 type: CollectionFileType.FILE,
75 status: TreeItemStatus.LOADED,
80 type: CollectionFileType.FILE,
86 status: TreeItemStatus.LOADED,
92 const wrapper = mount(<CollectionPanelFilesComponent {...props} />);
93 wrapper.find(SearchInput).simulate('change', { target: { value: searchPhrase } });
96 setTimeout(() => { // we have to use set timeout because of the debounce
97 expect(wrapper.find('FileTree').prop('items'))
100 data: { url: '', type: 'directory', name: 'test' },
107 data: { url: '', type: 'file', name: 'test123' },