Skip to content
Snippets Groups Projects
Verified Commit 722979b1 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: Improve HTTP response handling and update test data sources

Summary of changes

- Modified the fetchData function to check for successful HTTP response status codes (200-299) instead of relying on the "ok" property. This change enhances error handling by providing more granular status checks, making the code more robust against unexpected responses.
- Updated the test cases for both the "Select" and "Treeselect" components to use a consistent and valid URL for country data. The mappings for label and value templates were also updated for better clarity and accuracy, aligning the tests with expected response formats.
- Adjusted the timeout for the "Select" test to ensure it has enough time for asynchronous operations that may occur during the fetching of options.
- Ensured that the "done" callback in the "Treeselect" test is only called when an exception is caught, preventing unnecessary multiple calls to "done", which could lead to confusing test results.
parent 6a504232
No related branches found
No related tags found
No related merge requests found
......@@ -2454,7 +2454,7 @@ function fetchData(url) {
self[isLoadingSymbol] = false;
delayWatch = true;
if (!response.ok) {
if (response.status >= 200 && response.status < 300) {
throw new Error(`HTTP error! status: ${response.status}`);
}
......
......@@ -148,12 +148,14 @@ describe('Select', function () {
it('should have options', function (done) {
this.timeout(10000)
let mocks = document.getElementById('mocks');
const select = document.createElement('monster-select');
select.setOption('url', 'https://example.com')
select.setOption('url', 'https://monsterjs.org/assets/examples/countries.json')
select.setOption('mapping.selector', '*')
select.setOption('mapping.labelTemplate', '${id}')
select.setOption('mapping.valueTemplate', '${id}')
select.setOption('mapping.labelTemplate', '${name}')
select.setOption('mapping.valueTemplate', '${alpha-2}')
select.addEventListener('monster-options-set', (e) => {
setTimeout(() => {
......
......@@ -138,12 +138,11 @@ describe('Treeselect', function () {
let mocks = document.getElementById('mocks');
const treeselect = document.createElement('monster-tree-select');
treeselect.setOption('url', 'https://example.com')
treeselect.setOption('url', 'https://monsterjs.org/assets/examples/countries.json');
treeselect.setOption('mapping.selector', '*');
treeselect.setOption('mapping.labelTemplate', '${last_name}');
treeselect.setOption('mapping.valueTemplate', '${id | tostring }');
treeselect.setOption('mapping.labelTemplate', '${name}')
treeselect.setOption('mapping.valueTemplate', '${alpha-2}')
treeselect.addEventListener('monster-options-set', (e) => {
setTimeout(() => {
......@@ -159,13 +158,13 @@ describe('Treeselect', function () {
expect(optionHtml).contain.html('data-monster-insert-reference="options-1"');
expect(optionHtml).contain.html('data-monster-insert-reference="options-2"');
expect(optionHtml).contain.not.html('data-monster-insert-reference="options-3"');
done();
} catch (e) {
done(e)
return;
}
done();
}, 100)
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment