-
Notifications
You must be signed in to change notification settings - Fork 947
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for create data source picker handler
Signed-off-by: Huy Nguyen <[email protected]>
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...pe_timeseries/public/application/components/lib/create_data_source_change_handler.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
}); | ||
}); |