diff --git a/src/web/components/notification/__tests__/withDialogNotification.test.tsx b/src/web/components/notification/__tests__/withDialogNotification.test.tsx new file mode 100644 index 0000000000..e78615e312 --- /dev/null +++ b/src/web/components/notification/__tests__/withDialogNotification.test.tsx @@ -0,0 +1,92 @@ +/* SPDX-FileCopyrightText: 2026 Greenbone AG + * + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import {describe, expect, test} from '@gsa/testing'; +import {fireEvent, render, screen} from 'web/testing'; +import withDialogNotification, { + type DialogNotificationProps, +} from 'web/components/notification/withDialogNotification'; + +interface TestProps extends DialogNotificationProps { + label?: string; +} + +interface TestOwnProps { + label?: string; +} + +const TestComponent = ({ + label = 'test', + showError, + showErrorMessage, + showMessage, + showSuccessMessage, +}: TestProps) => ( +
+ {label} +
+); + +const WrappedComponent = withDialogNotification(TestComponent); + +const click = (testId: string) => fireEvent.click(screen.getByTestId(testId)); + +describe('withDialogNotification tests', () => { + test('should set the wrapper display name', () => { + expect(WrappedComponent.displayName).toBe( + 'withDialogNotification(TestComponent)', + ); + }); + + test('should render the wrapped component and forward props', () => { + render(); + + expect(screen.getByText('custom label')).toBeInTheDocument(); + expect(screen.queryDialog()).not.toBeInTheDocument(); + }); + + test.each([ + ['show-message', 'Message', 'message'], + ['show-message-with-subject', 'Subject', 'message'], + ['show-error-message', 'Error', 'error message'], + ['show-success-message', 'Success', 'success message'], + ['show-error', 'Error', 'error'], + ])('should show the %s notification as %s', (testId, title, message) => { + render(); + + click(testId); + + expect(screen.getDialogTitle()).toHaveTextContent(title); + expect(screen.getDialogContent()).toHaveTextContent(message); + }); + + test('should close the notification dialog', () => { + render(); + + click('show-message'); + expect(screen.queryDialog()).toBeInTheDocument(); + + fireEvent.click(screen.getByRole('button', {name: 'Close'})); + + expect(screen.queryDialog()).not.toBeInTheDocument(); + }); +});