16115: Adds unit tests to SharingURLsComponent.
authorLucas Di Pentima <lucas.dipentima@curii.com>
Mon, 16 May 2022 13:50:59 +0000 (10:50 -0300)
committerLucas Di Pentima <lucas.dipentima@curii.com>
Mon, 16 May 2022 14:30:10 +0000 (11:30 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima@curii.com>

src/views-components/sharing-dialog/sharing-urls-component.test.tsx [new file with mode: 0644]
src/views-components/sharing-dialog/sharing-urls-component.tsx

diff --git a/src/views-components/sharing-dialog/sharing-urls-component.test.tsx b/src/views-components/sharing-dialog/sharing-urls-component.test.tsx
new file mode 100644 (file)
index 0000000..0cbc661
--- /dev/null
@@ -0,0 +1,64 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import React from 'react';
+import { mount, configure } from 'enzyme';
+import Adapter from 'enzyme-adapter-react-16';
+
+import {
+    SharingURLsComponent,
+    SharingURLsComponentProps
+} from './sharing-urls-component';
+
+configure({ adapter: new Adapter() });
+
+describe("<SharingURLsComponent />", () => {
+    let props: SharingURLsComponentProps;
+    let wrapper;
+
+    beforeEach(() => {
+        props = {
+            collectionUuid: 'collection-uuid',
+            sharingURLsPrefix: 'sharing-urls-prefix',
+            sharingTokens: [
+                {
+                    uuid: 'token-uuid1',
+                    apiToken: 'aaaaaaaaaa',
+                    expiresAt: '2009-01-03T18:15:00Z',
+                },
+                {
+                    uuid: 'token-uuid2',
+                    apiToken: 'bbbbbbbbbb',
+                    expiresAt: '2009-01-03T18:15:01Z',
+                },
+            ],
+            onCopy: jest.fn(),
+            onDeleteSharingToken: jest.fn(),
+        };
+        wrapper = mount(<SharingURLsComponent {...props} />);
+    });
+
+    it("renders a list of sharing URLs", () => {
+        expect(wrapper.find('a').length).toBe(2);
+        // Check 1st URL
+        expect(wrapper.find('a').at(0).text()).toContain(`Token aaaaaaaa... expiring at: ${new Date(props.sharingTokens[0].expiresAt).toLocaleString()}`);
+        expect(wrapper.find('a').at(0).props().href).toBe(`${props.sharingURLsPrefix}/c=${props.collectionUuid}/t=${props.sharingTokens[0].apiToken}/_/`);
+        // Check 2nd URL
+        expect(wrapper.find('a').at(1).text()).toContain(`Token bbbbbbbb... expiring at: ${new Date(props.sharingTokens[1].expiresAt).toLocaleString()}`);
+        expect(wrapper.find('a').at(1).props().href).toBe(`${props.sharingURLsPrefix}/c=${props.collectionUuid}/t=${props.sharingTokens[1].apiToken}/_/`);
+    });
+
+    it("renders a list URLs with collection UUIDs as subdomains", () => {
+        props.sharingURLsPrefix = '*.sharing-urls-prefix';
+        const sharingPrefix = '.sharing-urls-prefix';
+        wrapper = mount(<SharingURLsComponent {...props} />);
+        expect(wrapper.find('a').at(0).props().href).toBe(`${props.collectionUuid}${sharingPrefix}/t=${props.sharingTokens[0].apiToken}/_/`);
+        expect(wrapper.find('a').at(1).props().href).toBe(`${props.collectionUuid}${sharingPrefix}/t=${props.sharingTokens[1].apiToken}/_/`);
+    });
+
+    it("calls delete token handler when delete button is clicked", () => {
+        wrapper.find('button').at(0).simulate('click');
+        expect(props.onDeleteSharingToken).toHaveBeenCalledWith(props.sharingTokens[0].uuid);
+    });
+});
\ No newline at end of file
index 5151e8a2e0a2090f1cd033a3bf3ccce36b3ee9f4..1638aaf768e33ea7b41900e3084e74669ae44407 100644 (file)
@@ -55,7 +55,7 @@ export interface SharingURLsComponentActionProps {
     onCopy: (message: string) => void;
 }
 
     onCopy: (message: string) => void;
 }
 
-type SharingURLsComponentProps = SharingURLsComponentDataProps & SharingURLsComponentActionProps;
+export type SharingURLsComponentProps = SharingURLsComponentDataProps & SharingURLsComponentActionProps;
 
 export const SharingURLsComponent = withStyles(styles)((props: SharingURLsComponentProps & WithStyles<CssRules>) => <Grid container direction='column' spacing={24} className={props.classes.sharingUrlList}>
     { props.sharingTokens.length > 0
 
 export const SharingURLsComponent = withStyles(styles)((props: SharingURLsComponentProps & WithStyles<CssRules>) => <Grid container direction='column' spacing={24} className={props.classes.sharingUrlList}>
     { props.sharingTokens.length > 0