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';
12 SharingDialogComponent,
13 SharingDialogComponentProps,
14 } from './sharing-dialog-component';
16 extractUuidObjectType,
18 } from 'models/resource';
20 configure({ adapter: new Adapter() });
22 describe("<SharingDialogComponent />", () => {
23 let props: SharingDialogComponentProps;
27 const initialAuthState = {
29 keepWebServiceUrl: 'http://example.com/',
30 keepWebInlineServiceUrl: 'http://*.collections.example.com/',
33 AnonymousUserToken: ""
38 store = createStore(combineReducers({
39 auth: (state: any = initialAuthState, action: any) => state,
46 sharedResourceUuid: 'zzzzz-4zz18-zzzzzzzzzzzzzzz',
49 sharingURLsDisabled: false,
52 onCreateSharingToken: jest.fn(),
53 refreshPermissions: jest.fn(),
57 it("show sharing urls tab on collections when not disabled", () => {
58 expect(props.sharingURLsDisabled).toBe(false);
59 expect(props.sharingURLsNr).toBe(2);
60 expect(extractUuidObjectType(props.sharedResourceUuid) === ResourceObjectType.COLLECTION).toBe(true);
61 let wrapper = mount(<Provider store={store}><SharingDialogComponent {...props} /></Provider>);
62 expect(wrapper.html()).toContain('Sharing URLs (2)');
64 // disable Sharing URLs UI
65 props.sharingURLsDisabled = true;
66 wrapper = mount(<Provider store={store}><SharingDialogComponent {...props} /></Provider>);
67 expect(wrapper.html()).not.toContain('Sharing URLs');
70 it("does not show sharing urls on non-collection resources", () => {
71 props.sharedResourceUuid = 'zzzzz-j7d0g-0123456789abcde';
72 expect(extractUuidObjectType(props.sharedResourceUuid) === ResourceObjectType.COLLECTION).toBe(false);
73 expect(props.sharingURLsDisabled).toBe(false);
74 let wrapper = mount(<Provider store={store}><SharingDialogComponent {...props} /></Provider>);
75 expect(wrapper.html()).not.toContain('Sharing URLs');