Skip to content

Commit

Permalink
test: add test case for notify-item (deriv-com#11003)
Browse files Browse the repository at this point in the history
* test: add test case for notify-item

* test: add test case scenarios for notify-item
  • Loading branch information
vinu-deriv authored Oct 27, 2023
1 parent 29d3c01 commit 02af38b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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();
});
});
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 02af38b

Please sign in to comment.