-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Lens] test suite - replace React specific props events with html events #113156
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,9 @@ | |
* 2.0. | ||
*/ | ||
|
||
import React, { ChangeEvent, ReactElement } from 'react'; | ||
import React from 'react'; | ||
import { waitFor } from '@testing-library/react'; | ||
import ReactDOM from 'react-dom'; | ||
import { createMockedDragDropContext } from './mocks'; | ||
import { dataPluginMock } from '../../../../../src/plugins/data/public/mocks'; | ||
import { InnerIndexPatternDataPanel, IndexPatternDataPanel, MemoizedDataPanel } from './datapanel'; | ||
|
@@ -240,6 +242,9 @@ const initialState: IndexPatternPrivateState = { | |
|
||
const dslQuery = { bool: { must: [], filter: [], should: [], must_not: [] } }; | ||
|
||
// @ts-expect-error Portal mocks are notoriously difficult to type | ||
ReactDOM.createPortal = jest.fn((element) => element); | ||
|
||
describe('IndexPattern Data Panel', () => { | ||
let defaultProps: Parameters<typeof InnerIndexPatternDataPanel>[0] & { | ||
showNoDataPopover: () => void; | ||
|
@@ -752,14 +757,13 @@ describe('IndexPattern Data Panel', () => { | |
it('should filter down by name', () => { | ||
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />); | ||
act(() => { | ||
wrapper.find('[data-test-subj="lnsIndexPatternFieldSearch"]').prop('onChange')!({ | ||
wrapper.find('[data-test-subj="lnsIndexPatternFieldSearch"]').simulate('change', { | ||
target: { value: 'me' }, | ||
} as ChangeEvent<HTMLInputElement>); | ||
}); | ||
}); | ||
|
||
wrapper | ||
.find('[data-test-subj="lnsIndexPatternEmptyFields"]') | ||
.find('button') | ||
.find('[data-test-subj="lnsIndexPatternEmptyFields"] button') | ||
.first() | ||
.simulate('click'); | ||
|
||
|
@@ -772,9 +776,9 @@ describe('IndexPattern Data Panel', () => { | |
it('should announce filter in live region', () => { | ||
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />); | ||
act(() => { | ||
wrapper.find('[data-test-subj="lnsIndexPatternFieldSearch"]').prop('onChange')!({ | ||
wrapper.find('[data-test-subj="lnsIndexPatternFieldSearch"]').simulate('change', { | ||
target: { value: 'me' }, | ||
} as ChangeEvent<HTMLInputElement>); | ||
}); | ||
}); | ||
|
||
wrapper | ||
|
@@ -832,9 +836,9 @@ describe('IndexPattern Data Panel', () => { | |
it('should filter down by type and by name', () => { | ||
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />); | ||
act(() => { | ||
wrapper.find('[data-test-subj="lnsIndexPatternFieldSearch"]').prop('onChange')!({ | ||
wrapper.find('[data-test-subj="lnsIndexPatternFieldSearch"]').simulate('change', { | ||
target: { value: 'me' }, | ||
} as ChangeEvent<HTMLInputElement>); | ||
}); | ||
}); | ||
|
||
wrapper.find('[data-test-subj="lnsIndexPatternFiltersToggle"]').first().simulate('click'); | ||
|
@@ -856,24 +860,26 @@ describe('IndexPattern Data Panel', () => { | |
); | ||
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />); | ||
act(() => { | ||
( | ||
wrapper | ||
.find('[data-test-subj="lnsIndexPatternActions-popover"]') | ||
.first() | ||
.prop('children') as ReactElement | ||
).props.items[0].props.onClick(); | ||
const popoverTrigger = wrapper.find( | ||
'[data-test-subj="lnsIndexPatternActions-popover"] button' | ||
); | ||
popoverTrigger.simulate('click'); | ||
}); | ||
|
||
wrapper.update(); | ||
act(() => { | ||
wrapper.find('[data-test-subj="indexPattern-add-field"]').first().simulate('click'); | ||
}); | ||
// wait for indx pattern to be loaded | ||
await act(async () => await new Promise((r) => setTimeout(r, 0))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit on the edge of replacing this with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The behaviour is different between the 2 things. |
||
|
||
expect(props.indexPatternFieldEditor.openEditor).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
ctx: expect.objectContaining({ | ||
indexPattern: mockIndexPattern, | ||
}), | ||
}) | ||
); | ||
await waitFor(() => { | ||
expect(props.indexPatternFieldEditor.openEditor).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
ctx: expect.objectContaining({ | ||
indexPattern: mockIndexPattern, | ||
}), | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
it('should reload index pattern if callback gets called', async () => { | ||
|
@@ -891,14 +897,19 @@ describe('IndexPattern Data Panel', () => { | |
Promise.resolve(mockIndexPattern) | ||
); | ||
const wrapper = mountWithIntl(<InnerIndexPatternDataPanel {...props} />); | ||
|
||
act(() => { | ||
( | ||
wrapper | ||
.find('[data-test-subj="lnsIndexPatternActions-popover"]') | ||
.first() | ||
.prop('children') as ReactElement | ||
).props.items[0].props.onClick(); | ||
const popoverTrigger = wrapper.find( | ||
'[data-test-subj="lnsIndexPatternActions-popover"] button' | ||
); | ||
popoverTrigger.simulate('click'); | ||
}); | ||
|
||
wrapper.update(); | ||
act(() => { | ||
wrapper.find('[data-test-subj="indexPattern-add-field"]').first().simulate('click'); | ||
}); | ||
|
||
// wait for indx pattern to be loaded | ||
await act(async () => await new Promise((r) => setTimeout(r, 0))); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks to mocking the portal:
ReactDOM.createPortal = jest.fn((element) => element)
we can just assume that the content of the popover will be placed directly inside the popover. And thanks to that we can avoid the ugly lines above.