15685: Adds integration tests, fixes rename dialog error reporting.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 12 Nov 2020 00:12:43 +0000 (21:12 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 12 Nov 2020 00:12:43 +0000 (21:12 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

cypress/integration/collection-panel.spec.js
src/components/tree/virtual-tree.tsx
src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts

index f0c53f3cd20335ce9c009d500cffee69eaedafad..c3f729f9f5cfde8909a0dd4d9ec5cc1ab3aa60e4 100644 (file)
@@ -165,6 +165,53 @@ 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.visit(`/collections/${this.testCollection.uuid}`);
+            // Rename 'bar' to 'subdir/foo'
+            cy.get('[data-cy=collection-files-panel]')
+                .contains('bar').rightclick();
+            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');
+            // Look for the "arrow icon" and expand the "subdir" directory.
+            cy.get('[data-cy=virtual-file-tree] > div > i').click();
+            // Rename 'subdir/foo' to 'baz'
+            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}baz`);
+                });
+            cy.get('[data-cy=form-submit-btn]').click();
+            cy.get('[data-cy=collection-files-panel]')
+                .should('contain', 'subdir') // empty dir kept
+                .and('contain', 'baz');
+        });
+    });
+
     it('tries to rename a file with an illegal names', function() {
         // Creates the collection using the admin token so we can set up
         // a bogus manifest text without block signatures.
@@ -175,8 +222,8 @@ describe('Collection panel tests', function() {
         .as('testCollection').then(function() {
             cy.loginAs(activeUser);
             cy.visit(`/collections/${this.testCollection.uuid}`);
-            const illegalNames = ['', '.', '..'];
-            illegalNames.forEach((name) => {
+            const illegalNamesFromBackend = ['.', '..'];
+            illegalNamesFromBackend.forEach((name) => {
                 cy.get('[data-cy=collection-files-panel]')
                     .contains('bar').rightclick();
                 cy.get('[data-cy=context-menu]')
@@ -194,6 +241,32 @@ describe('Collection panel tests', function() {
                         cy.contains('Could not rename');
                     });
                 cy.get('[data-cy=form-cancel-btn]').click();
+            });
+            const illegalNamesFromUI = [
+                ['', 'This field is required'],
+                [' ', 'Leading/trailing whitespaces not allowed'],
+                [' foo', 'Leading/trailing whitespaces not allowed'],
+                ['foo ', 'Leading/trailing whitespaces not allowed'],
+                ['//foo', 'Empty dir name not allowed']
+            ]
+            illegalNamesFromUI.forEach(([name, errMsg]) => {
+                cy.get('[data-cy=collection-files-panel]')
+                    .contains('bar').rightclick();
+                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}${name}`);
+                    });
+                cy.get('[data-cy=form-cancel-btn]').focus();
+                cy.get('[data-cy=form-dialog]')
+                    .should('contain', 'Rename')
+                    .within(() => {
+                        cy.contains(`${errMsg}`);
+                    });
+                cy.get('[data-cy=form-cancel-btn]').click();
             })
         });
     });
index 6db3d1e2598517e6706ffc787a25b3fa0f3c8f34..54938969ffded1d38c47cf1172d1fc160a7f1990 100644 (file)
@@ -130,7 +130,7 @@ export const Row =  <T, _>(itemList: VirtualTreeItem<T>[], render: any, treeProp
                 : undefined;
         };
 
-        return <div style={style}>
+        return <div data-cy='virtual-file-tree' style={style}>
             <ListItem button className={listItem}
                 style={{
                     paddingLeft: (level + 1) * levelIndentation,
index e77798f8a16b0a3eadf2bae3b7cf05b4a6117f47..7b2b2557aaf26eb2c39a729c05048dc6d7ccabbc 100644 (file)
@@ -147,7 +147,7 @@ export const renameFile = (newFullPath: string) =>
                     dispatch(snackbarActions.OPEN_SNACKBAR({ message: 'File name changed.', hideDuration: 2000 }));
                 } catch (e) {
                     const errors: FormErrors<RenameFileDialogData, string> = {
-                        name: `Could not rename the file: ${e.responseText}`
+                        path: `Could not rename the file: ${e.responseText}`
                     };
                     dispatch(stopSubmit(RENAME_FILE_DIALOG, errors));
                 }