1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { CollectionFile } from 'models/collection-file';
6 import { getFileFullPath, extractFilesData } from './collection-service-files-response';
8 describe('collection-service-files-response', () => {
10 describe('extractFilesData', () => {
11 it('should correctly decode URLs & file names', () => {
13 // input URL, input display name, expected URL, expected name
14 ['table%201%202%203', 'table 1 2 3', 'table%201%202%203', 'table 1 2 3'],
15 ['table%25&%3F%2A2', 'table%&?*2', 'table%25&%3F%2A2', 'table%&?*2'],
16 ["G%C3%BCnter%27s%20file.pdf", "Günter's file.pdf", "G%C3%BCnter%27s%20file.pdf", "Günter's file.pdf"],
17 ['G%25C3%25BCnter%27s%2520file.pdf', 'G%C3%BCnter's%20file.pdf', "G%25C3%25BCnter%27s%2520file.pdf", "G%C3%BCnter's%20file.pdf"]
20 testCases.forEach(([inputURL, inputDisplayName, expectedURL, expectedName]) => {
22 const collUUID = 'xxxxx-zzzzz-vvvvvvvvvvvvvvv';
23 const xmlData = `<?xml version="1.0" encoding="UTF-8"?>
24 <D:multistatus xmlns:D="DAV:">
26 <D:href>/c=xxxxx-zzzzz-vvvvvvvvvvvvvvv/</D:href>
30 <D:collection xmlns:D="DAV:"/>
33 <D:lockentry xmlns:D="DAV:">
42 <D:displayname></D:displayname>
43 <D:getlastmodified>Fri, 26 Mar 2021 14:44:08 GMT</D:getlastmodified>
45 <D:status>HTTP/1.1 200 OK</D:status>
49 <D:href>/c=${collUUID}/${inputURL}</D:href>
52 <D:resourcetype></D:resourcetype>
53 <D:getcontenttype>application/pdf</D:getcontenttype>
55 <D:lockentry xmlns:D="DAV:">
64 <D:displayname>${inputDisplayName}</D:displayname>
65 <D:getcontentlength>3</D:getcontentlength>
66 <D:getlastmodified>Fri, 26 Mar 2021 14:44:08 GMT</D:getlastmodified>
67 <D:getetag>"166feb9c9110c008325a59"</D:getetag>
69 <D:status>HTTP/1.1 200 OK</D:status>
74 const parser = new DOMParser();
75 const xmlDoc = parser.parseFromString(xmlData, "text/xml");
78 const result = extractFilesData(xmlDoc);
81 expect(result).toEqual([{ id: `${collUUID}/${expectedName}`, name: expectedName, path: "", size: 3, type: "file", url: `/c=${collUUID}/${expectedURL}` }]);
86 describe('getFileFullPath', () => {
87 it('should encode weird names', async () => {
91 path: 'http://localhost',
95 const result = getFileFullPath(file);
98 expect(result).toBe('http://localhost/#test');