21037: fixed all linter warnings Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox...
[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 SharingDialogComponent, {
12     SharingDialogComponentProps,
13 } from './sharing-dialog-component';
14 import {
15     extractUuidObjectType,
16     ResourceObjectType
17 } from 'models/resource';
18
19 configure({ adapter: new Adapter() });
20
21 describe("<SharingDialogComponent />", () => {
22     let props: SharingDialogComponentProps;
23     let store;
24
25     beforeEach(() => {
26         const initialAuthState = {
27             config: {
28                 keepWebServiceUrl: 'http://example.com/',
29                 keepWebInlineServiceUrl: 'http://*.collections.example.com/',
30                 clusterConfig: {
31                     Users: {
32                         AnonymousUserToken: ""
33                     }
34                 }
35             }
36         }
37         store = createStore(combineReducers({
38             auth: (state: any = initialAuthState, action: any) => state,
39         }));
40
41         props = {
42             open: true,
43             loading: false,
44             saveEnabled: false,
45             sharedResourceUuid: 'zzzzz-4zz18-zzzzzzzzzzzzzzz',
46             privateAccess: true,
47             sharingURLsNr: 2,
48             sharingURLsDisabled: false,
49             onClose: jest.fn(),
50             onSave: jest.fn(),
51             onCreateSharingToken: jest.fn(),
52             refreshPermissions: jest.fn(),
53         };
54     });
55
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)');
62
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');
67     });
68
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');
75     });
76 });