Skip to content

Commit 60589ea

Browse files
committed
Added a smoke test for the UploadcareImage component.
1 parent dcb029a commit 60589ea

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
import { cleanup, render, screen } from '@testing-library/react';
5+
import React from 'react';
6+
import { UploadcareImage } from '../components/UploadcareImage';
7+
import { addEnvVar, removeEnvVar } from './utils';
8+
9+
describe('UploadcareImage', () => {
10+
beforeEach(() => {
11+
cleanup();
12+
});
13+
14+
test('The UploadcareImage component renders passed image with default settings properly', () => {
15+
addEnvVar('NEXT_PUBLIC_UPLOADCARE_PUBLIC_KEY', 'test-public-key');
16+
17+
const src =
18+
'https://ucarecdn.com/a6f8abc8-f92e-460a-b7a1-c5cd70a18cdb/vercel.png';
19+
20+
render(
21+
<UploadcareImage
22+
src={src}
23+
width={500}
24+
height={500}
25+
quality={80}
26+
alt="Test image"
27+
// Necessary because lazy-loading causes a placeholder image render first.
28+
loading="eager"
29+
/>
30+
);
31+
32+
expect(screen.getByRole('img').getAttribute('src')).toEqual(
33+
'https://ucarecdn.com/a6f8abc8-f92e-460a-b7a1-c5cd70a18cdb/-/format/auto/-/stretch/off/-/progressive/yes/-/resize/1080x/-/quality/normal/vercel.png'
34+
);
35+
36+
removeEnvVar('NEXT_PUBLIC_UPLOADCARE_PUBLIC_KEY');
37+
});
38+
});

0 commit comments

Comments
 (0)