Skip to content

Commit

Permalink
fix lints and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-defi committed Jan 9, 2025
1 parent a99517f commit f6d4793
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 51 deletions.
23 changes: 2 additions & 21 deletions src/internal/components/PressableIcon.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,15 @@ describe('PressableIcon', () => {
</PressableIcon>,
);

const container = screen.getByTestId(
'ockPressableIconButton',
).parentElement;
expect(container).toHaveClass(
const button = screen.getByTestId('ockPressableIconButton');
expect(button).toHaveClass(
'flex',
'items-center',
'justify-center',
customClass,
);
});

it('merges custom button className with default classes', () => {
const customButtonClass = 'custom-class';
render(
<PressableIcon buttonClassName={customButtonClass}>
<span>Icon</span>
</PressableIcon>,
);

const pressableIconButton = screen.getByText('Icon').parentElement;
expect(pressableIconButton).toHaveClass(
'flex',
'items-center',
'justify-center',
customButtonClass,
);
});

it('applies aria-label to button', () => {
const ariaLabel = 'test-aria-label';
render(
Expand Down
4 changes: 1 addition & 3 deletions src/wallet/components/WalletIslandAddressDetails.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ describe('WalletIslandAddressDetails', () => {

const { rerender } = render(<AddressDetails />);

expect(
screen.getByTestId('ockWalletIsland_AddressBalance'),
).toHaveTextContent('');
expect(screen.queryByTestId('ockWalletIsland_AddressBalance')).toBeNull();

mockUseWalletIslandContext.mockReturnValue({
isFetchingPortfolioData: false,
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/components/WalletIslandProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('useWalletIslandContext', () => {
});

expect(mockUsePortfolioTokenBalances).toHaveBeenCalledWith({
address: '0x000',
address: null,
});

mockUseWalletContext.mockReturnValue({
Expand Down
37 changes: 22 additions & 15 deletions src/wallet/components/WalletIslandQrReceive.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,37 @@ describe('WalletIslandQrReceive', () => {
);
});

it('should close when the back button is clicked', () => {
vi.useFakeTimers();

const setShowQrMock = vi.fn();
const setIsQrClosingMock = vi.fn();
it('should close when back button is clicked', () => {
const mockSetShowQr = vi.fn();
const mockSetIsQrClosing = vi.fn();
mockUseWalletIslandContext.mockReturnValue({
...defaultMockUseWalletIslandContext,
showQr: true,
setShowQr: setShowQrMock,
setIsQrClosing: setIsQrClosingMock,
setShowQr: mockSetShowQr,
setIsQrClosing: mockSetIsQrClosing,
});

render(<WalletIslandQrReceive />);
const backButton = screen.getByRole('button', { name: /back/i });
const { rerender } = render(<WalletIslandQrReceive />);

const backButton = screen.getByRole('button', { name: /back button/i });
fireEvent.click(backButton);
expect(setIsQrClosingMock).toHaveBeenCalledWith(true);
expect(mockSetIsQrClosing).toHaveBeenCalledWith(true);

vi.advanceTimersByTime(200);
expect(setShowQrMock).toHaveBeenCalledWith(false);
mockUseWalletIslandContext.mockReturnValue({
...defaultMockUseWalletIslandContext,
showQr: true,
setShowQr: mockSetShowQr,
setIsQrClosing: mockSetIsQrClosing,
isQrClosing: true,
});

vi.advanceTimersByTime(200);
expect(setIsQrClosingMock).toHaveBeenCalledWith(false);
rerender(<WalletIslandQrReceive />);

vi.useRealTimers();
const qrContainer = screen.getByTestId('ockWalletIslandQrReceive');
fireEvent.animationEnd(qrContainer);

expect(mockSetShowQr).toHaveBeenCalledWith(false);
expect(mockSetIsQrClosing).toHaveBeenCalledWith(false);
});

it('should copy address when the copy icon is clicked', async () => {
Expand Down
33 changes: 23 additions & 10 deletions src/wallet/components/WalletIslandSwap.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,6 @@ describe('WalletIslandSwap', () => {
});

it('should close swap when back button is clicked', () => {
vi.useFakeTimers();

const mockSetShowSwap = vi.fn();
const mockSetIsSwapClosing = vi.fn();
mockUseWalletIslandContext.mockReturnValue({
Expand All @@ -212,7 +210,7 @@ describe('WalletIslandSwap', () => {
setIsSwapClosing: mockSetIsSwapClosing,
});

render(
const { rerender } = render(
<WalletIslandSwap
config={{ maxSlippage: 1 }}
from={[tokens[0]] as Token[]}
Expand All @@ -223,18 +221,33 @@ describe('WalletIslandSwap', () => {
/>,
);

expect(screen.getByTestId('ockWalletIslandSwap')).toBeInTheDocument();

const backButton = screen.getByRole('button', { name: /back button/i });
fireEvent.click(backButton);
expect(mockSetIsSwapClosing).toHaveBeenCalledWith(true);

vi.advanceTimersByTime(200);
expect(mockSetShowSwap).toHaveBeenCalledWith(false);
mockUseWalletIslandContext.mockReturnValue({
...defaultMockUseWalletIslandContext,
tokenHoldings: [tokens],
setShowSwap: mockSetShowSwap,
setIsSwapClosing: mockSetIsSwapClosing,
isSwapClosing: true,
});

vi.advanceTimersByTime(200);
expect(mockSetIsSwapClosing).toHaveBeenCalledWith(false);
rerender(
<WalletIslandSwap
config={{ maxSlippage: 1 }}
from={[tokens[0]] as Token[]}
to={[tokens[1]] as Token[]}
onError={vi.fn()}
onStatus={vi.fn()}
onSuccess={vi.fn()}
/>,
);

vi.useRealTimers();
const swapContainer = screen.getByTestId('ockWalletIslandSwap');
fireEvent.animationEnd(swapContainer);

expect(mockSetShowSwap).toHaveBeenCalledWith(false);
expect(mockSetIsSwapClosing).toHaveBeenCalledWith(false);
});
});
2 changes: 1 addition & 1 deletion src/wallet/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Token } from '@/token';
import { usdcToken, ethToken } from '@/token/constants';
import { ethToken, usdcToken } from '@/token/constants';

// The bytecode for the Coinbase Smart Wallet proxy contract.
export const CB_SW_PROXY_BYTECODE =
Expand Down

0 comments on commit f6d4793

Please sign in to comment.