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