1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { sanitizeToken, getCollectionItemClipboardUrl, getInlineFileUrl } from "./helpers";
7 describe('helpers', () => {
9 const url = 'https://example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html';
10 const urlWithPdh = 'https://example.com/c=012345678901234567890123456789aa+0/t=v2/a/b/LIMS/1.html';
12 describe('sanitizeToken', () => {
13 it('should sanitize token from the url', () => {
15 const result = sanitizeToken(url);
18 expect(result).toBe('https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html?api_token=v2/a/b');
22 describe('getClipboardUrl', () => {
23 it('should add redirectTo query param', () => {
25 const result = getCollectionItemClipboardUrl(url);
28 expect(result).toBe('http://localhost?redirectToDownload=https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html');
32 describe('getInlineFileUrl', () => {
33 it('should add the collection\'s uuid to the hostname', () => {
35 const webDavUrlA = 'https://*.collections.example.com/';
36 const webDavUrlB = 'https://*--collections.example.com/';
37 const webDavDownloadUrl = 'https://example.com/';
40 expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlA))
41 .toBe('https://zzzzz-4zz18-0123456789abcde.collections.example.com/t=v2/a/b/LIMS/1.html');
42 expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlB))
43 .toBe('https://zzzzz-4zz18-0123456789abcde--collections.example.com/t=v2/a/b/LIMS/1.html');
44 expect(getInlineFileUrl(urlWithPdh, webDavDownloadUrl, webDavUrlA))
45 .toBe('https://012345678901234567890123456789aa-0.collections.example.com/t=v2/a/b/LIMS/1.html');
46 expect(getInlineFileUrl(urlWithPdh, webDavDownloadUrl, webDavUrlB))
47 .toBe('https://012345678901234567890123456789aa-0--collections.example.com/t=v2/a/b/LIMS/1.html');
50 it('should keep the url the same when no inline url available', () => {
53 const webDavDownloadUrl = 'https://example.com/';
54 const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
57 expect(result).toBe('https://example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html');
60 it('should replace the url when available', () => {
62 const webDavUrl = 'https://download.example.com/';
63 const webDavDownloadUrl = 'https://example.com/';
64 const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
67 expect(result).toBe('https://download.example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html');