Skip to content

Commit

Permalink
Merge pull request #513 from PaulHax/relative-uri-manifests
Browse files Browse the repository at this point in the history
fix(remotemanifest): support relative URIs without names
  • Loading branch information
floryst authored Nov 22, 2023
2 parents ee36234 + 9c0635d commit 0b21084
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/io/import/processors/remoteManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
45 changes: 37 additions & 8 deletions tests/specs/remote-manifest.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 0b21084

Please sign in to comment.