forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQRCodeGenerator.test.tsx
More file actions
56 lines (48 loc) · 1.49 KB
/
Copy pathQRCodeGenerator.test.tsx
File metadata and controls
56 lines (48 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { describe, expect, it, vi, beforeEach } from 'vitest';
import { QRCodeGenerator } from './QRCodeGenerator';
vi.mock('qrcode.react', () => ({
QRCodeCanvas: () => <canvas data-testid="qr-canvas" />,
}));
const DESTINATION = 'GDQP2KPQGKIHYJGXNUIYOMHARUARCA6NSWVE2YQYCVY75HL7P5G4U2DI';
describe('QRCodeGenerator', () => {
beforeEach(() => {
Object.assign(navigator, {
clipboard: {
writeText: vi.fn().mockResolvedValue(undefined),
},
});
});
it('renders generated payment URI and QR canvas', () => {
render(
<QRCodeGenerator
paymentRequest={{
destination: DESTINATION,
amount: 12,
memo: 'split_123',
memoType: 'text',
}}
/>,
);
expect(screen.getByTestId('qr-canvas')).toBeInTheDocument();
expect(screen.getByTestId('payment-uri-value').textContent).toContain('web+stellar:pay?');
expect(screen.getByText('Download QR')).toBeInTheDocument();
});
it('copies URI to clipboard', async () => {
const writeTextSpy = vi.spyOn(navigator.clipboard, 'writeText');
render(
<QRCodeGenerator
paymentRequest={{
destination: DESTINATION,
amount: 5,
memo: 'split_999',
memoType: 'text',
}}
/>,
);
fireEvent.click(screen.getByText('Copy URI'));
await waitFor(() => {
expect(writeTextSpy).toHaveBeenCalledTimes(1);
});
});
});