Skip to content

Commit

Permalink
[WALL] Lubega / WALL-2987 / TransactionStatusError unit test (#13061)
Browse files Browse the repository at this point in the history
* chore: transaction status error unit test

* fix: applied comments

* Merge branch 'master' of github.com:binary-com/deriv-app into WALL-2987/transaction-status-error-unit-test

* fix: cleaned up code

* fix: rerun workflow
  • Loading branch information
lubega-deriv authored Jan 25, 2024
1 parent a0aa511 commit bb69546
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@ jest.mock('../../../../../../../components/ModalProvider', () => ({
}));

const mockTransaction = {
address_hash: '1234567890',
address_url: 'https://example.com/address',
address_hash: '',
address_url: '',
amount: 0.0002,
description: 'Transaction description',
formatted_address_hash: 'abc123',
formatted_amount: '0.0002 BTC',
description: '',
formatted_address_hash: '',
formatted_amount: '',
formatted_confirmations: 'Pending',
formatted_transaction_hash: 'Pending',
id: '123',
id: '',
is_deposit: false,
is_valid_to_cancel: 1 as const,
is_withdrawal: true,
status_code: 'LOCKED' as const,
status_message:
"We're reviewing your withdrawal request. You may still cancel this transaction if you wish. Once we start processing, you won't be able to cancel.",
status_name: 'In review',
submit_date: 1705399737,
status_message: '',
status_name: '',
submit_date: 123456,
transaction_type: 'withdrawal' as const,
};

Expand All @@ -60,23 +59,22 @@ describe('CryptoTransaction', () => {

it('should render component with correct properties for deposit type transaction', () => {
const mockDepositTransaction = {
address_hash: '1234567890',
address_url: 'https://example.com/address',
address_hash: '',
address_url: '',
amount: 0.0002,
description: 'Transaction description',
formatted_address_hash: 'abc123',
formatted_amount: '0.0002 BTC',
description: '',
formatted_address_hash: '',
formatted_amount: '',
formatted_confirmations: 'Pending',
formatted_transaction_hash: 'Pending',
id: '123',
id: '',
is_deposit: true,
is_valid_to_cancel: 1 as const,
is_withdrawal: false,
status_code: 'LOCKED' as const,
status_message:
"We're reviewing your deposit request. You may still cancel this transaction if you wish. Once we start processing, you won't be able to cancel.",
status_name: 'In review',
submit_date: 1705399737,
status_message: '',
status_name: '',
submit_date: 123456,
transaction_type: 'withdrawal' as const,
};
(useCancelCryptoTransaction as jest.Mock).mockReturnValue({ mutate: jest.fn() });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import TransactionStatusError from '../TransactionStatusError';

describe('TransactionStatusError', () => {
it('should render component correctly', () => {
const mockRefresh = jest.fn();

render(<TransactionStatusError refresh={mockRefresh} />);

expect(screen.getByText('Unfortunately, we cannot retrieve the information at this time.')).toBeInTheDocument();
expect(screen.getByText('Refresh')).toBeInTheDocument();
});

it('should render refresh function on click of refresh button', () => {
const mockRefresh = jest.fn();

render(<TransactionStatusError refresh={mockRefresh} />);

expect(screen.getByText('Unfortunately, we cannot retrieve the information at this time.')).toBeInTheDocument();

const refreshButton = screen.getByText('Refresh');
expect(refreshButton).toBeInTheDocument();

fireEvent.click(refreshButton);
expect(mockRefresh).toHaveBeenCalledTimes(1);
});
});

0 comments on commit bb69546

Please sign in to comment.