Skip to content

Commit 84bb1e8

Browse files
authored
Merge pull request #93 from NFDI4Chem/development
fix: load URLs that do not include an extension
2 parents 635a2a3 + 3e032e9 commit 84bb1e8

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/allowed-origins.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@
1616
"https://chemotion-01.zdv.uni-mainz.de",
1717
"https://chemotion.biblio.etc.tu-bs.de"
1818
]
19-

src/demo/NMRiumWrapperDemo.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ export default function NMRiumWrapperDemo() {
5555
>
5656
Test Load from URLS
5757
</Button.Done>
58+
59+
<Button.Done
60+
style={{ marginRight: '10px' }}
61+
onClick={() => {
62+
events.trigger('load', {
63+
data: [
64+
'https://cheminfo.github.io/bruker-data-test/data/zipped/aspirin-1h',
65+
],
66+
type: 'url',
67+
});
68+
}}
69+
>
70+
Test Load URL without extension
71+
</Button.Done>
5872
<Button.Done
5973
onClick={async () => {
6074
const files = await loadFilesFromURLs(['../data/13c.zip']);

src/hooks/useLoadSpectra.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ async function loadSpectraFromFiles(files: File[]) {
2323
async function loadSpectraFromURLs(urls: string[]) {
2424
const entries = urls.map((url) => {
2525
const refURL = new URL(url);
26-
let name = getFileNameFromURL(url);
26+
const name = getFileNameFromURL(url);
27+
let path = refURL.pathname;
2728
const hasExtension = name && name.indexOf('.') !== -1;
2829
if (!hasExtension) {
29-
name = `${name}.zip`;
30+
path = `${path}.zip`;
3031
}
31-
return { relativePath: refURL.pathname, baseURL: refURL.origin };
32+
return { relativePath: path, baseURL: refURL.origin };
3233
}, []);
3334

3435
const { data } = await readFromWebSource({ entries });

test-e2e/core.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,13 @@ test('should load NMRium from json', async ({ page }) => {
6464
// if loaded successfully, there should be a 1H and 13C tabs
6565
await expect(nmrium.page.locator('.tab-list-item >> text=13C')).toBeVisible();
6666
});
67+
test('should load NMRium from URL without .zip extension in the path', async ({
68+
page,
69+
}) => {
70+
const nmrium = await NmriumWrapperPage.create(page);
71+
72+
await nmrium.page.click('text=Test Load URL without extension');
73+
74+
// if loaded successfully, there should be a 1H
75+
await expect(nmrium.page.locator('.tab-list-item >> text=1H')).toBeVisible();
76+
});

0 commit comments

Comments
 (0)