-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathImageFailureMessage.test.jsx
More file actions
81 lines (66 loc) · 2.82 KB
/
ImageFailureMessage.test.jsx
File metadata and controls
81 lines (66 loc) · 2.82 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { render, screen } from '@tests/utils/test-utils';
import { ImageFailureMessage } from '../../../src/components/ImageFailureMessage';
import FailedImageProvider from '../../../src/contexts/FailedImageProvider';
import FailedImageContext from '../../../src/contexts/FailedImageContext';
describe('ImageFailureMessage', () => {
it('does not render when no images have failed', () => {
const { container } = render(
<FailedImageProvider>
<ImageFailureMessage imageUrls={['https://example.com/image1.jpg']} />
</FailedImageProvider>,
);
expect(container).toBeEmptyDOMElement();
});
it('renders message when a specific image has failed', () => {
const mockContext = {
failedImages: new Set(['https://example.com/image1.jpg']),
fallbackImage: 'data:image/svg+xml,...',
notifyFailure: vi.fn(),
};
render(
<FailedImageContext.Provider value={mockContext}>
<ImageFailureMessage imageUrls={['https://example.com/image1.jpg']} />
</FailedImageContext.Provider>,
);
// Should use the default English translation
expect(screen.getByText(/Problem loading image/i)).toBeInTheDocument();
expect(screen.getByText(/See console for details/i)).toBeInTheDocument();
});
it('isolates failures per window', () => {
const mockContext = {
failedImages: new Set(['https://example.com/manifest-a/canvas-1/image.jpg']),
fallbackImage: 'data:image/svg+xml,...',
notifyFailure: vi.fn(),
};
// Render Window A with its failed image
const { container: containerA } = render(
<FailedImageContext.Provider value={mockContext}>
<ImageFailureMessage imageUrls={['https://example.com/manifest-a/canvas-1/image.jpg']} />
</FailedImageContext.Provider>,
);
expect(containerA).not.toBeEmptyDOMElement();
expect(screen.getByText(/Problem loading image/i)).toBeInTheDocument();
// Render Window B with non-failed image
const { container: containerB } = render(
<FailedImageContext.Provider value={mockContext}>
<ImageFailureMessage imageUrls={['https://example.com/manifest-b/canvas-1/image.jpg']} />
</FailedImageContext.Provider>,
);
expect(containerB).toBeEmptyDOMElement();
});
it('has proper accessibility attributes', () => {
const mockContext = {
failedImages: new Set(['https://example.com/image1.jpg']),
fallbackImage: 'data:image/svg+xml,...',
notifyFailure: vi.fn(),
};
render(
<FailedImageContext.Provider value={mockContext}>
<ImageFailureMessage imageUrls={['https://example.com/image1.jpg']} />
</FailedImageContext.Provider>,
);
const message = screen.getByText(/Problem loading image/i);
const container = message.closest('[role="status"]');
expect(container).toHaveAttribute('aria-live', 'polite');
});
});