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 store = createStore(combineReducers({
33 auth: (state: any = initialAuthState, action: any) => state,
40 sharedResourceUuid: 'zzzzz-4zz18-zzzzzzzzzzzzzzz',
43 sharingURLsDisabled: false,
46 onCreateSharingToken: jest.fn(),
47 refreshPermissions: jest.fn(),
51 it("show sharing urls tab on collections when not disabled", () => {
52 expect(props.sharingURLsDisabled).toBe(false);
53 expect(props.sharingURLsNr).toBe(2);
54 expect(extractUuidObjectType(props.sharedResourceUuid) === ResourceObjectType.COLLECTION).toBe(true);
55 let wrapper = mount(<Provider store={store}><SharingDialogComponent {...props} /></Provider>);
56 expect(wrapper.html()).toContain('Sharing URLs (2)');
58 // disable Sharing URLs UI
59 props.sharingURLsDisabled = true;
60 wrapper = mount(<Provider store={store}><SharingDialogComponent {...props} /></Provider>);
61 expect(wrapper.html()).not.toContain('Sharing URLs');
64 it("does not show sharing urls on non-collection resources", () => {
65 props.sharedResourceUuid = 'zzzzz-j7d0g-0123456789abcde';
66 expect(extractUuidObjectType(props.sharedResourceUuid) === ResourceObjectType.COLLECTION).toBe(false);
67 expect(props.sharingURLsDisabled).toBe(false);
68 let wrapper = mount(<Provider store={store}><SharingDialogComponent {...props} /></Provider>);
69 expect(wrapper.html()).not.toContain('Sharing URLs');