Skip to content

Commit

Permalink
add test for windowSize
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAlec committed Aug 9, 2024
1 parent b08825e commit 09c2397
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/wallet/components/WalletDropdownFundLink.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('WalletDropdownFundLink', () => {
// Mock window.screen
vi.stubGlobal('screen', { width: 1024, height: 768 });

render(<WalletDropdownFundLink type="window" />);
render(<WalletDropdownFundLink openIn="window" />);

const linkElement = screen.getByText('Deposit Funds');
fireEvent.click(linkElement);
Expand All @@ -58,4 +58,41 @@ describe('WalletDropdownFundLink', () => {
// Clean up
vi.unstubAllGlobals();
});

const testCases: Array<{
size: 's' | 'm' | 'l';
width: number;
height: number;
}> = [
{ size: 's', width: 400, height: 500 },
{ size: 'm', width: 600, height: 700 },
{ size: 'l', width: 800, height: 900 },
];

testCases.forEach(({ size, width, height }) => {
it(`opens a new window when clicked with type="window" and windowSize="${size}"`, () => {
const mockOpen = vi.fn();
vi.stubGlobal('open', mockOpen);
vi.stubGlobal('open', mockOpen);
vi.stubGlobal('screen', { width: 1024, height: 768 });

render(<WalletDropdownFundLink openIn="window" windowSize={size} />);

const linkElement = screen.getByText('Deposit Funds');
fireEvent.click(linkElement);

const expectedLeft = (1024 - width) / 2;
const expectedTop = (768 - height) / 2;
expect(mockOpen).toHaveBeenCalledWith(
expect.stringContaining('http://keys.coinbase.com/funding'),
'Coinbase Fund Wallet',
expect.stringContaining(
`width=${width},height=${height},resizable,scrollbars=yes,status=1,left=${expectedLeft},top=${expectedTop}`,
),
);

vi.unstubAllGlobals();
vi.clearAllMocks();
});
});
});

0 comments on commit 09c2397

Please sign in to comment.