Skip to content

Commit

Permalink
fix: history box tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency committed Dec 2, 2024
1 parent b0099f4 commit 58fa478
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
23 changes: 7 additions & 16 deletions components/bank/components/__tests__/historyBox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mock.module('@/hooks', () => ({
],
},
}),
useSendTxIncludingAddressQuery: () => ({
useGetFilteredTxAndSuccessfulProposals: () => ({
sendTxs: mockTransactions,
totalPages: 1,
isLoading: false,
Expand All @@ -31,19 +31,16 @@ mock.module('@/hooks', () => ({
describe('HistoryBox', () => {
afterEach(() => {
cleanup();
mock.restore();
});

test('renders correctly', () => {
renderWithChainProvider(
<HistoryBox isLoading={false} send={mockTransactions} address="address1" />
);
renderWithChainProvider(<HistoryBox isLoading={false} address="address1" />);
expect(screen.getByText('Transaction History')).toBeTruthy();
});

test('displays transactions', () => {
renderWithChainProvider(
<HistoryBox isLoading={false} send={mockTransactions} address="address1" />
);
renderWithChainProvider(<HistoryBox isLoading={false} address="address1" />);

const sentText = screen.getByText('Sent');
const receivedText = screen.getByText('Received');
Expand All @@ -53,9 +50,7 @@ describe('HistoryBox', () => {
});

test('opens modal when clicking on a transaction', () => {
renderWithChainProvider(
<HistoryBox isLoading={false} send={mockTransactions} address="address1" />
);
renderWithChainProvider(<HistoryBox isLoading={false} address="address1" />);

const transactionElement = screen.getByText('Sent').closest('div[role="button"]');

Expand All @@ -66,9 +61,7 @@ describe('HistoryBox', () => {
});

test('formats amount correctly', () => {
renderWithChainProvider(
<HistoryBox isLoading={false} send={mockTransactions} address="address1" />
);
renderWithChainProvider(<HistoryBox isLoading={false} address="address1" />);

const sentAmount = screen.queryByText('-1 TOKEN');
const receivedAmount = screen.queryByText('+2 TOKEN');
Expand All @@ -78,9 +71,7 @@ describe('HistoryBox', () => {
});

test('displays both sent and received transactions', () => {
renderWithChainProvider(
<HistoryBox isLoading={false} send={mockTransactions} address="address1" />
);
renderWithChainProvider(<HistoryBox isLoading={false} address="address1" />);

const sentText = screen.getByText('Sent');
const receivedText = screen.getByText('Received');
Expand Down
2 changes: 0 additions & 2 deletions components/bank/components/historyBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ function formatLargeNumber(num: number): string {

export function HistoryBox({
isLoading: initialLoading,
send,
address,
}: {
isLoading: boolean;
send: TransactionGroup[];
address: string;
}) {
const [selectedTx, setSelectedTx] = useState<TransactionGroup | null>(null);
Expand Down
4 changes: 3 additions & 1 deletion tests/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@liftedinit/manifestjs/dist/codegen/cosmos/staking/v1beta1/staking';
import { ExtendedValidatorSDKType, TransactionGroup } from '@/components';
import { CombinedBalanceInfo } from '@/utils/types';
import { ExtendedGroupType } from '@/hooks';
import { ExtendedGroupType, HistoryTxType } from '@/hooks';
import {
MemberSDKType,
ProposalExecutorResult,
Expand Down Expand Up @@ -200,6 +200,7 @@ export const mockTransactions: TransactionGroup[] = [
block_number: 1,
formatted_date: '2023-05-01T12:00:00Z',
data: {
tx_type: HistoryTxType.SEND,
from_address: 'address1',
to_address: 'address2',
amount: [{ amount: '1000000', denom: 'utoken' }],
Expand All @@ -210,6 +211,7 @@ export const mockTransactions: TransactionGroup[] = [
block_number: 2,
formatted_date: '2023-05-02T12:00:00Z',
data: {
tx_type: HistoryTxType.SEND,
from_address: 'address2',
to_address: 'address1',
amount: [{ amount: '2000000', denom: 'utoken' }],
Expand Down

0 comments on commit 58fa478

Please sign in to comment.