[ML] Migrate Enzyme tests to RTL part 2#226205
Conversation
| const wrapper = shallowWithIntl(<AnnotationDescriptionList annotation={mockAnnotations[0]} />); | ||
| expect(wrapper).toMatchSnapshot(); | ||
| const { container } = renderWithI18n( | ||
| <AnnotationDescriptionList annotation={mockAnnotations[0] as unknown as Annotation} /> |
There was a problem hiding this comment.
did you try satisfies Annotation for the mock?
There was a problem hiding this comment.
Can get rid of as unknown but satisfies is not working properly.
95b9635
| }; | ||
|
|
||
| // Mock withKibana HOC | ||
| jest.mock('@kbn/kibana-react-plugin/public', () => { |
There was a problem hiding this comment.
I found several createWithKibanaMock in the codebase. I reckon it'd be convenient to create a reusable helper in kibana_react
| instance.closeFlyout(); | ||
| test6.wrapper.update(); | ||
| expect(test6.wrapper).toMatchSnapshot(); | ||
| test(`don't render when not opened`, () => { |
There was a problem hiding this comment.
do we need to keep tests when it's rendered?
There was a problem hiding this comment.
To test it we'd need to access component instance through ref. It uses function registration pattern rather than accepting props (isOpen)..
I believe it isn't a good way to test it.
example:
const componentRef = React.createRef();
const { container } = render(
<RuleEditorFlyout
{...getRequiredProps()}
ref={componentRef}
/>
);
act(() => {
componentRef.current.showFlyout({
jobId: 'test-job',
detectorIndex: 0,
source: { function: 'mean' }
});
});
| wrapper.find('EuiLink').simulate('click'); | ||
| wrapper.update(); | ||
| expect(addItemToFilterList).toHaveBeenCalled(); | ||
| fireEvent.click(getByRole('button', { name: 'Add elastic.co to safe_domains' })); |
There was a problem hiding this comment.
shall we rely on the test id instead?
| const { container } = renderWithI18n(<DeleteRuleModal {...requiredProps} />); | ||
|
|
||
| // Find and click the delete link | ||
| const deleteLink = screen.getByRole('button', { name: 'Delete rule' }); |
There was a problem hiding this comment.
did you consider using a data-test-subj for the buttons?
| jest.mock('../../../../capabilities/check_capabilities', () => ({ | ||
| usePermissionCheck: () => [true, true], | ||
| })); |
There was a problem hiding this comment.
consider using reusable mock from
| usePermissionCheck: () => [true, true], | ||
| })); | ||
|
|
||
| jest.mock('../../../../contexts/kibana/kibana_context', () => ({ |
There was a problem hiding this comment.
There was a problem hiding this comment.
The mock wasn't actually needed, removed in 82c857c
| const addButton = wrapper.find('EuiButton').first(); | ||
| expect(addButton.prop('disabled')).toBe(true); | ||
| // Find the Add button by its role | ||
| const addButton = getByRole('button', { name: 'Add' }); |
There was a problem hiding this comment.
it's be safer to use test ids
darnautov
left a comment
There was a problem hiding this comment.
LGTM, left some suggestions
💚 Build Succeeded
Metrics [docs]Async chunks
History
cc @rbrtj |
|
Starting backport for target branches: 8.19, 9.1 https://github.com/elastic/kibana/actions/runs/16163097447 |
The previous PR - elastic#225423, targeted only direct imports from `enzyme`. This PR targets all occurrences of helper functions that use Enzyme under the hood. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 293bb28)
💔 Some backports could not be created
Note: Successful backport PRs will be merged automatically after passing CI. Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
The previous PR - elastic#225423, targeted only direct imports from `enzyme`. This PR targets all occurrences of helper functions that use Enzyme under the hood. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 293bb28) # Conflicts: # x-pack/platform/plugins/shared/ml/public/application/settings/settings.test.tsx
# Backport This will backport the following commits from `main` to `9.1`: - [[ML] Migrate `Enzyme` tests to `RTL` part 2 (#226205)](#226205) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Robert Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-07-09T07:28:22Z","message":"[ML] Migrate `Enzyme` tests to `RTL` part 2 (#226205)\n\nThe previous PR - https://github.com/elastic/kibana/pull/225423,\ntargeted only direct imports from `enzyme`. This PR targets all\noccurrences of helper functions that use Enzyme under the hood.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"293bb28818f87bc9793e4ecbf9ecc56cfb00990c","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":[":ml","release_note:skip","Team:ML","backport:version","v9.1.0","v8.19.0","v9.2.0"],"title":"[ML] Migrate `Enzyme` tests to `RTL` part 2","number":226205,"url":"https://github.com/elastic/kibana/pull/226205","mergeCommit":{"message":"[ML] Migrate `Enzyme` tests to `RTL` part 2 (#226205)\n\nThe previous PR - https://github.com/elastic/kibana/pull/225423,\ntargeted only direct imports from `enzyme`. This PR targets all\noccurrences of helper functions that use Enzyme under the hood.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"293bb28818f87bc9793e4ecbf9ecc56cfb00990c"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/226205","number":226205,"mergeCommit":{"message":"[ML] Migrate `Enzyme` tests to `RTL` part 2 (#226205)\n\nThe previous PR - https://github.com/elastic/kibana/pull/225423,\ntargeted only direct imports from `enzyme`. This PR targets all\noccurrences of helper functions that use Enzyme under the hood.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"293bb28818f87bc9793e4ecbf9ecc56cfb00990c"}}]}] BACKPORT--> Co-authored-by: Robert Jaszczurek <92210485+rbrtj@users.noreply.github.com>
# Backport This will backport the following commits from `main` to `8.19`: - [[ML] Migrate `Enzyme` tests to `RTL` part 2 (#226205)](#226205) <!--- Backport version: 10.0.1 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Robert Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-07-09T07:28:22Z","message":"[ML] Migrate `Enzyme` tests to `RTL` part 2 (#226205)\n\nThe previous PR - https://github.com/elastic/kibana/pull/225423,\ntargeted only direct imports from `enzyme`. This PR targets all\noccurrences of helper functions that use Enzyme under the hood.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"293bb28818f87bc9793e4ecbf9ecc56cfb00990c","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":[":ml","release_note:skip","Team:ML","backport:version","v9.1.0","v8.19.0","v9.2.0"],"title":"[ML] Migrate `Enzyme` tests to `RTL` part 2","number":226205,"url":"https://github.com/elastic/kibana/pull/226205","mergeCommit":{"message":"[ML] Migrate `Enzyme` tests to `RTL` part 2 (#226205)\n\nThe previous PR - https://github.com/elastic/kibana/pull/225423,\ntargeted only direct imports from `enzyme`. This PR targets all\noccurrences of helper functions that use Enzyme under the hood.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"293bb28818f87bc9793e4ecbf9ecc56cfb00990c"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/227172","number":227172,"state":"OPEN"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/226205","number":226205,"mergeCommit":{"message":"[ML] Migrate `Enzyme` tests to `RTL` part 2 (#226205)\n\nThe previous PR - https://github.com/elastic/kibana/pull/225423,\ntargeted only direct imports from `enzyme`. This PR targets all\noccurrences of helper functions that use Enzyme under the hood.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"293bb28818f87bc9793e4ecbf9ecc56cfb00990c"}}]}] BACKPORT-->
The previous PR - elastic#225423, targeted only direct imports from `enzyme`. This PR targets all occurrences of helper functions that use Enzyme under the hood. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
The previous PR - #225423, targeted only direct imports from
enzyme. This PR targets all occurrences of helper functions that use Enzyme under the hood.