From c9b5713efdea82da68e63ff6be2bd42099d8c147 Mon Sep 17 00:00:00 2001 From: Jesus Wahrman <41008968+jesuswr@users.noreply.github.com> Date: Fri, 1 Aug 2025 19:54:13 +0200 Subject: [PATCH] [Core] Unzyme `src/core/packages/notifications` :shipit: (#230255) ## Summary Resolves https://github.com/elastic/kibana/issues/224001 --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 929a67b5f76b6864d71c1e6dce17c15a8077ec98) --- .../deduplicate_toasts.test.tsx.snap | 15 ----------- .../__snapshots__/error_toast.test.tsx.snap | 27 +------------------ .../src/toasts/deduplicate_toasts.test.tsx | 13 ++++----- .../src/toasts/error_toast.test.tsx | 12 ++++----- 4 files changed, 14 insertions(+), 53 deletions(-) delete mode 100644 src/core/packages/notifications/browser-internal/src/toasts/__snapshots__/deduplicate_toasts.test.tsx.snap diff --git a/src/core/packages/notifications/browser-internal/src/toasts/__snapshots__/deduplicate_toasts.test.tsx.snap b/src/core/packages/notifications/browser-internal/src/toasts/__snapshots__/deduplicate_toasts.test.tsx.snap deleted file mode 100644 index 2ffb987d03e8c..0000000000000 --- a/src/core/packages/notifications/browser-internal/src/toasts/__snapshots__/deduplicate_toasts.test.tsx.snap +++ /dev/null @@ -1,15 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`TitleWithBadge component renders with string titles 1`] = ` - - Welcome! - - - 5 - - -`; diff --git a/src/core/packages/notifications/browser-internal/src/toasts/__snapshots__/error_toast.test.tsx.snap b/src/core/packages/notifications/browser-internal/src/toasts/__snapshots__/error_toast.test.tsx.snap index 2c90434d83e58..e24dff447febf 100644 --- a/src/core/packages/notifications/browser-internal/src/toasts/__snapshots__/error_toast.test.tsx.snap +++ b/src/core/packages/notifications/browser-internal/src/toasts/__snapshots__/error_toast.test.tsx.snap @@ -1,28 +1,3 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders matching snapshot 1`] = ` - - -

- This is the toast message -

-
- - - -
-
-
-`; +exports[`renders matching snapshot 1`] = `"

This is the toast message

"`; diff --git a/src/core/packages/notifications/browser-internal/src/toasts/deduplicate_toasts.test.tsx b/src/core/packages/notifications/browser-internal/src/toasts/deduplicate_toasts.test.tsx index d3acc0c97778e..8157ec5496521 100644 --- a/src/core/packages/notifications/browser-internal/src/toasts/deduplicate_toasts.test.tsx +++ b/src/core/packages/notifications/browser-internal/src/toasts/deduplicate_toasts.test.tsx @@ -8,8 +8,8 @@ */ import React from 'react'; -import { mount, render, shallow } from 'enzyme'; import { ReactElement, ReactNode } from 'react'; +import { render } from '@testing-library/react'; import { deduplicateToasts, TitleWithBadge, ToastWithRichTitle } from './deduplicate_toasts'; import { Toast } from '@kbn/core-notifications-browser'; @@ -104,11 +104,12 @@ describe('TitleWithBadge component', () => { const title = 'Welcome!'; const titleComponent = ; - const shallowRender = shallow(titleComponent); - const fullRender = mount(titleComponent); + const renderedTitle = render(titleComponent); - expect(fullRender.text()).toBe('Welcome! 5'); - expect(shallowRender).toMatchSnapshot(); + expect(renderedTitle.container.textContent).toMatch('Welcome! 5'); + expect(render(titleComponent).container.innerHTML).toMatchInlineSnapshot( + `"Welcome! 5"` + ); }); }); @@ -123,5 +124,5 @@ function verifyTextAndTitle( function getNodeText(node: ReactNode | MountPoint) { const rendered = render(node as ReactElement); - return rendered.text(); + return rendered.container.textContent; } diff --git a/src/core/packages/notifications/browser-internal/src/toasts/error_toast.test.tsx b/src/core/packages/notifications/browser-internal/src/toasts/error_toast.test.tsx index 544fc9e712d16..1dd86835fc6e4 100644 --- a/src/core/packages/notifications/browser-internal/src/toasts/error_toast.test.tsx +++ b/src/core/packages/notifications/browser-internal/src/toasts/error_toast.test.tsx @@ -7,9 +7,9 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import { shallow } from 'enzyme'; +import { render, fireEvent } from '@testing-library/react'; import React from 'react'; -import { mountWithIntl } from '@kbn/test-jest-helpers'; +import { renderWithI18n } from '@kbn/test-jest-helpers'; import { ErrorToast } from './error_toast'; import { renderingServiceMock } from '@kbn/core-rendering-browser-mocks'; @@ -25,7 +25,7 @@ const mockRendering = renderingServiceMock.create(); beforeEach(() => (openModal = jest.fn())); -function render(props: ErrorToastProps = {}) { +function getErrorToast(props: ErrorToastProps = {}) { return ( { - expect(shallow(render())).toMatchSnapshot(); + expect(render(getErrorToast()).container.innerHTML).toMatchSnapshot(); }); it('should open a modal when clicking button', () => { - const wrapper = mountWithIntl(render()); + const { getByTestId } = renderWithI18n(getErrorToast()); expect(openModal).not.toHaveBeenCalled(); - wrapper.find('button').simulate('click'); + fireEvent.click(getByTestId('errorToastBtn')); expect(openModal).toHaveBeenCalled(); });