19231: Add smaller page sizes (10 and 20 items) to load faster
[arvados-workbench2.git] / 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             }
31         }
32         store = createStore(combineReducers({
33             auth: (state: any = initialAuthState, action: any) => state,
34         }));
35
36         props = {
37             open: true,
38             loading: false,
39             saveEnabled: false,
40             sharedResourceUuid: 'zzzzz-4zz18-zzzzzzzzzzzzzzz',
41             privateAccess: true,
42             sharingURLsNr: 2,
43             sharingURLsDisabled: false,
44             onClose: jest.fn(),
45             onSave: jest.fn(),
46             onCreateSharingToken: jest.fn(),
47             refreshPermissions: jest.fn(),
48         };
49     });
50
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)');
57
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');
62     });
63
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');
70     });
71 });