1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { mount, configure } from 'enzyme';
7 import Adapter from 'enzyme-adapter-react-16';
11 SharingURLsComponentProps
12 } from './sharing-urls-component';
14 configure({ adapter: new Adapter() });
16 describe("<SharingURLsComponent />", () => {
17 let props: SharingURLsComponentProps;
22 collectionUuid: 'collection-uuid',
23 sharingURLsPrefix: 'sharing-urls-prefix',
27 apiToken: 'aaaaaaaaaa',
28 expiresAt: '2009-01-03T18:15:00Z',
32 apiToken: 'bbbbbbbbbb',
33 expiresAt: '2009-01-03T18:15:01Z',
37 onDeleteSharingToken: jest.fn(),
39 wrapper = mount(<SharingURLsComponent {...props} />);
42 it("renders a list of sharing URLs", () => {
43 expect(wrapper.find('a').length).toBe(2);
45 expect(wrapper.find('a').at(0).text()).toContain(`Token aaaaaaaa... expiring at: ${new Date(props.sharingTokens[0].expiresAt).toLocaleString()}`);
46 expect(wrapper.find('a').at(0).props().href).toBe(`${props.sharingURLsPrefix}/c=${props.collectionUuid}/t=${props.sharingTokens[0].apiToken}/_/`);
48 expect(wrapper.find('a').at(1).text()).toContain(`Token bbbbbbbb... expiring at: ${new Date(props.sharingTokens[1].expiresAt).toLocaleString()}`);
49 expect(wrapper.find('a').at(1).props().href).toBe(`${props.sharingURLsPrefix}/c=${props.collectionUuid}/t=${props.sharingTokens[1].apiToken}/_/`);
52 it("renders a list URLs with collection UUIDs as subdomains", () => {
53 props.sharingURLsPrefix = '*.sharing-urls-prefix';
54 const sharingPrefix = '.sharing-urls-prefix';
55 wrapper = mount(<SharingURLsComponent {...props} />);
56 expect(wrapper.find('a').at(0).props().href).toBe(`${props.collectionUuid}${sharingPrefix}/t=${props.sharingTokens[0].apiToken}/_/`);
57 expect(wrapper.find('a').at(1).props().href).toBe(`${props.collectionUuid}${sharingPrefix}/t=${props.sharingTokens[1].apiToken}/_/`);
60 it("renders a list of URLs with no expiration", () => {
61 props.sharingTokens[0].expiresAt = null;
62 props.sharingTokens[1].expiresAt = null;
63 wrapper = mount(<SharingURLsComponent {...props} />);
64 expect(wrapper.find('a').at(0).text()).toContain(`Token aaaaaaaa... with no expiration date`);
65 expect(wrapper.find('a').at(1).text()).toContain(`Token bbbbbbbb... with no expiration date`);
68 it("calls delete token handler when delete button is clicked", () => {
69 wrapper.find('button').at(0).simulate('click');
70 expect(props.onDeleteSharingToken).toHaveBeenCalledWith(props.sharingTokens[0].uuid);