From e4f36191c4d265a119f904df263724b63304dadc Mon Sep 17 00:00:00 2001 From: TanyaGashtold <61136841+TanyaGashtold@users.noreply.github.com> Date: Tue, 5 Nov 2024 01:08:00 +0300 Subject: [PATCH] FIO-9290: fixed an issue where infinite loader is shown when radio/selectboxes with url type is failed to load options (#5891) --- src/components/radio/Radio.js | 7 ++++--- test/unit/Radio.unit.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/components/radio/Radio.js b/src/components/radio/Radio.js index 636970b9e2..eaed8451d3 100644 --- a/src/components/radio/Radio.js +++ b/src/components/radio/Radio.js @@ -365,12 +365,13 @@ export default class RadioComponent extends ListComponent { .then((response) => { this.loading = false; this.setItems(response); - this.optionsLoaded = true; - this.redraw(); }) .catch((err) => { - this.optionsLoaded = true; this.handleLoadingError(err); + }) + .finally(() => { + this.optionsLoaded = true; + this.redraw(); }); } diff --git a/test/unit/Radio.unit.js b/test/unit/Radio.unit.js index bd12027bc8..a4fd032280 100644 --- a/test/unit/Radio.unit.js +++ b/test/unit/Radio.unit.js @@ -322,6 +322,27 @@ describe('Radio Component', () => { done(); }).catch(done); }); + + it('Should not show infinite loader for radio with URL data source if options loading failed', (done) => { + const form = _.cloneDeep(comp9); + const element = document.createElement('div'); + const originalMakeRequest = Formio.makeRequest; + + Formio.makeRequest = function() { + return new Promise((res, rej) => { + setTimeout(() => rej('loading error'), 200); + }); + }; + Formio.createForm(element, form).then(form => { + const radio = form.getComponent('radio'); + assert.equal(!!radio.element.querySelector('.loader'), true, 'Should show loader.') + setTimeout(()=>{ + assert.equal(!!radio.element.querySelector('.loader'), false, 'Should not show loader.') + Formio.makeRequest = originalMakeRequest; + done(); + }, 350); + }).catch(done); + }); }); describe('Radio Component', () => {