17585: Added tests
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 9 Sep 2021 18:44:28 +0000 (20:44 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Thu, 9 Sep 2021 18:44:28 +0000 (20:44 +0200)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

cypress/integration/collection.spec.js
src/components/collection-panel-files/collection-panel-files.tsx

index c169de2f6f4101e41d2235b91bb29cb4d907201b..bf2375d0da10a0ff3e575c3d24064afe12a17c28 100644 (file)
@@ -178,6 +178,7 @@ describe('Collection panel tests', function () {
                         }
                         // Check that the file listing show both read & write operations
                         cy.get('[data-cy=collection-files-panel]').within(() => {
                         }
                         // Check that the file listing show both read & write operations
                         cy.get('[data-cy=collection-files-panel]').within(() => {
+                            cy.wait(1000);
                             cy.root().should('contain', fileName);
                             if (isWritable) {
                                 cy.get('[data-cy=upload-button]')
                             cy.root().should('contain', fileName);
                             if (isWritable) {
                                 cy.get('[data-cy=upload-button]')
@@ -279,7 +280,7 @@ describe('Collection panel tests', function () {
             });
     });
 
             });
     });
 
-    it('renames a file to a different directory', function () {
+    it.skip('renames a file to a different directory', function () {
         // Creates the collection using the admin token so we can set up
         // a bogus manifest text without block signatures.
         cy.createCollection(adminUser.token, {
         // Creates the collection using the admin token so we can set up
         // a bogus manifest text without block signatures.
         cy.createCollection(adminUser.token, {
@@ -336,6 +337,71 @@ describe('Collection panel tests', function () {
             });
     });
 
             });
     });
 
+    it('renames a file to a different directory', function () {
+        // Creates the collection using the admin token so we can set up
+        // a bogus manifest text without block signatures.
+        cy.createCollection(adminUser.token, {
+            name: `Test collection ${Math.floor(Math.random() * 999999)}`,
+            owner_uuid: activeUser.user.uuid,
+            manifest_text: ". 37b51d194a7513e45b56f6524f2d51f2+3 0:3:bar\n"
+        })
+            .as('testCollection').then(function () {
+                cy.loginAs(activeUser);
+                cy.goToPath(`/collections/${this.testCollection.uuid}`);
+
+                ['subdir', 'G%C3%BCnter\'s%20file', 'table%&?*2'].forEach((subdir) => {
+                    cy.get('[data-cy=collection-files-panel]')
+                        .contains('bar').rightclick({force: true});
+                    cy.get('[data-cy=context-menu]')
+                        .contains('Rename')
+                        .click();
+                    cy.get('[data-cy=form-dialog]')
+                        .should('contain', 'Rename')
+                        .within(() => {
+                            cy.get('input').type(`{selectall}{backspace}${subdir}/foo`);
+                        });
+                    cy.get('[data-cy=form-submit-btn]').click();
+                    cy.get('[data-cy=collection-files-panel]')
+                        .should('not.contain', 'bar')
+                        .and('contain', subdir);
+                    cy.wait(1000);
+                    cy.get('[data-cy=collection-files-panel]').contains(subdir).click();
+                    // Rename 'subdir/foo' to 'foo'
+                    cy.wait(1000);
+                    cy.get('[data-cy=collection-files-panel]')
+                        .contains('foo').rightclick();
+                    cy.get('[data-cy=context-menu]')
+                        .contains('Rename')
+                        .click();
+                    cy.get('[data-cy=form-dialog]')
+                        .should('contain', 'Rename')
+                        .within(() => {
+                            cy.get('input')
+                                .should('have.value', `${subdir}/foo`)
+                                .type(`{selectall}{backspace}bar`);
+                        });
+                    cy.get('[data-cy=form-submit-btn]').click();
+
+                    cy.wait(1000);
+                    cy.get('[data-cy=collection-files-panel]')
+                        .contains('Home')
+                        .click();
+
+                    cy.wait(2000);
+                    cy.get('[data-cy=collection-files-panel]')
+                        .should('contain', subdir) // empty dir kept
+                        .and('contain', 'bar');
+
+                    cy.get('[data-cy=collection-files-panel]')
+                        .contains(subdir).rightclick();
+                    cy.get('[data-cy=context-menu]')
+                        .contains('Remove')
+                        .click();
+                    cy.get('[data-cy=confirmation-dialog-ok-btn]').click();
+                });
+            });
+    });
+
     it('tries to rename a file with illegal names', function () {
         // Creates the collection using the admin token so we can set up
         // a bogus manifest text without block signatures.
     it('tries to rename a file with illegal names', function () {
         // Creates the collection using the admin token so we can set up
         // a bogus manifest text without block signatures.
index 12dd554ce82965cdcafa2df1ccb1b3d807e4c66a..70c72107e71125633a82c7e43558c9bd277d1caa 100644 (file)
@@ -7,9 +7,9 @@ import classNames from 'classnames';
 import { connect } from 'react-redux';
 import { FixedSizeList } from "react-window";
 import AutoSizer from "react-virtualized-auto-sizer";
 import { connect } from 'react-redux';
 import { FixedSizeList } from "react-window";
 import AutoSizer from "react-virtualized-auto-sizer";
-import { CustomizeTableIcon } from 'components/icon/icon';
+import { CustomizeTableIcon, DownloadIcon } from 'components/icon/icon';
 import { SearchInput } from 'components/search-input/search-input';
 import { SearchInput } from 'components/search-input/search-input';
-import { ListItemIcon, StyleRulesCallback, Theme, WithStyles, withStyles, Tooltip, IconButton, Checkbox, CircularProgress } from '@material-ui/core';
+import { ListItemIcon, StyleRulesCallback, Theme, WithStyles, withStyles, Tooltip, IconButton, Checkbox, CircularProgress, Button } from '@material-ui/core';
 import { FileTreeData } from '../file-tree/file-tree-data';
 import { TreeItem, TreeItemStatus } from '../tree/tree';
 import { RootState } from 'store/store';
 import { FileTreeData } from '../file-tree/file-tree-data';
 import { TreeItem, TreeItemStatus } from '../tree/tree';
 import { RootState } from 'store/store';
@@ -40,7 +40,7 @@ export interface CollectionPanelFilesProps {
     collectionPanel: any;
 }
 
     collectionPanel: any;
 }
 
-type CssRules = "loader" | "wrapper" | "dataWrapper" | "row" | "rowEmpty" | "leftPanel" | "rightPanel" | "pathPanel" | "pathPanelItem" | "rowName" | "listItemIcon" | "rowActive" | "pathPanelMenu" | "rowSelection" | "leftPanelHidden" | "leftPanelVisible" | "searchWrapper" | "searchWrapperHidden";
+type CssRules = "pathPanelPathWrapper" | "uploadButton" | "uploadIcon" | "loader" | "wrapper" | "dataWrapper" | "row" | "rowEmpty" | "leftPanel" | "rightPanel" | "pathPanel" | "pathPanelItem" | "rowName" | "listItemIcon" | "rowActive" | "pathPanelMenu" | "rowSelection" | "leftPanelHidden" | "leftPanelVisible" | "searchWrapper" | "searchWrapperHidden";
 
 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
     wrapper: {
 
 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
     wrapper: {
@@ -85,7 +85,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
         justifyContent: 'center'
     },
     searchWrapper: {
         justifyContent: 'center'
     },
     searchWrapper: {
-        width: '100%',
+        display: 'inline-block',
         marginBottom: '1rem'
     },
     searchWrapperHidden: {
         marginBottom: '1rem'
     },
     searchWrapperHidden: {
@@ -112,6 +112,9 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
         backgroundColor: '#fff',
         boxShadow: '0px 1px 3px 0px rgb(0 0 0 / 20%), 0px 1px 1px 0px rgb(0 0 0 / 14%), 0px 2px 1px -1px rgb(0 0 0 / 12%)',
     },
         backgroundColor: '#fff',
         boxShadow: '0px 1px 3px 0px rgb(0 0 0 / 20%), 0px 1px 1px 0px rgb(0 0 0 / 14%), 0px 2px 1px -1px rgb(0 0 0 / 12%)',
     },
+    pathPanelPathWrapper: {
+        display: 'inline-block',
+    },
     leftPanel: {
         flex: 0,
         padding: '1rem',
     leftPanel: {
         flex: 0,
         padding: '1rem',
@@ -151,6 +154,12 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
     },
     pathPanelItem: {
         cursor: 'pointer',
     },
     pathPanelItem: {
         cursor: 'pointer',
+    },
+    uploadIcon: {
+        transform: 'rotate(180deg)'
+    },
+    uploadButton: {
+        float: 'right',
     }
 });
 
     }
 });
 
@@ -161,7 +170,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
     collectionPanel: state.collectionPanel,
     collectionPanelFiles: state.collectionPanelFiles,
 }))((props: CollectionPanelFilesProps & WithStyles<CssRules> & { auth: AuthState }) => {
     collectionPanel: state.collectionPanel,
     collectionPanelFiles: state.collectionPanelFiles,
 }))((props: CollectionPanelFilesProps & WithStyles<CssRules> & { auth: AuthState }) => {
-    const { classes, onItemMenuOpen, isWritable, dispatch, collectionPanelFiles, collectionPanel } = props;
+    const { classes, onItemMenuOpen, onUploadDataClick, isWritable, dispatch, collectionPanelFiles, collectionPanel } = props;
     const { apiToken, config } = props.auth;
 
     const webdavClient = new WebDAV();
     const { apiToken, config } = props.auth;
 
     const webdavClient = new WebDAV();
@@ -197,16 +206,32 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
         }
     }, [props.currentItemUuid]);
 
         }
     }, [props.currentItemUuid]);
 
