From 9c0635d394ea68318f4a5e20831b0a8455c1212f Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 21 Nov 2023 19:25:25 -0500 Subject: [PATCH] fix(remotemanifest): support relative URIs without names new URL('/foo') would error without base argument --- src/io/import/processors/remoteManifest.ts | 2 +- tests/specs/remote-manifest.e2e.ts | 45 ++++++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/io/import/processors/remoteManifest.ts b/src/io/import/processors/remoteManifest.ts index 7b5a80ae7..9e85f3a1b 100644 --- a/src/io/import/processors/remoteManifest.ts +++ b/src/io/import/processors/remoteManifest.ts @@ -20,7 +20,7 @@ const handleRemoteManifest: ImportHandler = async ( remotes.push({ uriSrc: { uri: res.url, - name: res.name ?? new URL(res.url).pathname, + name: res.name ?? new URL(res.url, window.location.origin).pathname, }, parent: dataSource, }); diff --git a/tests/specs/remote-manifest.e2e.ts b/tests/specs/remote-manifest.e2e.ts index feab572cf..c167cec0f 100644 --- a/tests/specs/remote-manifest.e2e.ts +++ b/tests/specs/remote-manifest.e2e.ts @@ -4,21 +4,50 @@ import { cleanuptotal } from 'wdio-cleanuptotal-service'; import { TEMP_DIR } from '../../wdio.shared.conf'; import { volViewPage } from '../pageobjects/volview.page'; +async function writeManifestToFile(manifest: any, fileName: string) { + const filePath = path.join(TEMP_DIR, fileName); + await fs.promises.writeFile(filePath, JSON.stringify(manifest)); + cleanuptotal.addCleanup(async () => { + fs.unlinkSync(filePath); + }); + return filePath; +} + +async function openVolViewPage(fileName: string) { + const urlParams = `?urls=[tmp/${fileName}]`; + await volViewPage.open(urlParams); +} + describe('VolView loading of remoteManifest.json', () => { it('should show error when there is no name and URL is malformed', async () => { const manifest = { resources: [{ url: 'foo' }], }; - // write object as json to file const fileName = 'remoteFilesBadUrl.json'; - const filePath = path.join(TEMP_DIR, fileName); - await fs.promises.writeFile(filePath, JSON.stringify(manifest)); - cleanuptotal.addCleanup(async () => { - fs.unlinkSync(filePath); - }); + await writeManifestToFile(manifest, fileName); + await openVolViewPage(fileName); - const urlParams = `?urls=[tmp/${fileName}]`; - await volViewPage.open(urlParams); await volViewPage.waitForNotification(); }); + + it('should load relative URI with no name property', async () => { + const dicom = '1-001.dcm'; + const dicomPath = path.join(TEMP_DIR, dicom); + if (!fs.existsSync(dicomPath)) { + const response = await fetch( + 'https://data.kitware.com/api/v1/file/655d42a694ef39bf0a4a8bb3/download' + ); + const data = await response.arrayBuffer(); + const buffer = Buffer.from(data); + fs.writeFileSync(dicomPath, buffer); + } + + const manifest = { + resources: [{ url: `/tmp/${dicom}` }], + }; + const fileName = 'remoteFilesRelativeURI.json'; + await writeManifestToFile(manifest, fileName); + await openVolViewPage(fileName); + await volViewPage.waitForViews(); + }); });