21700: Install Bundler system-wide in Rails postinst
[arvados.git] / services / workbench2 / src / views-components / sharing-dialog / sharing-dialog-component.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
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';
10
11 import {
12     SharingDialogComponent,
13     SharingDialogComponentProps,
14 } from './sharing-dialog-component';
15 import {
16     extractUuidObjectType,
17     ResourceObjectType
18 } from 'models/resource';
19
20 configure({ adapter: new Adapter() });
21
22 describe("<SharingDialogComponent />", () => {
23     let props: SharingDialogComponentProps;
24     let store;
25
26     beforeEach(() => {
27         const initialAuthState = {
28             config: {
29                 keepWebServiceUrl: 'http://example.com/',
30                 keepWebInlineServiceUrl: 'http://*.collections.example.com/',
31                 clusterConfig: {
32                     Users: {
33                         AnonymousUserToken: ""
34                     }
35                 }
36             }
37         }
38         store = createStore(combineReducers({
39             auth: (state: any = initialAuthState, action: any) => state,
40         }));
41
42         props = {
43             open: true,
44             loading: false,
45             saveEnabled: false,
46             sharedResourceUuid: 'zzzzz-4zz18-zzzzzzzzzzzzzzz',
47             privateAccess: true,
48             sharingURLsNr: 2,
49             sharingURLsDisabled: false,
50             onClose: jest.fn(),
51             onSave: jest.fn(),
52             onCreateSharingToken: jest.fn(),
53             refreshPermissions: jest.fn(),
54         };
55     });
56
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)');
63
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');
68     });
69
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');
76     });
77 });