Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>
--- /dev/null
+// 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
--- /dev/null
+// 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
--- /dev/null
+// 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
--- /dev/null
+// 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