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';
8 import { Provider } from 'react-redux';
9 import { combineReducers, createStore } from 'redux';
11 import SharingDialogComponent, {
12 SharingDialogComponentProps,
13 } from './sharing-dialog-component';
15 extractUuidObjectType,
17 } from 'models/resource';
19 configure({ adapter: new Adapter() });
21 describe("<SharingDialogComponent />", () => {
22 let props: SharingDialogComponentProps;
26 const initialAuthState = {
28 keepWebServiceUrl: 'http://example.com/',
29 keepWebInlineServiceUrl: 'http://*.collections.example.com/',
32 AnonymousUserToken: ""
37 store = createStore(combineReducers({
38 auth: (state: any = initialAuthState, action: any) => state,
45 sharedResourceUuid: 'zzzzz-4zz18-zzzzzzzzzzzzzzz',
48 sharingURLsDisabled: false,
51 onCreateSharingToken: jest.fn(),
52 refreshPermissions: jest.fn(),
56 it("show sharing urls tab on collections when not disabled", () => {
57 expect(props.sharingURLsDisabled).toBe(false);
58 expect(props.sharingURLsNr).toBe(2);
59 expect(extractUuidObjectType(props.sharedResourceUuid) === ResourceObjectType.COLLECTION).toBe(true);
60 let wrapper = mount(<Provider store={store}><SharingDialogComponent {...props} /></Provider>);
61 expect(wrapper.html()).toContain('Sharing URLs (2)');
63 // disable Sharing URLs UI
64 props.sharingURLsDisabled = true;
65 wrapper = mount(<Provider store={store}><SharingDialogComponent {...props} /></Provider>);
66 expect(wrapper.html()).not.toContain('Sharing URLs');
69 it("does not show sharing urls on non-collection resources", () => {
70 props.sharedResourceUuid = 'zzzzz-j7d0g-0123456789abcde';
71 expect(extractUuidObjectType(props.sharedResourceUuid) === ResourceObjectType.COLLECTION).toBe(false);
72 expect(props.sharingURLsDisabled).toBe(false);
73 let wrapper = mount(<Provider store={store}><SharingDialogComponent {...props} /></Provider>);
74 expect(wrapper.html()).not.toContain('Sharing URLs');