From 02af38b6b43045a2f5ddc20c500c9294c98f99b0 Mon Sep 17 00:00:00 2001 From: vinu-deriv <100689171+vinu-deriv@users.noreply.github.com> Date: Fri, 27 Oct 2023 15:40:06 +0400 Subject: [PATCH] test: add test case for notify-item (#11003) * test: add test case for notify-item * test: add test case scenarios for notify-item --- .../__tests__/notify-item.spec.tsx | 39 +++++++++++++++++++ .../components/notify-item/notify-item.jsx | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 packages/bot-web-ui/src/components/notify-item/__tests__/notify-item.spec.tsx diff --git a/packages/bot-web-ui/src/components/notify-item/__tests__/notify-item.spec.tsx b/packages/bot-web-ui/src/components/notify-item/__tests__/notify-item.spec.tsx new file mode 100644 index 000000000000..d309f3be20f2 --- /dev/null +++ b/packages/bot-web-ui/src/components/notify-item/__tests__/notify-item.spec.tsx @@ -0,0 +1,39 @@ +import { render, screen } from '@testing-library/react'; +import { messageWithButton, messageWithImage, getIcon } from '../notify-item'; +import userEvent from '@testing-library/user-event'; + +const messageWithButtonMockProps = { + unique_id: '123', + type: 'error', + message: 'sample text', + btn_text: 'ok', + onClick: jest.fn(), +}; + +describe('messageWithButtonMockProps', () => { + it('should render messageWithButton', () => { + const { container } = render(messageWithButton({ ...messageWithButtonMockProps })); + expect(container).toBeInTheDocument(); + expect(screen.getByText('sample text')).toBeInTheDocument(); + }); + + it('should call function of the button on click of the button', () => { + render(messageWithButton({ ...messageWithButtonMockProps })); + userEvent.click(screen.getByRole('button')); + expect(messageWithButtonMockProps.onClick).toHaveBeenCalled(); + }); + + it('should get appropriate icon when getIcon is called', () => { + expect(getIcon('warn')).toEqual('IcAlertWarning'); + expect(getIcon('info')).toEqual('IcAlertInfo'); + expect(getIcon('error')).toEqual('IcAlertDanger'); + expect(getIcon('')).toEqual('IcAlertWarning'); + }); + + it('should render messageWithImage', () => { + const { container } = render(messageWithImage('sample text', '')); + expect(container).toBeInTheDocument(); + expect(screen.getByText('sample text')).toBeInTheDocument(); + expect(screen.getByRole('img')).toBeInTheDocument(); + }); +}); diff --git a/packages/bot-web-ui/src/components/notify-item/notify-item.jsx b/packages/bot-web-ui/src/components/notify-item/notify-item.jsx index ef37861da106..244b3c1ce958 100644 --- a/packages/bot-web-ui/src/components/notify-item/notify-item.jsx +++ b/packages/bot-web-ui/src/components/notify-item/notify-item.jsx @@ -1,7 +1,7 @@ import React from 'react'; import { Button, ExpansionPanel, Icon } from '@deriv/components'; -const getIcon = type => { +export const getIcon = type => { switch (type) { case 'error': return 'IcAlertDanger';