Skip to content

Commit 39f2ab0

Browse files
authored
Merge pull request #183 from NFDI4Chem/error-action-test
test: error event
2 parents 6b6a1f3 + 0cd1881 commit 39f2ab0

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

public/data/sample-with-error.zip

12.8 MB
Binary file not shown.

src/demo/NMRiumWrapperDemo.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default function NMRiumWrapperDemo() {
7272
Test Load URL without extension
7373
</Button.Done>
7474
<Button.Done
75+
style={{ marginRight: '10px' }}
7576
onClick={() => {
7677
void loadFilesFromURLs([
7778
'../data/COSY-12.zip',
@@ -87,6 +88,21 @@ export default function NMRiumWrapperDemo() {
8788
>
8889
Test Load Files
8990
</Button.Done>
91+
<Button.Done
92+
className="logger-btn"
93+
onClick={() => {
94+
void loadFilesFromURLs(['../data/sample-with-error.zip']).then(
95+
(files) => {
96+
events.trigger('load', {
97+
data: files,
98+
type: 'file',
99+
});
100+
},
101+
);
102+
}}
103+
>
104+
Test Logger
105+
</Button.Done>
90106
</div>
91107

92108
<NMRiumWrapper />

test-e2e/core.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,38 @@ test('should load NMRium from URL without .zip extension in the path', async ({
8080
// if loaded successfully, there should be a 1H
8181
await expect(nmrium.page.locator('.tab-list-item >> text=1H')).toBeVisible();
8282
});
83+
84+
85+
86+
test("Should trigger error action and load the other one that parses successfully", async ({
87+
page,
88+
}) => {
89+
const nmrium = await NmriumWrapperPage.create(page);
90+
91+
92+
93+
const hasError = await nmrium.page.evaluate(() => {
94+
const button = document.querySelector(".logger-btn") as HTMLButtonElement;
95+
// Add a listener for the 'message' event
96+
return new Promise((resolve) => {
97+
window.addEventListener('message', (event) => {
98+
if (event.data.type === "nmr-wrapper:error") {
99+
resolve(true)
100+
}
101+
})
102+
button.click();
103+
104+
}
105+
);
106+
107+
});
108+
109+
// the error event is triggered
110+
expect(hasError).toBeTruthy();
111+
112+
// load a 1H spectrum successfully
113+
await expect(nmrium.page.locator('.tab-list-item >> text=1H')).toBeVisible();
114+
// load a 13C spectrum successfully
115+
await expect(nmrium.page.locator('.tab-list-item >> text=13C')).toBeVisible();
116+
117+
});

0 commit comments

Comments
 (0)