Skip to content

Commit

Permalink
More comments
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyZhang777 committed Apr 27, 2024
1 parent 40214ce commit 9f56d4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions static/js/formatters-internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ export function joinList(list, separator) {
* preserving the aspect ratio. In other words, both dimensions will either match or be smaller
* than the desired dimensions (e.g. if original image is 100x100, returns an image of 100x100).
*
* If only one dimension is provided in desiredSize (e.g. "200x", which is also the default):
* If only one dimension is provided in desiredSize (e.g. "200x", which is also the default, or
* "200x0"):
* - returns an image that matches this dimension while preserving ratio of the original image
* (e.g. if original image is 100x100, returned image would be 200x200).
*
Expand Down Expand Up @@ -365,7 +366,7 @@ export function image(simpleOrComplexImage = {}, desiredSize = '200x', atLeastAs
* (e.g. 'height=200,width=100,fit=contain')
*/
function _getImageFormatOptions(desiredSize, atLeastAsLarge, fullSizeWidth, fullSizeHeight) {
let desiredDims = desiredSize.split('x');
const desiredDims = desiredSize.split('x');
const desiredWidth = desiredDims[0] ? Number.parseInt(desiredDims[0]) : 0;
if (Number.isNaN(desiredWidth)) {
throw new Error("Invalid width specified");
Expand Down
12 changes: 10 additions & 2 deletions tests/static/js/formatters-internal/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ describe('image formatter', () => {
expect(photoImgUrl).toEqual('https://dyn.mktgcdn.com/p/FOO/fit=contain,width=1000,height=200');
const photoWithPaddingImgUrl = Formatters.image({url: photoWithPaddingUrl, width: 0}, '1000x200', false).url;
expect(photoWithPaddingImgUrl).toEqual('https://dyn.mktgcdn.com/p/FOO/1.0000/fit=contain,width=1000,height=200');
const oldFileImgUrl = Formatters.image({url: oldFileUrl, height: 100}, '200x500', false).url;
const oldFileImgUrl = Formatters.image({url: oldFileUrl, width: undefined}, '200x500', false).url;
expect(oldFileImgUrl).toEqual('https://dyn.mktgcdn.com/f/0/FOO.jpg/fit=contain,width=200,height=500');
const newFileImgUrl = Formatters.image({url: newFileUrl, height: 0}, '3000x2000', false).url;
expect(newFileImgUrl).toEqual('https://dyn.mktgcdn.com/f/FOO.jpg/fit=contain,width=3000,height=2000');
const euFileImgUrl = Formatters.image({url: euFileUrl, height: undefined}, '3000x3000', false).url;
const euFileImgUrl = Formatters.image({url: euFileUrl, width: 0, height: 0}, '3000x3000', false).url;
expect(euFileImgUrl).toEqual('https://dyn.eu.mktgcdn.com/f/0/FOO.jpg/fit=contain,width=3000,height=3000');
});
});
Expand Down Expand Up @@ -177,5 +177,13 @@ describe('image formatter', () => {
it('throws an error', () => {
expect(() => {Formatters.image(photoImg, 'ax')}).toThrowError();
});

it('throws an error', () => {
expect(() => {Formatters.image(photoImg, 'xa')}).toThrowError();
});

it('throws an error', () => {
expect(() => {Formatters.image(photoImg, '')}).toThrowError();
});
});
});

0 comments on commit 9f56d4c

Please sign in to comment.