Skip to content

Commit

Permalink
fix - add test to Select
Browse files Browse the repository at this point in the history
  • Loading branch information
vitPinchuk committed Feb 8, 2024
1 parent a469826 commit 0324b72
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/__mocks__/@grafana/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}}
Expand Down
24 changes: 24 additions & 0 deletions src/components/DatasetEditor/DatasetEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 0324b72

Please sign in to comment.