From: Daniel Kutyła Date: Thu, 9 Sep 2021 18:44:28 +0000 (+0200) Subject: 17585: Added tests X-Git-Tag: 2.3.0~1^2~5 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/3ef505311c624abd61dd899283e061974abe8efb 17585: Added tests Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- diff --git a/cypress/integration/collection.spec.js b/cypress/integration/collection.spec.js index c169de2f..bf2375d0 100644 --- a/cypress/integration/collection.spec.js +++ b/cypress/integration/collection.spec.js @@ -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(() => { + cy.wait(1000); 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, { @@ -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. diff --git a/src/components/collection-panel-files/collection-panel-files.tsx b/src/components/collection-panel-files/collection-panel-files.tsx index 12dd554c..70c72107 100644 --- a/src/components/collection-panel-files/collection-panel-files.tsx +++ b/src/components/collection-panel-files/collection-panel-files.tsx @@ -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 { CustomizeTableIcon } from 'components/icon/icon'; +import { CustomizeTableIcon, DownloadIcon } from 'components/icon/icon'; 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'; @@ -40,7 +40,7 @@ export interface CollectionPanelFilesProps { 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 = (theme: Theme) => ({ wrapper: { @@ -85,7 +85,7 @@ const styles: StyleRulesCallback = (theme: Theme) => ({ justifyContent: 'center' }, searchWrapper: { - width: '100%', + display: 'inline-block', marginBottom: '1rem' }, searchWrapperHidden: { @@ -112,6 +112,9 @@ const styles: StyleRulesCallback = (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%)', }, + pathPanelPathWrapper: { + display: 'inline-block', + }, leftPanel: { flex: 0, padding: '1rem', @@ -151,6 +154,12 @@ const styles: StyleRulesCallback = (theme: Theme) => ({ }, 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 & { 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(); @@ -197,16 +206,32 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState } }, [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') { @@ -217,19 +242,20 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState } 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(() => { @@ -244,7 +270,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState 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 @@ -258,11 +284,6 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState const handleRightClick = React.useCallback( (event) => { event.preventDefault(); - - if (!rightClickUsed) { - setRightClickUsed(true); - } - 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 (!rightClickUsed) { + setRightClickUsed(true); + } } }, [onItemMenuOpen, isWritable, rightData] // eslint-disable-line react-hooks/exhaustive-deps @@ -380,17 +405,19 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState return (
- { - path - .map((p: string, index: number) => - {index === 0 ? 'Home' : p} /  - ) - } +
+ { + path + .map((p: string, index: number) => + {index === 0 ? 'Home' : p} /  + ) + } +
+ { + isWritable && + + }
{ rightData && !isLoading ? @@ -473,7 +513,7 @@ export const CollectionPanelFiles = withStyles(styles)(connect((state: RootState {getItemIcon(type, null)}
{name}
- + {formatFileSize(size)}