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';