Merge branch '22134-railsapi-envvars'
[arvados.git] / services / workbench2 / src / views-components / sharing-dialog / sharing-dialog-component.cy.js
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 { Provider } from 'react-redux';
7 import { combineReducers, createStore } from 'redux';
8 import { SharingDialogComponent } from './sharing-dialog-component';
9 import {
10     extractUuidObjectType,
11     ResourceObjectType
12 } from 'models/resource';
13 import { ThemeProvider } from "@mui/material";
14 import { CustomTheme } from 'common/custom-theme';
15
16 describe("<SharingDialogComponent />", () => {
17     let props;
18     let store;
19
20     beforeEach(() => {
21         const initialAuthState = {
22             config: {
23                 keepWebServiceUrl: 'http://example.com/',
24                 keepWebInlineServiceUrl: 'http://*.collections.example.com/',
25                 clusterConfig: {
26                     Users: {
27                         AnonymousUserToken: ""
28                     }
29                 }
30             }
31         }
32         store = createStore(combineReducers({
33             auth: (state = initialAuthState, action) => 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: cy.stub(),
45             onSave: cy.stub(),
46             onCreateSharingToken: cy.stub(),
47             refreshPermissions: cy.stub(),
48         };
49     });
50
51     it("show sharing urls tab on collections when not disabled", () => {
52         expect(props.sharingURLsDisabled).to.equal(false);
53         expect(props.sharingURLsNr).to.equal(2);
54         expect(extractUuidObjectType(props.sharedResourceUuid)).to.equal(ResourceObjectType.COLLECTION)
55         cy.mount(
56             <Provider store={store}>
57                 <ThemeProvider theme={CustomTheme}>
58                     <SharingDialogComponent {...props} />
59                 </ThemeProvider>
60             </Provider>);
61         cy.get('html').should('contain', 'Sharing URLs (2)');
62
63         // disable Sharing URLs UI
64         props.sharingURLsDisabled = true;
65         cy.mount(
66             <Provider store={store}>
67                 <ThemeProvider theme={CustomTheme}>
68                     <SharingDialogComponent {...props} />
69                 </ThemeProvider>
70             </Provider>);
71         cy.get('html').should('not.contain', 'Sharing URLs');
72     });
73
74     it("does not show sharing urls on non-collection resources", () => {
75         props.sharedResourceUuid = 'zzzzz-j7d0g-0123456789abcde';
76         expect(extractUuidObjectType(props.sharedResourceUuid)).to.not.equal(ResourceObjectType.COLLECTION);
77         expect(props.sharingURLsDisabled).to.equal(false);
78         cy.mount(
79             <Provider store={store}>
80                 <ThemeProvider theme={CustomTheme}>
81                     <SharingDialogComponent {...props} />
82                 </ThemeProvider>
83             </Provider>);
84         cy.get('html').should('not.contain', 'Sharing URLs');
85     });
86 });