17337: Added unit tests and directory names with non trivial names
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Wed, 31 Mar 2021 18:51:59 +0000 (20:51 +0200)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Wed, 31 Mar 2021 18:51:59 +0000 (20:51 +0200)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

cypress/integration/collection.spec.js
src/common/url.test.ts
src/common/url.ts
src/common/webdav.ts
src/services/collection-service/collection-service-files-response.test.ts
src/services/collection-service/collection-service-files-response.ts

index 7764a8ebbc6264105beffb208d1dfc061ff18fd9..841197abcfdc5a0b130ce9759e7760bc93d48584 100644 (file)
@@ -240,40 +240,48 @@ describe('Collection panel tests', function () {
                 cy.loginAs(activeUser);
                 cy.doSearch(`${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');
+                ['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);
+                    // Look for the "arrow icon" and expand the "subdir" directory.
+                    cy.get('[data-cy=virtual-file-tree] > div > i').click();
+                    // Rename 'subdir/foo' to 'foo'
+                    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.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();
+                });
             });
     });
 
index b0f8ae251af7e9a5b054c0cc2cb74ee78d20bbf6..21bc518ce1f8c687a15fc9320d76c28565c09af6 100644 (file)
@@ -2,34 +2,9 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { customDecodeURI, customEncodeURI, encodeHash } from './url';
+import { customDecodeURI, customEncodeURI } from './url';
 
 describe('url', () => {
-    describe('encodeHash', () => {
-        it('should ignore path without hash', () => {
-            // given
-            const path = 'path/without/hash';
-
-            // when
-            const result = encodeHash(path);
-
-            // then
-            expect(result).toEqual(path);
-        });
-
-        it('should replace all hashes within the path', () => {
-            // given
-            const path = 'path/with/hash # and one more #';
-            const expectedResult = 'path/with/hash %23 and one more %23';
-
-            // when
-            const result = encodeHash(path);
-
-            // then
-            expect(result).toEqual(expectedResult);
-        });
-    });
-
     describe('customDecodeURI', () => {
         it('should decode encoded URI', () => {
             // given
index 16dc6170a4d5f38d6fbc4324e133b7c8d68d4a8a..185737cac331d2a6a5eece01e8f99f293f76c230 100644 (file)
@@ -33,7 +33,3 @@ export const customDecodeURI = (path: string) => {
 
     return path;
 };
-
-export const encodeHash = (path: string) => {
-    return path.replace(/#/g, '%23');
-};
\ No newline at end of file
index 0b77f8c33262e9b7b0b284b4da682d6ec58ceb85..758a5e18e1e9ad44015b9a802d0e532e70ba3d76 100644 (file)
@@ -79,12 +79,6 @@ export class WebDAV {
                     ? this.defaults.baseURL+'/'
                     : ''}${customEncodeURI(config.url)}`);
 
-            if (config.headers && config.headers.Destination) {
-                const regexp = /(http[s]?:\/\/)?([^\/\s]+\/)(.*)/;
-                const match = decodeURIComponent(config.headers.Destination).match(regexp) || {};
-                config.headers.Destination = `${match[1]}${match[2]}${customEncodeURI(match[3])}`;
-            }
-
             const headers = { ...this.defaults.headers, ...config.headers };
             Object
                 .keys(headers)
index b2480c4bd2429c12dc0b5de8a05fd95773bb4bdd..074aa5ce707f02d3c317332e4562fdabe0492d1c 100644 (file)
@@ -11,10 +11,10 @@ describe('collection-service-files-response', () => {
         it('should correctly decode URLs & file names', () => {
             const testCases = [
                 // input URL, input display name, expected URL, expected name
-                ['table%201%202%203', 'table 1 2 3', 'table 1 2 3', 'table 1 2 3'],
-                ['table%25&amp;%3F%2A2', 'table%&amp;?*2', 'table%&?*2', 'table%&?*2'],
-                ["G%C3%BCnter%27s%20file.pdf", "Günter&#39;s file.pdf", "Günter's file.pdf", "Günter's file.pdf"],
-                ['G%25C3%25BCnter%27s%2520file.pdf', 'G%C3%BCnter&#39;s%20file.pdf', "G%C3%BCnter's%20file.pdf", "G%C3%BCnter's%20file.pdf"]
+                ['table%201%202%203', 'table 1 2 3', 'table%201%202%203', 'table 1 2 3'],
+                ['table%25&amp;%3F%2A2', 'table%&amp;?*2', 'table%25&%3F%2A2', 'table%&?*2'],
+                ["G%C3%BCnter%27s%20file.pdf", "Günter&#39;s file.pdf", "G%C3%BCnter%27s%20file.pdf", "Günter's file.pdf"],
+                ['G%25C3%25BCnter%27s%2520file.pdf', 'G%C3%BCnter&#39;s%20file.pdf', "G%25C3%25BCnter%27s%2520file.pdf", "G%C3%BCnter's%20file.pdf"]
             ];
 
             testCases.forEach(([inputURL, inputDisplayName, expectedURL, expectedName]) => {
@@ -79,7 +79,7 @@ describe('collection-service-files-response', () => {
                 const result = extractFilesData(xmlDoc);
 
                 // then
-                expect(result).toEqual([{ id: `${collUUID}/${expectedURL}`, name: expectedName, path: "", size: 3, type: "file", url: `/c=${collUUID}/${expectedURL}` }]);
+                expect(result).toEqual([{ id: `${collUUID}/${expectedName}`, name: expectedName, path: "", size: 3, type: "file", url: `/c=${collUUID}/${expectedURL}` }]);
             });
         });
     });
index 1be99457c84431cd5d9832d790eb4234832e075d..325339d00bb803d6e8aebbd19e8926f3953b56e0 100644 (file)
@@ -27,13 +27,15 @@ export const extractFilesData = (document: Document) => {
         .map(element => {
             const name = getTagValue(element, 'D:displayname', '', true); // skip decoding as value should be already decoded
             const size = parseInt(getTagValue(element, 'D:getcontentlength', '0', true), 10);
-            const url = getTagValue(element, 'D:href', '');
-            const nameSuffix = name;
+            const url = getTagValue(element, 'D:href', '', true);
             const collectionUuidMatch = collectionUrlPrefix.exec(url);
             const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : '';
-            const directory = url
+            const pathArray = url.split(`/`);
+            if (!pathArray.pop()) {
+                pathArray.pop();
+            }
+            const directory = pathArray.join('/')
                 .replace(collectionUrlPrefix, '')
-                .replace(nameSuffix, '')
                 .replace(/\/\//g, '/');
 
             const parentPath = directory.replace(/\/$/, '');
@@ -41,11 +43,11 @@ export const extractFilesData = (document: Document) => {
                 url,
                 id: [
                     collectionUuid ? collectionUuid : '',
-                    directory ? parentPath : '',
+                    directory ? unescape(parentPath) : '',
                     '/' + name
                 ].join(''),
                 name,
-                path: parentPath,
+                path: unescape(parentPath),
             };
 
             const result = getTagValue(element, 'D:resourcetype', '')