diff --git a/src/__mocks__/@grafana/ui.tsx b/src/__mocks__/@grafana/ui.tsx index a9e1276..c14b4d2 100644 --- a/src/__mocks__/@grafana/ui.tsx +++ b/src/__mocks__/@grafana/ui.tsx @@ -12,7 +12,8 @@ const Select = jest.fn(({ options, onChange, value, isMulti, isClearable, ...res if (isMulti) { onChange(options.filter((option: any) => event.target.values.includes(option.value))); } else { - onChange(options.find((option: any) => option.value === event.target.value)); + const option = options.find((option: any) => option.value === event.target.value); + option && onChange(option); } } }} diff --git a/src/components/DatasetEditor/DatasetEditor.test.tsx b/src/components/DatasetEditor/DatasetEditor.test.tsx index f53ffbe..b65190d 100644 --- a/src/components/DatasetEditor/DatasetEditor.test.tsx +++ b/src/components/DatasetEditor/DatasetEditor.test.tsx @@ -159,6 +159,30 @@ describe('Dataset Editor', () => { expect(selectors.item(true, 'A:Value')).not.toBeInTheDocument(); }); + it('Should not allow selecting already selected fields', () => { + const { value, onChange } = createOnChangeHandler([{ name: 'Time', source: 'A' }]); + + /** + * Render + */ + render( + getComponent({ + value, + onChange, + }) + ); + + const newItemNameInput = selectors.newItemName(); + + /** + * Simulate select option doesn't exist + */ + + fireEvent.change(newItemNameInput, { target: { value: 'A:Time' } }); + + expect(selectors.buttonAddNew()).toBeDisabled(); + }); + /** * Items order */