X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/f55d7e31aa315de4eece3139c4fa1df7d6eb929e..07bcb7d7b574ce4dfd5d335618f683e6fb1c7d4f:/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