X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/67d77b206ebee7c776bd4d7dbc112ebb0c7ba800..b61a12ca0d14433ddb10a6d6361a18b1f127c98e:/src/views-components/context-menu/actions/helpers.test.ts diff --git a/src/views-components/context-menu/actions/helpers.test.ts b/src/views-components/context-menu/actions/helpers.test.ts index 9750a1cc..7776d0e5 100644 --- a/src/views-components/context-menu/actions/helpers.test.ts +++ b/src/views-components/context-menu/actions/helpers.test.ts @@ -2,11 +2,12 @@ // // SPDX-License-Identifier: AGPL-3.0 -import { sanitizeToken, getClipboardUrl } from "./helpers"; +import { sanitizeToken, getCollectionItemClipboardUrl, getInlineFileUrl } from "./helpers"; describe('helpers', () => { // given - const url = 'https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/t=v2/arlog-gj3su-stk5unu8570brvs/fryzaq6z1ow1npak5nngldtkoup918isrvlualf134uf1fbtd/LIMS/1.html'; + const url = 'https://example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html'; + const urlWithPdh = 'https://example.com/c=012345678901234567890123456789aa+0/t=v2/a/b/LIMS/1.html'; describe('sanitizeToken', () => { it('should sanitize token from the url', () => { @@ -14,17 +15,56 @@ describe('helpers', () => { const result = sanitizeToken(url); // then - expect(result).toBe('https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/LIMS/1.html?api_token=v2/arlog-gj3su-stk5unu8570brvs/fryzaq6z1ow1npak5nngldtkoup918isrvlualf134uf1fbtd'); + expect(result).toBe('https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html?api_token=v2/a/b'); }); }); describe('getClipboardUrl', () => { it('should add redirectTo query param', () => { // when - const result = getClipboardUrl(url); + const result = getCollectionItemClipboardUrl(url); // then - expect(result).toBe('http://localhost?redirectTo=https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/LIMS/1.html'); + expect(result).toBe('http://localhost?redirectToDownload=https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html'); }); }); -}); \ No newline at end of file + + describe('getInlineFileUrl', () => { + it('should add the collection\'s uuid to the hostname', () => { + // when + const webDavUrlA = 'https://*.collections.example.com/'; + const webDavUrlB = 'https://*--collections.example.com/'; + const webDavDownloadUrl = 'https://example.com/'; + + // then + expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlA)) + .toBe('https://zzzzz-4zz18-0123456789abcde.collections.example.com/t=v2/a/b/LIMS/1.html'); + expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlB)) + .toBe('https://zzzzz-4zz18-0123456789abcde--collections.example.com/t=v2/a/b/LIMS/1.html'); + expect(getInlineFileUrl(urlWithPdh, webDavDownloadUrl, webDavUrlA)) + .toBe('https://012345678901234567890123456789aa-0.collections.example.com/t=v2/a/b/LIMS/1.html'); + expect(getInlineFileUrl(urlWithPdh, webDavDownloadUrl, webDavUrlB)) + .toBe('https://012345678901234567890123456789aa-0--collections.example.com/t=v2/a/b/LIMS/1.html'); + }); + + it('should keep the url the same when no inline url available', () => { + // when + const webDavUrl = ''; + const webDavDownloadUrl = 'https://example.com/'; + const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl); + + // then + expect(result).toBe('https://example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html'); + }); + + it('should replace the url when available', () => { + // when + const webDavUrl = 'https://download.example.com/'; + const webDavDownloadUrl = 'https://example.com/'; + const result = getInlineFileUrl(url, webDavDownloadUrl, webDavUrl); + + // then + expect(result).toBe('https://download.example.com/c=zzzzz-4zz18-0123456789abcde/t=v2/a/b/LIMS/1.html'); + }); + }); +});