Merge branch '17256-file-selection-dialog-issue'
[arvados-workbench2.git] / 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, getClipboardUrl, getInlineFileUrl } from "./helpers";
6
7 describe('helpers', () => {
8     // given
9     const url = 'https://example.com/c=zzzzz/t=v2/a/b/LIMS/1.html';
10
11     describe('sanitizeToken', () => {
12         it('should sanitize token from the url', () => {
13             // when
14             const result = sanitizeToken(url);
15
16             // then
17             expect(result).toBe('https://example.com/c=zzzzz/LIMS/1.html?api_token=v2/a/b');
18         });
19     });
20
21     describe('getClipboardUrl', () => {
22         it('should add redirectTo query param', () => {
23             // when
24             const result = getClipboardUrl(url);
25
26             // then
27             expect(result).toBe('http://localhost?redirectTo=https://example.com/c=zzzzz/LIMS/1.html');
28         });
29     });
30
31     describe('getInlineFileUrl', () => {
32         it('should add the collection\'s uuid to the hostname', () => {
33             // when
34             const webDavUrlA = 'https://*.collections.example.com/';
35             const webDavUrlB = 'https://*--collections.example.com/';
36             const webDavDownloadUrl = 'https://example.com/';
37
38             // then
39             expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlA))
40                 .toBe('https://zzzzz.collections.example.com/t=v2/a/b/LIMS/1.html');
41             expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlB))
42                 .toBe('https://zzzzz--collections.example.com/t=v2/a/b/LIMS/1.html');
43         });
44
45         it('should keep the url the same when no inline url available', () => {
46             // when
47             const webDavUrl = '';
48             const webDavDownloadUrl = 'https://example.com/';
49             const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
50
51             // then
52             expect(result).toBe('https://example.com/c=zzzzz/t=v2/a/b/LIMS/1.html');
53         });
54
55         it('should replace the url when available', () => {
56             // when
57             const webDavUrl = 'https://download.example.com/';
58             const webDavDownloadUrl = 'https://example.com/';
59             const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl);
60
61             // then
62             expect(result).toBe('https://download.example.com/c=zzzzz/t=v2/a/b/LIMS/1.html');
63         });
64     });
65 });