18559: Combine firstName and lastName users column, add link navigation, fix sorting
[arvados-workbench2.git] / src / views-components / data-explorer / renderers.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 { mount, configure } from 'enzyme';
7 import { ResourceFileSize } from './renderers';
8 import Adapter from "enzyme-adapter-react-16";
9 import { Provider } from 'react-redux';
10 import configureMockStore from 'redux-mock-store'
11 import { ResourceKind } from '../../models/resource';
12
13 const middlewares = [];
14 const mockStore = configureMockStore(middlewares);
15
16 configure({ adapter: new Adapter() });
17
18 describe('renderers', () => {
19     let props = null;
20
21     describe('ResourceFileSize', () => {
22         beforeEach(() => {
23             props = {
24                 uuid: 'UUID',
25             };
26         });
27
28         it('should render collection fileSizeTotal', () => {
29             // given
30             const store = mockStore({ resources: {
31                 [props.uuid]: {
32                     kind: ResourceKind.COLLECTION,
33                     fileSizeTotal: 100,
34                 }
35             }});
36
37             // when
38             const wrapper = mount(<Provider store={store}>
39                 <ResourceFileSize {...props}></ResourceFileSize>
40             </Provider>);
41
42             // then
43             expect(wrapper.text()).toContain('100 B');
44         });
45
46         it('should render 0 B as file size', () => {
47             // given
48             const store = mockStore({ resources: {} });
49
50             // when
51             const wrapper = mount(<Provider store={store}>
52                 <ResourceFileSize {...props}></ResourceFileSize>
53             </Provider>);
54
55             // then
56             expect(wrapper.text()).toContain('0 B');
57         });
58
59         it('should render empty string for non collection resource', () => {
60             // given
61             const store1 = mockStore({ resources: {
62                 [props.uuid]: {
63                     kind: ResourceKind.PROJECT,
64                 }
65             }});
66             const store2 = mockStore({ resources: {
67                 [props.uuid]: {
68                     kind: ResourceKind.PROJECT,
69                 }
70             }});
71
72             // when
73             const wrapper1 = mount(<Provider store={store1}>
74                 <ResourceFileSize {...props}></ResourceFileSize>
75             </Provider>);
76             const wrapper2 = mount(<Provider store={store2}>
77                 <ResourceFileSize {...props}></ResourceFileSize>
78             </Provider>);
79
80             // then
81             expect(wrapper1.text()).toContain('');
82             expect(wrapper2.text()).toContain('');
83         });
84     });
85 });