Merge branch '17109-keepweb-webdav-urls'
[arvados-workbench2.git] / src / views-components / context-menu / actions / helpers.test.ts
index 4234a8cc3a5ea594ef62f760a505dd5fab3255b8..c3a31691383764aaa5f33d47828bc72d4a961626 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { sanitizeToken, getClipboardUrl } from "./helpers";
+import { sanitizeToken, getClipboardUrl, getInlineFileUrl } from "./helpers";
 
 describe('helpers', () => {
     // given
@@ -27,4 +27,39 @@ describe('helpers', () => {
             expect(result).toBe('http://localhost?redirectTo=https://example.com/c=zzzzz/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.collections.example.com/t=v2/a/b/LIMS/1.html');
+            expect(getInlineFileUrl(url, webDavDownloadUrl, webDavUrlB))
+                .toBe('https://zzzzz--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/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/t=v2/a/b/LIMS/1.html');
+        });
+    });
 });
\ No newline at end of file