From 5a7d3c08744413b659fd24be59992fc1daa486e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Kuty=C5=82a?= Date: Wed, 31 Mar 2021 20:51:59 +0200 Subject: [PATCH] 17337: Added unit tests and directory names with non trivial names MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła --- cypress/integration/collection.spec.js | 76 ++++++++++--------- src/common/url.test.ts | 27 +------ src/common/url.ts | 4 - src/common/webdav.ts | 6 -- .../collection-service-files-response.test.ts | 10 +-- .../collection-service-files-response.ts | 14 ++-- 6 files changed, 56 insertions(+), 81 deletions(-) diff --git a/cypress/integration/collection.spec.js b/cypress/integration/collection.spec.js index 7764a8eb..841197ab 100644 --- a/cypress/integration/collection.spec.js +++ b/cypress/integration/collection.spec.js @@ -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(); + }); }); }); diff --git a/src/common/url.test.ts b/src/common/url.test.ts index b0f8ae25..21bc518c 100644 --- a/src/common/url.test.ts +++ b/src/common/url.test.ts @@ -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 diff --git a/src/common/url.ts b/src/common/url.ts index 16dc6170..185737ca 100644 --- a/src/common/url.ts +++ b/src/common/url.ts @@ -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 diff --git a/src/common/webdav.ts b/src/common/webdav.ts index 0b77f8c3..758a5e18 100644 --- a/src/common/webdav.ts +++ b/src/common/webdav.ts @@ -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) diff --git a/src/services/collection-service/collection-service-files-response.test.ts b/src/services/collection-service/collection-service-files-response.test.ts index b2480c4b..074aa5ce 100644 --- a/src/services/collection-service/collection-service-files-response.test.ts +++ b/src/services/collection-service/collection-service-files-response.test.ts @@ -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&%3F%2A2', 'table%&?*2', 'table%&?*2', 'table%&?*2'], - ["G%C3%BCnter%27s%20file.pdf", "Günter's file.pdf", "Günter's file.pdf", "Günter's file.pdf"], - ['G%25C3%25BCnter%27s%2520file.pdf', 'G%C3%BCnter'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&%3F%2A2', 'table%&?*2', 'table%25&%3F%2A2', 'table%&?*2'], + ["G%C3%BCnter%27s%20file.pdf", "Günter's file.pdf", "G%C3%BCnter%27s%20file.pdf", "Günter's file.pdf"], + ['G%25C3%25BCnter%27s%2520file.pdf', 'G%C3%BCnter'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}` }]); }); }); }); diff --git a/src/services/collection-service/collection-service-files-response.ts b/src/services/collection-service/collection-service-files-response.ts index 1be99457..325339d0 100644 --- a/src/services/collection-service/collection-service-files-response.ts +++ b/src/services/collection-service/collection-service-files-response.ts @@ -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', '') -- 2.30.2