Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ To see all available options, visit [getCldImageUrl](/helpers/getcldimageurl/con
{
prop: 'height',
type: 'number',
default: () => (<code>630</code>),
example: () => (<code>630</code>),
default: () => (<code>627</code>),
example: () => (<code>627</code>),
more: () => (<a className="whitespace-nowrap" href="https://cloudinary.com/documentation/transformation_reference#h_height">More Info</a>)
},

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { describe, expect, it, vi } from 'vitest';
import { CldOgImage, getCldOgImageUrl } from '$src/index';
import { tick } from 'svelte';

describe('GetCldOgImage', () => {
it('should render a Cloudinary image with defualts', () => {
const url = getCldOgImageUrl(
{
src: 'sample',
},
{ cloud: { cloudName: 'testing' } },
);
expect(url).toContain('sample');
expect(url).toContain('h_627');
expect(url).toContain('w_1200');
expect(url).toContain('c_fill');
expect(url).toContain('g_center');
});

it('should render a Cloudinary image with the given attributes', () => {
const url = getCldOgImageUrl(
{
src: 'sample',
width: 300,
height: 200,
crop: { type: 'auto', gravity: 'east' },
},
{ cloud: { cloudName: 'testing' } },
);
expect(url).toContain('sample');
expect(url).toContain('h_200');
expect(url).toContain('w_300');
expect(url).toContain('c_auto');
expect(url).toContain('g_east');
});

it('should work with global config from environment variables', () => {
const cloudName = crypto.randomUUID();
vi.stubEnv('VITE_CLOUDINARY_CLOUD_NAME', cloudName);

const url = getCldOgImageUrl({
src: 'sample',
});
expect(url).toContain(cloudName);
});
});