X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f15181b0b69599cc33385d4af2f1a60de087882b..c0309f65edc9e6ed92e13d4d83afaa8b043c56b0:/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 6aaacc2fc6..b2cb4a5500 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, getClipboardUrl, getInlineFileUrl } from "./helpers"; describe('helpers', () => { // given - const url = 'https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/t=1ha4ykd3w14ed19b2gh3uyjrjup38vsx27x1utwdne0bxcfg5d/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,7 +15,7 @@ describe('helpers', () => { const result = sanitizeToken(url); // then - expect(result).toBe('https://collections.ardev.roche.com/c=ardev-4zz18-k0hamvtwyit6q56/LIMS/1.html?api_token=1ha4ykd3w14ed19b2gh3uyjrjup38vsx27x1utwdne0bxcfg5d'); + expect(result).toBe('https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html?api_token=v2/a/b'); }); }); @@ -24,7 +25,46 @@ describe('helpers', () => { const result = getClipboardUrl(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?redirectTo=https://example.com/c=zzzzz-4zz18-0123456789abcde/LIMS/1.html'); + }); + }); + + 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'); }); }); }); \ No newline at end of file