-    const fetchData = (rightKey, ignoreCache = false) => {
-        const dataExists = !!pathData[rightKey];
-        const runningRequest = pathPromise[rightKey];
+    const fetchData = (keys, ignoreCache = false) => {
+        const keyArray = Array.isArray(keys) ? keys : [keys];
 
 
-        if ((!dataExists || ignoreCache) && !runningRequest) {
-            setIsLoading(true);
+        Promise.all(keyArray
+            .map((key) => {
+                const dataExists = !!pathData[key];
+                const runningRequest = pathPromise[key];
 
 
-            webdavClient.propfind(`c=${rightKey}`, webDAVRequestConfig)
-                .then((request) => {
-                    if (request.responseXML != null) {
+                if ((!dataExists || ignoreCache) && (!runningRequest || ignoreCache)) {
+                    if (!isLoading) {
+                        setIsLoading(true);
+                    }
+
+                    pathPromise[key] = true;
+
+                    return webdavClient.propfind(`c=${key}`, webDAVRequestConfig);
+                }
+
+                return Promise.resolve(null);
+            })
+            .filter((promise) => !!promise)
+        )
+            .then((requests) => {
+                const newState = requests.map((request, index) => {
+                    if (request && request.responseXML != null) {
+                        const key = keyArray[index];
                         const result: any = extractFilesData(request.responseXML);
                         const sortedResult = sortBy(result, (n) => n.name).sort((n1, n2) => {
                             if (n1.type === 'directory' && n2.type !== 'directory') {
                         const result: any = extractFilesData(request.responseXML);
                         const sortedResult = sortBy(result, (n) => n.name).sort((n1, n2) => {
                             if (n1.type === 'directory' && n2.type !== 'directory') {
@@ -217,19 +242,20 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
                             }
                             return 0;
                         });
                             }
                             return 0;
                         });
-                        const newPathData = { ...pathData, [rightKey]: sortedResult };
-                        setPathData(newPathData);
+
+                        return { [key]: sortedResult };
                     }
                     }
-                })
-                .finally(() => {
-                    setIsLoading(false);
-                    delete pathPromise[rightKey];
-                });
-
-            pathPromise[rightKey] = true;
-        } else {
-            setTimeout(() => setIsLoading(false), 0);
-        }
+                    return {};
+                }).reduce((prev, next) => {
+                    return { ...next, ...prev };
+                }, {});
+
+                setPathData({ ...pathData, ...newState });
+            })
+            .finally(() => {
+                setIsLoading(false);
+                keyArray.forEach(key => delete pathPromise[key]);
+            });
     };
 
     React.useEffect(() => {
     };
 
     React.useEffect(() => {
@@ -244,7 +270,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
         const hash = (collectionPanel.item || {}).portableDataHash;
 
         if (hash && rightClickUsed) {
         const hash = (collectionPanel.item || {}).portableDataHash;
 
         if (hash && rightClickUsed) {
-            fetchData(rightKey, true);
+            fetchData([leftKey, rightKey], true);
         }
     }, [(collectionPanel.item || {}).portableDataHash]); // eslint-disable-line react-hooks/exhaustive-deps
 
         }
     }, [(collectionPanel.item || {}).portableDataHash]); // eslint-disable-line react-hooks/exhaustive-deps
 
