21700: Install Bundler system-wide in Rails postinst
[arvados.git] / services / workbench2 / src / views-components / context-menu / actions / download-action.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import axios from 'axios';
7 import { configure, shallow } from "enzyme";
8 import Adapter from 'enzyme-adapter-react-16';
9 import { ListItem } from '@material-ui/core';
10 import JSZip from 'jszip';
11 import { DownloadAction } from './download-action';
12
13 configure({ adapter: new Adapter() });
14
15 jest.mock('axios');
16
17 jest.mock('file-saver', () => ({
18     saveAs: jest.fn(),
19 }));
20
21 const mock = {
22     file: jest.fn(),
23     generateAsync: jest.fn().mockImplementation(() => Promise.resolve('test')),
24 };
25
26 describe('<DownloadAction />', () => {
27     let props;
28     let zip;
29
30     beforeEach(() => {
31         props = {};
32         zip = new JSZip();
33         (axios as any).get.mockImplementationOnce(() => Promise.resolve({ data: '1234' }));
34     });
35
36     it('should return null if missing href or kind of file in props', () => {
37         // when
38         const wrapper = shallow(<DownloadAction {...props} />);
39
40         // then
41         expect(wrapper.html()).toBeNull();
42     });
43
44     it('should return a element', () => {
45         // setup
46         props.href = '#';
47
48         // when
49         const wrapper = shallow(<DownloadAction {...props} />);
50
51         // then
52         expect(wrapper.html()).not.toBeNull();
53     });
54
55     it('should handle download', () => {
56         // setup
57         props = {
58             href: ['file1'],
59             kind: 'files',
60             download: [],
61             currentCollectionUuid: '123412-123123'
62         };
63         const wrapper = shallow(<DownloadAction {...props} />);
64
65         // when
66         wrapper.find(ListItem).simulate('click');
67
68         // then
69         expect(axios.get).toHaveBeenCalledWith(props.href[0]);
70     });
71 });