Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"devDependencies": {
"@types/node": "^20.12.7",
"@types/jest": "^29.5.14",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.1",
"autoprefixer": "^10.4.19",
Expand Down
86 changes: 86 additions & 0 deletions src/components/BalanceCard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import { BalanceCard } from './BalanceCard';
import { useVault } from '@/hooks/useVault';

jest.mock('@/hooks/useVault', () => ({
useVault: jest.fn(),
}));

const mockUseVault = useVault as jest.Mock;

const defaultVaultState = {
balance: 15000000000n,
totalShares: 100000n,
isLoading: false,
isRefreshing: false,
error: null,
deposit: jest.fn(),
withdraw: jest.fn(),
claimRewards: jest.fn(),
refresh: jest.fn(),
};

const renderBalanceCard = (overrides = {}) => {
const state = {
...defaultVaultState,
refresh: jest.fn(),
claimRewards: jest.fn(),
...overrides,
};

mockUseVault.mockReturnValue(state);
render(<BalanceCard />);

return state;
};

describe('BalanceCard', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('renders the current balance and pending rewards', () => {
renderBalanceCard();

expect(screen.getByText('Vault Balance')).toBeInTheDocument();
expect(screen.getByRole('heading', { name: '1500 XLM' })).toBeInTheDocument();
expect(screen.getByText('Pending Rewards: 12.5 XLM')).toBeInTheDocument();
});

it('shows a loading placeholder and disables actions while loading', () => {
renderBalanceCard({ isLoading: true });

expect(screen.getByRole('heading', { name: '...' })).toBeInTheDocument();

const [refreshButton, claimButton] = screen.getAllByRole('button');
expect(refreshButton).toBeDisabled();
expect(claimButton).toBeDisabled();
});

it('renders zero balance clearly', () => {
renderBalanceCard({ balance: 0n });

expect(screen.getByRole('heading', { name: '0 XLM' })).toBeInTheDocument();
});

it('formats atomic Stellar units as XLM', () => {
renderBalanceCard({ balance: 123456789n });

expect(screen.getByRole('heading', { name: '12.3456789 XLM' })).toBeInTheDocument();
});

it('calls vault actions from the refresh and claim buttons', () => {
const refresh = jest.fn();
const claimRewards = jest.fn();

renderBalanceCard({ refresh, claimRewards });

const [refreshButton, claimButton] = screen.getAllByRole('button');
fireEvent.click(refreshButton);
fireEvent.click(claimButton);

expect(refresh).toHaveBeenCalledTimes(1);
expect(claimRewards).toHaveBeenCalledTimes(1);
});
});
4 changes: 3 additions & 1 deletion src/components/TransactionHistory.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ describe('TransactionHistory', () => {
// So it should show 1 successful deposit.
const transactions = screen.getAllByRole('link');
expect(transactions.length).toBe(1);
expect(screen.getByText('500.00 XLM')).toBeInTheDocument();
expect(
screen.getByText((_, element) => element?.textContent === '+500.00 XLM')
).toBeInTheDocument();
});

it('filters by failed transactions', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/components/TransactionHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export const TransactionHistory: React.FC = () => {
</div>
<p className="text-sm text-slate-600 font-bold">No transactions found</p>
<p className="text-xs text-slate-400 mt-1.5 max-w-[180px]">
We couldn't find any activities matching your current filters.
We couldn&apos;t find any activities matching your current filters.
</p>
</div>
)}
Expand All @@ -172,4 +172,3 @@ export const TransactionHistory: React.FC = () => {
</div>
);
};

3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2020",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand All @@ -18,6 +18,7 @@
"paths": {
"@/*": ["src/*"]
},
"types": ["jest", "@testing-library/jest-dom"],
"plugins": [
{
"name": "next"
Expand Down