@@ -258,11 +284,6 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
     const handleRightClick = React.useCallback(
         (event) => {
             event.preventDefault();
     const handleRightClick = React.useCallback(
         (event) => {
             event.preventDefault();
-
-            if (!rightClickUsed) {
-                setRightClickUsed(true);
-            }
-
             let elem = event.target;
 
             while (elem && elem.dataset && !elem.dataset.item) {
             let elem = event.target;
 
             while (elem && elem.dataset && !elem.dataset.item) {
@@ -278,6 +299,10 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
 
             if (id) {
                 onItemMenuOpen(event, item, isWritable);
 
             if (id) {
                 onItemMenuOpen(event, item, isWritable);
+
+                if (!rightClickUsed) {
+                    setRightClickUsed(true);
+                }
             }
         },
         [onItemMenuOpen, isWritable, rightData] // eslint-disable-line react-hooks/exhaustive-deps
             }
         },
         [onItemMenuOpen, isWritable, rightData] // eslint-disable-line react-hooks/exhaustive-deps
@@ -380,17 +405,19 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
     return (
         <div data-cy="collection-files-panel" onClick={handleClick} ref={parentRef}>
             <div className={classes.pathPanel}>
     return (
         <div data-cy="collection-files-panel" onClick={handleClick} ref={parentRef}>
             <div className={classes.pathPanel}>
-                {
-                    path
-                        .map((p: string, index: number) => <span
-                            key={`${index}-${p}`}
-                            data-item="true"
-                            className={classes.pathPanelItem}
-                            data-breadcrumb-path={p}
-                        >
-                            {index === 0 ? 'Home' : p} /&nbsp;
-                        </span>)
-                }
+                <div className={classes.pathPanelPathWrapper}>
+                    {
+                        path
+                            .map((p: string, index: number) => <span
+                                key={`${index}-${p}`}
+                                data-item="true"
+                                className={classes.pathPanelItem}
+                                data-breadcrumb-path={p}
+                            >
+                                {index === 0 ? 'Home' : p} /&nbsp;
+                            </span>)
+                    }
+                </div>
                 <Tooltip className={classes.pathPanelMenu} title="More options" disableFocusListener>
                     <IconButton
                         data-cy='collection-files-panel-options-btn'
                 <Tooltip className={classes.pathPanelMenu} title="More options" disableFocusListener>
                     <IconButton
                         data-cy='collection-files-panel-options-btn'
@@ -441,6 +468,19 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
                     <div className={classes.searchWrapper}>
                         <SearchInput label="Search" value={rightSearch} onSearch={setRightSearch} />
                     </div>
                     <div className={classes.searchWrapper}>
                         <SearchInput label="Search" value={rightSearch} onSearch={setRightSearch} />
                     </div>
+                    {
+                        isWritable &&
+                        <Button
+                            className={classes.uploadButton}
+                            data-cy='upload-button'
+                            onClick={onUploadDataClick}
+                            variant='contained'
+                            color='primary'
+                            size='small'>
+                            <DownloadIcon className={classes.uploadIcon} />
+                            Upload data
+                        </Button>
+                    }
                     <div className={classes.dataWrapper}>
                         {
                             rightData && !isLoading ?
                     <div className={classes.dataWrapper}>
                         {
                             rightData && !isLoading ?
@@ -473,7 +513,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState
                                                     {getItemIcon(type, null)} <div className={classes.rowName}>
                                                             {name}
                                                         </div>
                                                     {getItemIcon(type, null)} <div className={classes.rowName}>
                                                             {name}
                                                         </div>
-                                                        <span className={classes.rowName} style={{marginLeft: 'auto', marginRight: '1rem'}}>
+                                                        <span className={classes.rowName} style={{ marginLeft: 'auto', marginRight: '1rem' }}>
                                                             {formatFileSize(size)}
                                                         </span>
                                                     </div>
                                                             {formatFileSize(size)}
                                                         </span>
                                                     </div>