Skip to content

Commit 3f29977

Browse files
test: add coverage to the transactions tab
1 parent 64d6f25 commit 3f29977

File tree

4 files changed

+156
-4
lines changed

4 files changed

+156
-4
lines changed

apps/evm/src/clients/api/__mocks__/index.ts

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import voters from '__mocks__/models/voters';
1818
import FunctionKey from 'constants/functionKey';
1919

2020
import { proposals } from '__mocks__/models/proposals';
21+
import { usdt } from '__mocks__/models/tokens';
2122
import type { Token, VToken } from 'types';
2223
import type { Address } from 'viem';
2324
import type { GetBalanceOfInput } from '../queries/getBalanceOf';
@@ -634,6 +635,111 @@ export const useGetAccountPerformanceHistory = vi.fn(() =>
634635
}),
635636
);
636637

638+
export const getAccountTransactionHistory = vi.fn(async () => ({
639+
transactions: [
640+
{
641+
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
642+
amountCents: new BigNumber('2406931.018168454893468167206'),
643+
amountTokens: new BigNumber('24066181578079398.612862'),
644+
blockNumber: '41604850',
645+
blockTimestamp: new Date('2024-08-23T04:17:09.000Z'),
646+
chainId: 97,
647+
contractAddress: '0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c',
648+
hash: '0xda13a0f45b10dabd21b863b6b602c6d8776edd4c6b10fe65a0881d491f468f35',
649+
poolName: 'Metaverse',
650+
token: usdt,
651+
txType: 'redeem',
652+
},
653+
{
654+
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
655+
amountCents: new BigNumber('2401121.576132434220587935367386'),
656+
amountTokens: new BigNumber('24001813290985731.455439'),
657+
blockNumber: '41114054',
658+
blockTimestamp: new Date('2024-08-06T02:18:03.000Z'),
659+
chainId: 97,
660+
contractAddress: '0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c',
661+
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
662+
poolName: 'Metaverse',
663+
token: usdt,
664+
txType: 'mint',
665+
},
666+
{
667+
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
668+
amountCents: new BigNumber('2401121.576132434220587935367386'),
669+
amountTokens: new BigNumber('24001813290985731.455439'),
670+
blockNumber: '41114053',
671+
blockTimestamp: new Date('2024-08-05T02:18:03.000Z'),
672+
chainId: 97,
673+
contractAddress: '0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c',
674+
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
675+
poolName: 'Metaverse',
676+
token: usdt,
677+
txType: 'borrow',
678+
},
679+
{
680+
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
681+
amountCents: new BigNumber('2401121.576132434220587935367386'),
682+
amountTokens: new BigNumber('24001813290985731.455439'),
683+
blockNumber: '41114052',
684+
blockTimestamp: new Date('2024-08-04T02:18:03.000Z'),
685+
chainId: 97,
686+
contractAddress: '0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c',
687+
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
688+
poolName: 'Metaverse',
689+
token: usdt,
690+
txType: 'repay',
691+
},
692+
{
693+
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
694+
amountCents: new BigNumber('2401121.576132434220587935367386'),
695+
amountTokens: new BigNumber('24001813290985731.455439'),
696+
blockNumber: '41114051',
697+
blockTimestamp: new Date('2024-08-03T02:18:03.000Z'),
698+
chainId: 97,
699+
contractAddress: '0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c',
700+
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
701+
poolName: 'Metaverse',
702+
token: usdt,
703+
txType: 'enter_market',
704+
},
705+
{
706+
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
707+
amountCents: new BigNumber('2401121.576132434220587935367386'),
708+
amountTokens: new BigNumber('24001813290985731.455439'),
709+
blockNumber: '41114050',
710+
blockTimestamp: new Date('2024-08-03T02:18:00.000Z'),
711+
chainId: 97,
712+
contractAddress: '0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c',
713+
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
714+
poolName: 'Metaverse',
715+
token: usdt,
716+
txType: 'exit_market',
717+
},
718+
{
719+
accountAddress: '0x3d759121234cd36F8124C21aFe1c6852d2bEd848',
720+
amountCents: new BigNumber('0'),
721+
amountTokens: new BigNumber(
722+
'115792089237316195423570985008687907853269984665640564039457584007913129639935',
723+
),
724+
blockNumber: '41114008',
725+
blockTimestamp: new Date('2024-08-02T02:18:00.000Z'),
726+
chainId: 97,
727+
contractAddress: '0xA11c8D9DC9b66E209Ef60F0C8D969D3CD988782c',
728+
hash: '0xb0435b135762a7ca2ad7dccb9aa6c7f50237c6139b16a76348d6c64dfece110e',
729+
poolName: 'Metaverse',
730+
token: usdt,
731+
txType: 'approve',
732+
},
733+
],
734+
count: 7,
735+
}));
736+
export const useGetAccountTransactionHistory = vi.fn(() =>
737+
useQuery({
738+
queryKey: [FunctionKey.GET_ACCOUNT_TRANSACTION_HISTORY],
739+
queryFn: getAccountTransactionHistory,
740+
}),
741+
);
742+
637743
// Mutations
638744
export const useApproveToken = vi.fn((_variables: never, options?: MutationObserverOptions) =>
639745
useMutation({

apps/evm/src/clients/api/queries/getAccountTransactionHistory/__tests__/index.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { ChainId } from '@venusprotocol/chains';
22
import fakeAddress from '__mocks__/models/address';
33
import { poolData } from '__mocks__/models/pools';
4+
import { TxType } from 'types';
45
import { restService } from 'utilities';
56
import { type Mock, vi } from 'vitest';
6-
import { type ApiAccountHistoricalTransaction, TxType, getAccountTransactionHistory } from '..';
7+
import { type ApiAccountHistoricalTransaction, getAccountTransactionHistory } from '..';
78

89
vi.mock('utilities/restService');
910

@@ -53,9 +54,10 @@ describe('getAccountTransactionHistory', () => {
5354

5455
return {
5556
data: {
56-
count: '2',
57-
results: txs,
58-
}};
57+
count: '2',
58+
results: txs,
59+
},
60+
};
5961
});
6062

6163
const response = await getAccountTransactionHistory(fakeInput);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`Transactions > displays content correctly 1`] = `"All transactionsAll marketsAug 23, 2024Withdraw04:17 AM> 100T USDT$24.06K • vUSDT • MetaverseViewAug 06, 2024Supply02:18 AM> 100T USDT$24.01K • vUSDT • MetaverseViewAug 05, 2024Borrow02:18 AM> 100T USDT$24.01K • vUSDT • MetaverseViewAug 04, 2024Repayment02:18 AM> 100T USDT$24.01K • vUSDT • MetaverseViewAug 03, 2024Enabled collateral02:18 AMEnabled vUSDT as collateralMetaverseViewDisabled collateral02:18 AMDisabled vUSDT as collateralMetaverseViewAug 02, 2024Approval02:18 AMApproved spending > 100T USDTvUSDT • MetaverseView"`;
4+
5+
exports[`Transactions > displays placeholder when there are no transactions to display 1`] = `"All transactionsAll marketsNo transactions yetYour transactions will appear here"`;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { waitFor } from '@testing-library/dom';
2+
import fakeAccountAddress from '__mocks__/models/address';
3+
import { useGetAccountTransactionHistory } from 'clients/api';
4+
import { type UseIsFeatureEnabledInput, useIsFeatureEnabled } from 'hooks/useIsFeatureEnabled';
5+
import { en } from 'libs/translations';
6+
import { renderComponent } from 'testUtils/render';
7+
import type { Mock } from 'vitest';
8+
import { Transactions } from '..';
9+
10+
describe('Transactions', () => {
11+
beforeEach(() => {
12+
(useIsFeatureEnabled as Mock).mockImplementation(
13+
({ name }: UseIsFeatureEnabledInput) => name === 'transactionHistory',
14+
);
15+
});
16+
it('displays content correctly', async () => {
17+
const { container, getByText } = renderComponent(<Transactions />, {
18+
accountAddress: fakeAccountAddress,
19+
});
20+
await waitFor(() => expect(getByText(en.account.transactions.txType.mint)));
21+
22+
expect(container.textContent).toMatchSnapshot();
23+
});
24+
25+
it('displays placeholder when there are no transactions to display', async () => {
26+
(useGetAccountTransactionHistory as Mock).mockImplementation(() => ({
27+
data: {
28+
count: 0,
29+
transactions: [],
30+
},
31+
isLoading: false,
32+
}));
33+
const { container } = renderComponent(<Transactions />, {
34+
accountAddress: fakeAccountAddress,
35+
});
36+
37+
expect(container.textContent).toMatchSnapshot();
38+
});
39+
});

0 commit comments

Comments
 (0)