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

fix: Enhance fetch mocks and option mappings for select components

Summary of changes
- Updated fetch mocks in select and tree-select tests to include response status and an 'ok' property for better simulation of real fetch behavior.
- Removed redundant afterEach cleanup in the select test, as it's no longer necessary with the current setup.
- Adjusted timeout duration for the fetch test in the select component to be more appropriate, reducing from 10000ms to 5000ms.
- Changed option mapping templates in both select and tree-select tests to use '${id}' instead of '${name}' and '${alpha-2}' to align with the expected data structure.
parent 556b6d63
No related branches found
No related tags found
No related merge requests found
......@@ -58,19 +58,22 @@ describe('Select', function () {
describe('With fetch', function () {
beforeEach(() => {
beforeEach((done) => {
let mocks = document.getElementById('mocks');
mocks.innerHTML = html1;
global['fetch'] = function (url, options) {
let headers = new Map;
headers.set('content-type', 'application/json');
return new Promise((resolve, reject) => {
resolve({
ok:true,
status:200,
headers: headers,
text: function () {
return new Promise((resolve2, reject2) => {
let json = JSON.parse(`[
......@@ -110,7 +113,7 @@ describe('Select', function () {
})
};
done()
})
......@@ -126,12 +129,6 @@ describe('Select', function () {
mocks.innerHTML = html2;
});
afterEach(() => {
let mocks = document.getElementById('mocks');
mocks.innerHTML = "";
global['fetch'] = fetchReference;
})
describe('create from template', function () {
it('should contains monster-select', function () {
expect(document.getElementById('test2')).contain.html('<monster-select');
......@@ -148,14 +145,14 @@ describe('Select', function () {
it('should have options', function (done) {
this.timeout(10000)
this.timeout(5000)
let mocks = document.getElementById('mocks');
const select = document.createElement('monster-select');
select.setOption('url', 'https://monsterjs.org/assets/examples/countries.json')
select.setOption('url', 'https://monsterjs.org/assets/examples/countries.json') // url is not used in this test, see fetch mock
select.setOption('mapping.selector', '*')
select.setOption('mapping.labelTemplate', '${name}')
select.setOption('mapping.valueTemplate', '${alpha-2}')
select.setOption('mapping.labelTemplate', '${id}')
select.setOption('mapping.valueTemplate', '${id}')
select.addEventListener('monster-options-set', (e) => {
setTimeout(() => {
......
......@@ -63,6 +63,8 @@ describe('Treeselect', function () {
return new Promise((resolve, reject) => {
resolve({
headers: headers,
ok:true,
status:200,
text: function () {
return new Promise((resolve2, reject2) => {
......@@ -141,8 +143,8 @@ describe('Treeselect', function () {
treeselect.setOption('url', 'https://monsterjs.org/assets/examples/countries.json');
treeselect.setOption('mapping.selector', '*');
treeselect.setOption('mapping.labelTemplate', '${name}')
treeselect.setOption('mapping.valueTemplate', '${alpha-2}')
treeselect.setOption('mapping.labelTemplate', '${id}')
treeselect.setOption('mapping.valueTemplate', '${id}')
treeselect.addEventListener('monster-options-set', (e) => {
setTimeout(() => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment