17305: Added unit tests 17305-projects-file-size-always-0
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Mon, 7 Jun 2021 19:41:30 +0000 (21:41 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Mon, 7 Jun 2021 19:41:30 +0000 (21:41 +0200)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

src/views-components/data-explorer/renderers.test.tsx [new file with mode: 0644]
src/views-components/data-explorer/renderers.tsx

diff --git a/src/views-components/data-explorer/renderers.test.tsx b/src/views-components/data-explorer/renderers.test.tsx
new file mode 100644 (file)
index 0000000..5f752b6
--- /dev/null
@@ -0,0 +1,85 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { mount, configure } from 'enzyme';
+import { ResourceFileSize } from './renderers';
+import * as Adapter from "enzyme-adapter-react-16";
+import { Provider } from 'react-redux';
+import configureMockStore from 'redux-mock-store'
+import { ResourceKind } from '../../models/resource';
+
+const middlewares = [];
+const mockStore = configureMockStore(middlewares);
+
+configure({ adapter: new Adapter() });
+
+describe('renderers', () => {
+    let props = null;
+
+    describe('ResourceFileSize', () => {
+        beforeEach(() => {
+            props = {
+                uuid: 'UUID',
+            };
+        });
+
+        it('should render collection fileSizeTotal', () => {
+            // given
+            const store = mockStore({ resources: {
+                [props.uuid]: {
+                    kind: ResourceKind.COLLECTION,
+                    fileSizeTotal: 100,
+                }
+            }});
+
+            // when
+            const wrapper = mount(<Provider store={store}>
+                <ResourceFileSize {...props}></ResourceFileSize>
+            </Provider>);
+
+            // then
+            expect(wrapper.text()).toContain('100 B');
+        });
+
+        it('should render 0 B as file size', () => {
+            // given
+            const store = mockStore({ resources: {} });
+
+            // when
+            const wrapper = mount(<Provider store={store}>
+                <ResourceFileSize {...props}></ResourceFileSize>
+            </Provider>);
+
+            // then
+            expect(wrapper.text()).toContain('0 B');
+        });
+        
+        it('should render empty string for non collection resource', () => {
+            // given
+            const store1 = mockStore({ resources: {
+                [props.uuid]: {
+                    kind: ResourceKind.PROJECT,
+                }
+            }});
+            const store2 = mockStore({ resources: {
+                [props.uuid]: {
+                    kind: ResourceKind.PROJECT,
+                }
+            }});
+
+            // when
+            const wrapper1 = mount(<Provider store={store1}>
+                <ResourceFileSize {...props}></ResourceFileSize>
+            </Provider>);
+            const wrapper2 = mount(<Provider store={store2}>
+                <ResourceFileSize {...props}></ResourceFileSize>
+            </Provider>);
+
+            // then
+            expect(wrapper1.text()).toContain('');
+            expect(wrapper2.text()).toContain('');
+        });
+    });
+});
\ No newline at end of file
index 4ec0734442644d0168a9edc18fc0860950113303..0e3eefe231671e470075090d9f0c064b6d40bdc1 100644 (file)
@@ -418,7 +418,7 @@ export const ResourceFileSize = connect(
     (state: RootState, props: { uuid: string }) => {
         const resource = getResource<CollectionResource>(props.uuid)(state.resources);
 
-        if (resource && resource.kind === ResourceKind.COLLECTION) {
+        if (resource && resource.kind !== ResourceKind.COLLECTION) {
             return { fileSize: '' };
         }