Skip to content

Commit

Permalink
[WALL] Farhan/WALL-2911/Unit test for WalletsErrorScreen component (#…
Browse files Browse the repository at this point in the history
…12217)

* chore: ✨unit tests for WalletsErrorScreen component

* chore: ✨ clear mocks

* refactor: 🧹 change getbytext to getbyrole
  • Loading branch information
farhan-nurzi-deriv committed Dec 13, 2023
1 parent 7b17ce1 commit c17ab6c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import IcCashierError from '../../public/images/ic-cashier-error.svg';
import ErrorIcon from '../../public/images/error-icon.svg';
import { WalletButton } from '../Base';
import { WalletsActionScreen } from '../WalletsActionScreen';

type TProps = {
message: string;
message?: string;
};

const ErrorState: React.FC<TProps> = ({
Expand All @@ -13,7 +13,7 @@ const ErrorState: React.FC<TProps> = ({
return (
<WalletsActionScreen
description={message}
icon={<IcCashierError />}
icon={<ErrorIcon data-testid='dt_error_icon' />}
renderButtons={() => (
<WalletButton onClick={() => window.location.reload()} size='lg' variant='ghost'>
Try again
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import WalletsErrorScreen from '../WalletsErrorScreen';

describe('WalletsErrorScreen', () => {
afterAll(() => {
jest.clearAllMocks();
});

it('should show the correct title and icon with default message', () => {
render(<WalletsErrorScreen />);
expect(screen.getByTestId('dt_error_icon')).toBeInTheDocument();
expect(screen.getByText('Oops, something went wrong!')).toBeInTheDocument();
expect(
screen.getByText('Sorry an error occurred. Please try accessing our cashier page again.')
).toBeInTheDocument();
});

it('should show the message passed as prop', () => {
render(<WalletsErrorScreen message='Error message from props' />);
expect(screen.getByText('Error message from props')).toBeInTheDocument();
});

it('should reload the page when Try again button is clicked', () => {
const reloadMock = jest.fn();
Object.defineProperty(window, 'location', {
value: { reload: reloadMock },
writable: true,
});
render(<WalletsErrorScreen />);
screen.getByRole('button', { name: 'Try again' }).click();
expect(reloadMock).toHaveBeenCalled();
});
});
1 change: 0 additions & 1 deletion packages/wallets/src/public/images/ic-cashier-error.svg

This file was deleted.

1 comment on commit c17ab6c

@vercel
Copy link

@vercel vercel bot commented on c17ab6c Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

deriv-app – ./

deriv-app.vercel.app
deriv-app-git-master.binary.sx
binary.sx
deriv-app.binary.sx

Please sign in to comment.