17526: Rename cyberduck tab to webdav, mention credentials in mac/win tab
[arvados.git] / src / views-components / webdav-s3-dialog / webdav-s3-dialog.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 { MuiThemeProvider, WithStyles } from '@material-ui/core';
9 import { CustomTheme } from 'common/custom-theme';
10 import { WebDavS3InfoDialog, CssRules } from './webdav-s3-dialog';
11 import { WithDialogProps } from 'store/dialog/with-dialog';
12 import { WebDavS3InfoDialogData, COLLECTION_WEBDAV_S3_DIALOG_NAME } from 'store/collections/collection-info-actions';
13 import { Provider } from "react-redux";
14 import { createStore, combineReducers } from 'redux';
15
16 configure({ adapter: new Adapter() });
17
18 describe('WebDavS3InfoDialog', () => {
19     let props: WithDialogProps<WebDavS3InfoDialogData> & WithStyles<CssRules>;
20     let store;
21
22     beforeEach(() => {
23         const initialDialogState = {
24             [COLLECTION_WEBDAV_S3_DIALOG_NAME]: {
25                 open: true,
26                 data: {
27                     uuid: "zzzzz-4zz18-b1f8tbldjrm8885",
28                     token: "v2/zzzzb-jjjjj-123123/xxxtokenxxx",
29                     downloadUrl: "https://download.example.com",
30                     collectionsUrl: "https://collections.example.com",
31                     localCluster: "zzzzz",
32                     username: "bobby",
33                     activeTab: 0,
34                     setActiveTab: (event: any, tabNr: number) => { }
35                 }
36             }
37         };
38         const initialAuthState = {
39             localCluster: "zzzzz",
40             remoteHostsConfig: {},
41             sessions: {},
42         };
43         store = createStore(combineReducers({
44             dialog: (state: any = initialDialogState, action: any) => state,
45             auth: (state: any = initialAuthState, action: any) => state,
46         }));
47
48         props = {
49             classes: {
50                 details: 'details',
51             }
52         };
53     });
54
55     it('render cyberduck tab', () => {
56         store.getState().dialog[COLLECTION_WEBDAV_S3_DIALOG_NAME].data.activeTab = 0;
57         // when
58         const wrapper = mount(
59             <MuiThemeProvider theme={CustomTheme}>
60                 <Provider store={store}>
61                     <WebDavS3InfoDialog {...props} />
62                 </Provider>
63             </MuiThemeProvider>
64         );
65
66         // then
67         expect(wrapper.text()).toContain("davs://bobby@download.example.com/by_id/zzzzz-4zz18-b1f8tbldjrm8885");
68     });
69
70     it('render win/mac tab', () => {
71         store.getState().dialog[COLLECTION_WEBDAV_S3_DIALOG_NAME].data.activeTab = 1;
72         // when
73         const wrapper = mount(
74             <MuiThemeProvider theme={CustomTheme}>
75                 <Provider store={store}>
76                     <WebDavS3InfoDialog {...props} />
77                 </Provider>
78             </MuiThemeProvider>
79         );
80
81         // then
82         expect(wrapper.text()).toContain("https://download.example.com/by_id/zzzzz-4zz18-b1f8tbldjrm8885");
83     });
84
85     it('render s3 tab with federated token', () => {
86         store.getState().dialog[COLLECTION_WEBDAV_S3_DIALOG_NAME].data.activeTab = 2;
87         // when
88         const wrapper = mount(
89             <MuiThemeProvider theme={CustomTheme}>
90                 <Provider store={store}>
91                     <WebDavS3InfoDialog {...props} />
92                 </Provider>
93             </MuiThemeProvider>
94         );
95
96         // then
97         expect(wrapper.text()).toContain("Secret Keyv2_zzzzb-jjjjj-123123_xxxtokenxxx");
98     });
99
100     it('render s3 tab with local token', () => {
101         store.getState().dialog[COLLECTION_WEBDAV_S3_DIALOG_NAME].data.activeTab = 2;
102         store.getState().dialog[COLLECTION_WEBDAV_S3_DIALOG_NAME].data.token = "v2/zzzzz-jjjjj-123123/xxxtokenxxx";
103         // when
104         const wrapper = mount(
105             <MuiThemeProvider theme={CustomTheme}>
106                 <Provider store={store}>
107                     <WebDavS3InfoDialog {...props} />
108                 </Provider>
109             </MuiThemeProvider>
110         );
111
112         // then
113         expect(wrapper.text()).toContain("Access Keyzzzzz-jjjjj-123123Secret Keyxxxtokenxxx");
114     });
115
116     it('render cyberduck tab with wildcard DNS', () => {
117         store.getState().dialog[COLLECTION_WEBDAV_S3_DIALOG_NAME].data.activeTab = 0;
118         store.getState().dialog[COLLECTION_WEBDAV_S3_DIALOG_NAME].data.collectionsUrl = "https://*.collections.example.com";
119         // when
120         const wrapper = mount(
121             <MuiThemeProvider theme={CustomTheme}>
122                 <Provider store={store}>
123                     <WebDavS3InfoDialog {...props} />
124                 </Provider>
125             </MuiThemeProvider>
126         );
127
128         // then
129         expect(wrapper.text()).toContain("davs://bobby@zzzzz-4zz18-b1f8tbldjrm8885.collections.example.com");
130     });
131
132 });