forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReceiptImageViewer.test.tsx
More file actions
62 lines (54 loc) · 2.21 KB
/
Copy pathReceiptImageViewer.test.tsx
File metadata and controls
62 lines (54 loc) · 2.21 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
57
58
59
60
61
62
import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import { ReceiptImageViewer } from './ReceiptImageViewer';
describe('ReceiptImageViewer', () => {
const mockImageUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
it('renders receipt image', () => {
render(<ReceiptImageViewer imageUrl={mockImageUrl} />);
const img = screen.getByAltText('Receipt');
expect(img).toBeDefined();
});
it('displays zoom controls', () => {
render(<ReceiptImageViewer imageUrl={mockImageUrl} />);
expect(screen.getByLabelText('Zoom in')).toBeDefined();
expect(screen.getByLabelText('Zoom out')).toBeDefined();
});
it('zooms in on button click', () => {
render(<ReceiptImageViewer imageUrl={mockImageUrl} />);
const zoomInBtn = screen.getByLabelText('Zoom in');
fireEvent.click(zoomInBtn);
expect(screen.getByText(/120%/)).toBeDefined();
});
it('zooms out on button click', () => {
render(<ReceiptImageViewer imageUrl={mockImageUrl} />);
const zoomInBtn = screen.getByLabelText('Zoom in');
const zoomOutBtn = screen.getByLabelText('Zoom out');
fireEvent.click(zoomInBtn);
fireEvent.click(zoomOutBtn);
expect(screen.getByText(/100%/)).toBeDefined();
});
it('disables zoom out at minimum', () => {
render(<ReceiptImageViewer imageUrl={mockImageUrl} />);
const zoomOutBtn = screen.getByLabelText('Zoom out') as HTMLButtonElement;
expect(zoomOutBtn.disabled).toBe(true);
});
it('highlights region when provided', () => {
const { container } = render(
<ReceiptImageViewer
imageUrl={mockImageUrl}
highlightRegion={{ x: 10, y: 20, width: 30, height: 40 }}
/>
);
const highlight = container.querySelector('[style*="border-2"]');
expect(highlight).toBeDefined();
});
it('calls onRegionClick when image is clicked', () => {
const onRegionClick = vi.fn();
render(
<ReceiptImageViewer imageUrl={mockImageUrl} onRegionClick={onRegionClick} />
);
const img = screen.getByAltText('Receipt');
fireEvent.click(img);
expect(onRegionClick).toHaveBeenCalled();
});
});