[ARVADOS-WORKBENCH2] updated: 1.4.1-433-gf15181b0

Git user git at public.arvados.org
Mon Sep 28 15:12:48 UTC 2020


Summary of changes:
 src/common/redirect-to.test.ts                     | 61 ++++++++++++++++++++++
 .../actions/copy-to-clipboard-action.test.tsx      | 36 +++++++++++++
 .../actions/file-viewer-action.test.tsx            | 33 ++++++++++++
 .../context-menu/actions/helpers.test.ts           | 30 +++++++++++
 .../actions/{helpers.tsx => helpers.ts}            |  0
 5 files changed, 160 insertions(+)
 create mode 100644 src/common/redirect-to.test.ts
 create mode 100644 src/views-components/context-menu/actions/copy-to-clipboard-action.test.tsx
 create mode 100644 src/views-components/context-menu/actions/file-viewer-action.test.tsx
 create mode 100644 src/views-components/context-menu/actions/helpers.test.ts
 rename src/views-components/context-menu/actions/{helpers.tsx => helpers.ts} (100%)

       via  f15181b0b69599cc33385d4af2f1a60de087882b (commit)
      from  055723f58e163f0b5e49c1e8b92fd1bebe81873e (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit f15181b0b69599cc33385d4af2f1a60de087882b
Author: Daniel Kutyła <daniel.kutyla at contractors.roche.com>
Date:   Mon Sep 28 17:12:10 2020 +0200

    16812: Added unit tests
    
    Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla at contractors.roche.com>

diff --git a/src/common/redirect-to.test.ts b/src/common/redirect-to.test.ts
new file mode 100644
index 00000000..24eaada8
--- /dev/null
+++ b/src/common/redirect-to.test.ts
@@ -0,0 +1,61 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { storeRedirects, handleRedirects } from './redirect-to';
+
+describe('redirect-to', () => {
+    const redirectTo = 'http://localhost/test123';
+
+    describe('storeRedirects', () => {
+        beforeEach(() => {
+            Object.defineProperty(window, 'location', {
+                value: {
+                    href: `${window.location.href}?redirectTo=${redirectTo}`
+                }
+            });
+            Object.defineProperty(window, 'sessionStorage', {
+                value: {
+                    setItem: jest.fn(),
+                },
+                writable: true
+            });
+        });
+
+        it('should store redirectTo in the session storage', () => {
+            // when
+            storeRedirects();
+
+            // then
+            expect(window.sessionStorage.setItem).toHaveBeenCalledWith('redirectTo', redirectTo);
+        });
+    });
+
+    describe('handleRedirects', () => {
+        beforeEach(() => {
+            Object.defineProperty(window, 'location', {
+                value: {
+                    href: ''
+                }
+            });
+            Object.defineProperty(window, 'sessionStorage', {
+                value: {
+                    getItem: () => redirectTo,
+                    removeItem: jest.fn(),
+                },
+                writable: true
+            });
+        });
+
+        it('should redirect to page when it is present in session storage', () => {
+            // given
+            const token = 'testToken';
+
+            // when
+            handleRedirects(token);
+
+            // then
+            expect(window.location.href).toBe(`${redirectTo}?api_token=${token}`);
+        });
+    });
+});
\ No newline at end of file
diff --git a/src/views-components/context-menu/actions/copy-to-clipboard-action.test.tsx b/src/views-components/context-menu/actions/copy-to-clipboard-action.test.tsx
new file mode 100644
index 00000000..1ada703b
--- /dev/null
+++ b/src/views-components/context-menu/actions/copy-to-clipboard-action.test.tsx
@@ -0,0 +1,36 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { shallow, configure } from 'enzyme';
+import { ListItem } from "@material-ui/core";
+import * as Adapter from 'enzyme-adapter-react-16';
+import { CopyToClipboardAction } from './copy-to-clipboard-action';
+
+configure({ adapter: new Adapter() });
+
+jest.mock('copy-to-clipboard', () => jest.fn());
+
+describe('CopyToClipboardAction', () => {
+    let props;
+
+    beforeEach(() => {
+        props = {
+            onClick: jest.fn(),
+            href: 'https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/t=1ha4ykd3w14ed19b2gh3uyjrjup38vsx27x1utwdne0bxcfg5d/LIMS/1.html',
+        };
+    });
+
+    it('should render properly and handle click', () => {
+        // when
+        const wrapper = shallow(<CopyToClipboardAction {...props} />);
+        wrapper.find(ListItem).simulate('click');
+
+        // then
+        expect(wrapper).not.toBeUndefined();
+
+        // and
+        expect(props.onClick).toHaveBeenCalled();
+    });
+});
\ No newline at end of file
diff --git a/src/views-components/context-menu/actions/file-viewer-action.test.tsx b/src/views-components/context-menu/actions/file-viewer-action.test.tsx
new file mode 100644
index 00000000..fa455def
--- /dev/null
+++ b/src/views-components/context-menu/actions/file-viewer-action.test.tsx
@@ -0,0 +1,33 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { shallow, configure } from 'enzyme';
+import * as Adapter from 'enzyme-adapter-react-16';
+import { FileViewerAction } from './file-viewer-action';
+
+configure({ adapter: new Adapter() });
+
+describe('FileViewerAction', () => {
+    let props;
+
+    beforeEach(() => {
+        props = {
+            onClick: jest.fn(),
+            href: 'https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/t=1ha4ykd3w14ed19b2gh3uyjrjup38vsx27x1utwdne0bxcfg5d/LIMS/1.html',
+        };
+    });
+
+    it('should render properly and handle click', () => {
+        // when
+        const wrapper = shallow(<FileViewerAction {...props} />);
+        wrapper.find('a').simulate('click');
+
+        // then
+        expect(wrapper).not.toBeUndefined();
+
+        // and
+        expect(props.onClick).toHaveBeenCalled();
+    });
+});
\ No newline at end of file
diff --git a/src/views-components/context-menu/actions/helpers.test.ts b/src/views-components/context-menu/actions/helpers.test.ts
new file mode 100644
index 00000000..6aaacc2f
--- /dev/null
+++ b/src/views-components/context-menu/actions/helpers.test.ts
@@ -0,0 +1,30 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { sanitizeToken, getClipboardUrl } from "./helpers";
+
+describe('helpers', () => {
+    // given
+    const url = 'https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/t=1ha4ykd3w14ed19b2gh3uyjrjup38vsx27x1utwdne0bxcfg5d/LIMS/1.html';
+
+    describe('sanitizeToken', () => {
+        it('should sanitize token from the url', () => {
+            // when
+            const result = sanitizeToken(url);
+
+            // then
+            expect(result).toBe('https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/LIMS/1.html?api_token=1ha4ykd3w14ed19b2gh3uyjrjup38vsx27x1utwdne0bxcfg5d');
+        });
+    });
+
+    describe('getClipboardUrl', () => {
+        it('should add redirectTo query param', () => {
+            // when
+            const result = getClipboardUrl(url);
+
+            // then
+            expect(result).toBe('http://localhost?redirectTo=https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/LIMS/1.html');
+        });
+    });
+});
\ No newline at end of file
diff --git a/src/views-components/context-menu/actions/helpers.tsx b/src/views-components/context-menu/actions/helpers.ts
similarity index 100%
rename from src/views-components/context-menu/actions/helpers.tsx
rename to src/views-components/context-menu/actions/helpers.ts

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list