-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUG] Check for duplicate data source id before fetching the data sou…
…rces in index pattern selector (#6498) (#6508) * remove duplicate entries * add test --------- (cherry picked from commit d2d410b) Signed-off-by: Lu Yu <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
bd35609
commit 5b048ba
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/plugins/data/public/ui/index_pattern_select/index_pattern_select.test.tsx
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,56 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
import { SavedObjectsClientContract } from '../../../../../core/public'; | ||
import React from 'react'; | ||
import IndexPatternSelect from './index_pattern_select'; | ||
|
||
describe('IndexPatternSelect', () => { | ||
let client: SavedObjectsClientContract; | ||
const bulkGetMock = jest.fn(); | ||
|
||
const nextTick = () => new Promise((res) => process.nextTick(res)); | ||
|
||
beforeEach(() => { | ||
client = { | ||
find: jest.fn().mockResolvedValue({ | ||
savedObjects: [ | ||
{ | ||
references: [{ id: 'testDataSourceId', type: 'data-source' }], | ||
attributes: { title: 'testTitle1' }, | ||
}, | ||
{ | ||
references: [{ id: 'testDataSourceId', type: 'data-source' }], | ||
attributes: { title: 'testTitle2' }, | ||
}, | ||
], | ||
}), | ||
bulkGet: bulkGetMock, | ||
get: jest.fn().mockResolvedValue({ | ||
references: [{ id: 'someId', type: 'data-source' }], | ||
attributes: { title: 'testTitle' }, | ||
}), | ||
} as any; | ||
}); | ||
|
||
it('should render index pattern select', async () => { | ||
const onChangeMock = jest.fn(); | ||
const compInstance = shallow( | ||
<IndexPatternSelect | ||
placeholder={'test index pattern'} | ||
indexPatternId={'testId'} | ||
onChange={onChangeMock} | ||
data-test-subj={'testId'} | ||
savedObjectsClient={client} | ||
/> | ||
).instance(); | ||
|
||
bulkGetMock.mockResolvedValue({ savedObjects: [{ attributes: { title: 'test1' } }] }); | ||
compInstance.debouncedFetch(''); | ||
await new Promise((resolve) => setTimeout(resolve, 300)); | ||
await nextTick(); | ||
expect(bulkGetMock).toBeCalledWith([{ id: 'testDataSourceId', type: 'data-source' }]); | ||
}); | ||
}); |
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