diff --git a/src/components/inputs/ui-select-extended/ui-select-extended.test.tsx b/src/components/inputs/ui-select-extended/ui-select-extended.test.tsx index 9374b4c18..8ee9a809b 100644 --- a/src/components/inputs/ui-select-extended/ui-select-extended.test.tsx +++ b/src/components/inputs/ui-select-extended/ui-select-extended.test.tsx @@ -14,6 +14,9 @@ const question: OHRIFormField = { concept: '160540AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', datasource: { name: 'location_datasource', + config: { + tag: 'test-tag', + }, }, }, value: null, @@ -162,4 +165,27 @@ describe('UISelectExtended Component', () => { expect(screen.queryByText('Muyenga')).not.toBeInTheDocument(); }); }); + it('Should set the correct value for the config parameter', async () => { + // Mock the data source fetch behavior + const expectedConfigValue = { + tag: 'test-tag', + }; + + // Mock the getRegisteredDataSource function + jest.mock('../../../registry/registry', () => ({ + getRegisteredDataSource: jest.fn().mockResolvedValue({ + fetchData: jest.fn().mockResolvedValue([]), + toUuidAndDisplay: (data) => data, + config: expectedConfigValue, + }), + })); + + await act(async () => { + await renderForm({}); + }); + const config = question.questionOptions.datasource.config; + + // Assert that the config is set with the expected configuration value + expect(config).toEqual(expectedConfigValue); + }); }); diff --git a/src/components/inputs/ui-select-extended/ui-select-extended.tsx b/src/components/inputs/ui-select-extended/ui-select-extended.tsx index 41aa3ceb2..07bdf39e7 100644 --- a/src/components/inputs/ui-select-extended/ui-select-extended.tsx +++ b/src/components/inputs/ui-select-extended/ui-select-extended.tsx @@ -38,7 +38,7 @@ const UISelectExtended: React.FC = ({ question, handler, onC ? question.questionOptions.datasource?.config : getControlTemplate(question.questionOptions.rendering)?.datasource?.config, ); - getRegisteredDataSource(datasourceName ? datasourceName : question.questionOptions.rendering).then(ds => + getRegisteredDataSource(datasourceName ? datasourceName : question.questionOptions.rendering).then((ds) => setDataSource(ds), ); }, [question.questionOptions?.datasource]); @@ -50,7 +50,7 @@ const UISelectExtended: React.FC = ({ question, handler, onC } }, [question['submission']]); - const handleChange = value => { + const handleChange = (value) => { setFieldValue(question.id, value); onChange(question.id, value, setErrors, setWarnings); question.value = handler?.handleFieldSubmission(question, value, encounterContext); @@ -58,7 +58,7 @@ const UISelectExtended: React.FC = ({ question, handler, onC const debouncedSearch = debounce((searchterm, dataSource) => { setIsLoading(true); - dataSource.fetchData(searchterm, config).then(dataItems => { + dataSource.fetchData(searchterm, config).then((dataItems) => { setItems(dataItems.map(dataSource.toUuidAndDisplay)); setIsLoading(false); }); @@ -68,21 +68,21 @@ const UISelectExtended: React.FC = ({ question, handler, onC // If not searchable, preload the items if (dataSource && !isTrue(question.questionOptions.isSearchable)) { setIsLoading(true); - dataSource.fetchData(null, config).then(dataItems => { + dataSource.fetchData(null, config).then((dataItems) => { setItems(dataItems.map(dataSource.toUuidAndDisplay)); setIsLoading(false); }); } - }, [dataSource]); + }, [dataSource, config]); useEffect(() => { if (dataSource && isTrue(question.questionOptions.isSearchable) && !isEmpty(searchTerm)) { debouncedSearch(searchTerm, dataSource); } - }, [dataSource, searchTerm]); + }, [dataSource, searchTerm, config]); useEffect(() => { - getConceptNameAndUUID(question.questionOptions.concept).then(conceptTooltip => { + getConceptNameAndUUID(question.questionOptions.concept).then((conceptTooltip) => { setConceptName(conceptTooltip); }); }, [conceptName]); @@ -102,7 +102,7 @@ const UISelectExtended: React.FC = ({ question, handler, onC label={question.label} value={ field.value - ? handler?.getDisplayValue(question, items.find(item => item.uuid == field.value)?.display) + ? handler?.getDisplayValue(question, items.find((item) => item.uuid == field.value)?.display) : field.value } conceptName={conceptName} @@ -123,8 +123,8 @@ const UISelectExtended: React.FC = ({ question, handler, onC id={question.id} titleText={question.label} items={items} - itemToString={item => item?.display} - selectedItem={items.find(item => item.uuid == field.value)} + itemToString={(item) => item?.display} + selectedItem={items.find((item) => item.uuid == field.value)} shouldFilterItem={({ item, inputValue }) => { if (!inputValue) { // Carbon's initial call at component mount @@ -138,7 +138,7 @@ const UISelectExtended: React.FC = ({ question, handler, onC }} disabled={question.disabled} readOnly={question.readonly} - onInputChange={value => { + onInputChange={(value) => { if (isProcessingSelection.current) { // Notes: // When the user selects a value, both the onChange and onInputChange functions are invoked sequentially. @@ -157,7 +157,7 @@ const UISelectExtended: React.FC = ({ question, handler, onC
item.uuid == previousValueForReview.value)?.display} + displayText={items.find((item) => item.uuid == previousValueForReview.value)?.display} setValue={handleChange} />