Skip to content

Commit aadeade

Browse files
authored
test: add tests for getCldOgImageUrl (#150)
1 parent 5a0ac66 commit aadeade

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

packages/docs/src/content/docs/helpers/getcldogimageurl/configuration.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ To see all available options, visit [getCldImageUrl](/helpers/getcldimageurl/con
8484
{
8585
prop: 'height',
8686
type: 'number',
87-
default: () => (<code>630</code>),
88-
example: () => (<code>630</code>),
87+
default: () => (<code>627</code>),
88+
example: () => (<code>627</code>),
8989
more: () => (<a className="whitespace-nowrap" href="https://cloudinary.com/documentation/transformation_reference#h_height">More Info</a>)
9090
},
9191

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { describe, expect, it, vi } from 'vitest';
2+
import { CldOgImage, getCldOgImageUrl } from '$src/index';
3+
import { tick } from 'svelte';
4+
5+
describe('GetCldOgImage', () => {
6+
it('should render a Cloudinary image with defualts', () => {
7+
const url = getCldOgImageUrl(
8+
{
9+
src: 'sample',
10+
},
11+
{ cloud: { cloudName: 'testing' } },
12+
);
13+
expect(url).toContain('sample');
14+
expect(url).toContain('h_627');
15+
expect(url).toContain('w_1200');
16+
expect(url).toContain('c_fill');
17+
expect(url).toContain('g_center');
18+
});
19+
20+
it('should render a Cloudinary image with the given attributes', () => {
21+
const url = getCldOgImageUrl(
22+
{
23+
src: 'sample',
24+
width: 300,
25+
height: 200,
26+
crop: { type: 'auto', gravity: 'east' },
27+
},
28+
{ cloud: { cloudName: 'testing' } },
29+
);
30+
expect(url).toContain('sample');
31+
expect(url).toContain('h_200');
32+
expect(url).toContain('w_300');
33+
expect(url).toContain('c_auto');
34+
expect(url).toContain('g_east');
35+
});
36+
37+
it('should work with global config from environment variables', () => {
38+
const cloudName = crypto.randomUUID();
39+
vi.stubEnv('VITE_CLOUDINARY_CLOUD_NAME', cloudName);
40+
41+
const url = getCldOgImageUrl({
42+
src: 'sample',
43+
});
44+
expect(url).toContain(cloudName);
45+
});
46+
});

0 commit comments

Comments
 (0)