Skip to content

Commit

Permalink
Merge pull request #183 from NFDI4Chem/error-action-test
Browse files Browse the repository at this point in the history
test: error event
  • Loading branch information
CS76 authored Jan 4, 2024
2 parents 6b6a1f3 + 0cd1881 commit 39f2ab0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Binary file added public/data/sample-with-error.zip
Binary file not shown.
16 changes: 16 additions & 0 deletions src/demo/NMRiumWrapperDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default function NMRiumWrapperDemo() {
Test Load URL without extension
</Button.Done>
<Button.Done
style={{ marginRight: '10px' }}
onClick={() => {
void loadFilesFromURLs([
'../data/COSY-12.zip',
Expand All @@ -87,6 +88,21 @@ export default function NMRiumWrapperDemo() {
>
Test Load Files
</Button.Done>
<Button.Done
className="logger-btn"
onClick={() => {
void loadFilesFromURLs(['../data/sample-with-error.zip']).then(
(files) => {
events.trigger('load', {
data: files,
type: 'file',
});
},
);
}}
>
Test Logger
</Button.Done>
</div>

<NMRiumWrapper />
Expand Down
35 changes: 35 additions & 0 deletions test-e2e/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,38 @@ test('should load NMRium from URL without .zip extension in the path', async ({
// if loaded successfully, there should be a 1H
await expect(nmrium.page.locator('.tab-list-item >> text=1H')).toBeVisible();
});



test("Should trigger error action and load the other one that parses successfully", async ({
page,
}) => {
const nmrium = await NmriumWrapperPage.create(page);



const hasError = await nmrium.page.evaluate(() => {
const button = document.querySelector(".logger-btn") as HTMLButtonElement;
// Add a listener for the 'message' event
return new Promise((resolve) => {
window.addEventListener('message', (event) => {
if (event.data.type === "nmr-wrapper:error") {
resolve(true)
}
})
button.click();

}
);

});

// the error event is triggered
expect(hasError).toBeTruthy();

// load a 1H spectrum successfully
await expect(nmrium.page.locator('.tab-list-item >> text=1H')).toBeVisible();
// load a 13C spectrum successfully
await expect(nmrium.page.locator('.tab-list-item >> text=13C')).toBeVisible();

});

0 comments on commit 39f2ab0

Please sign in to comment.