From 07bcb7d7b574ce4dfd5d335618f683e6fb1c7d4f Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Mon, 16 May 2022 10:50:59 -0300 Subject: [PATCH] 16115: Adds unit tests to SharingURLsComponent. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- .../sharing-urls-component.test.tsx | 64 +++++++++++++++++++ .../sharing-dialog/sharing-urls-component.tsx | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/views-components/sharing-dialog/sharing-urls-component.test.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 index 00000000..0cbc661d --- /dev/null +++ b/src/views-components/sharing-dialog/sharing-urls-component.test.tsx @@ -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("", () => { + 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(); + }); + + 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(); + 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 diff --git a/src/views-components/sharing-dialog/sharing-urls-component.tsx b/src/views-components/sharing-dialog/sharing-urls-component.tsx index 5151e8a2..1638aaf7 100644 --- a/src/views-components/sharing-dialog/sharing-urls-component.tsx +++ b/src/views-components/sharing-dialog/sharing-urls-component.tsx @@ -55,7 +55,7 @@ export interface SharingURLsComponentActionProps { onCopy: (message: string) => void; } -type SharingURLsComponentProps = SharingURLsComponentDataProps & SharingURLsComponentActionProps; +export type SharingURLsComponentProps = SharingURLsComponentDataProps & SharingURLsComponentActionProps; export const SharingURLsComponent = withStyles(styles)((props: SharingURLsComponentProps & WithStyles) => { props.sharingTokens.length > 0 -- 2.30.2