Skip to content

Commit

Permalink
Add test for create data source picker handler
Browse files Browse the repository at this point in the history
Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
  • Loading branch information
huyaboo committed Apr 16, 2024
1 parent 76ed1a4 commit fe2b794
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { createDataSourcePickerHandler } from './create_data_source_change_handler';

describe('createDataSourcePickerHandler()', () => {
let handleChange: jest.Mock<any, any>;
let changeHandler: (selectedOptions: []) => void;

beforeEach(() => {
handleChange = jest.fn();
changeHandler = createDataSourcePickerHandler(handleChange);
});

test.each([
{
id: undefined,
},
{},
])(
'calls handleChange() and sets data_source_id to undefined if id cannot be found or is undefined',
({ id }) => {
// @ts-ignore
changeHandler([{ id }]);
expect(handleChange.mock.calls.length).toEqual(1);
expect(handleChange.mock.calls[0][0]).toEqual({
data_source_id: undefined,
});
}
);

test.each([
{
id: '',
},
{
id: 'foo',
},
])('calls handleChange() function with partial and updates the data_source_id', ({ id }) => {
// @ts-ignore
changeHandler([{ id }]);
expect(handleChange.mock.calls.length).toEqual(1);
expect(handleChange.mock.calls[0][0]).toEqual({
data_source_id: id,
});
});
});

0 comments on commit fe2b794

Please sign in to comment.