Skip to content

Commit

Permalink
test: add tests for getCldOgImageUrl (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
sccalabr authored Oct 11, 2024
1 parent 5a0ac66 commit aadeade
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
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);
});
});

0 comments on commit aadeade

Please sign in to comment.