21700: Install Bundler system-wide in Rails postinst
[arvados.git] / services / workbench2 / src / views-components / context-menu / actions / helpers.test.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { sanitizeToken, getCollectionItemClipboardUrl, getInlineFileUrl } from "./helpers";
6
7 describe('helpers', () => {
8     // given
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';
11
12     describe('sanitizeToken', () => {
13         it('should sanitize token from the url', () => {
14             // when
15             const result = sanitizeToken(url);
16
17             // then
18             expect(result).toBe('https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html?api_token=v2/a/b');
19         });
20     });
21
22     describe('getClipboardUrl', () => {
23         it('should add redirectTo query param', () => {
24             // when
25             const result = getCollectionItemClipboardUrl(url);
26
27             // then
28             expect(result).toBe('http://localhost?redirectToDownload=https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html');
29         });
30     });
31
32     describe('getInlineFileUrl', () => {
33         it('should add the collection\'s uuid to the hostname', () => {
34             // when
35             const webDavUrlA = 'https://*.collections.example.com/';
36             const webDavUrlB = 'https://*--collections.example.com/';
37             const webDavDownloadUrl = 'https://example.com/';
38
39             // then
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');
48         });
49
50         it('should keep the url the same when no inline url available', () => {
51             // when
52             const webDavUrl = '';
53             const webDavDownloadUrl = 'https://example.com/';
54             const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
55
56             // then
57             expect(result).toBe('https://example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html');
58         });
59
60         it('should replace the url when available', () => {
61             // when
62             const webDavUrl = 'https://download.example.com/';
63             const webDavDownloadUrl = 'https://example.com/';
64             const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
65
66             // then
67             expect(result).toBe('https://download.example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html');
68         });
69     });
70 });