Skip to content

Commit 82c8f90

Browse files
harisaurusMina Smart
authored and
Mina Smart
committed
reverse order of maxHeight and maxWidth in generated url
1 parent 2c7aa78 commit 82c8f90

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/image-helpers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export default {
1111
* @method imageForSize
1212
* @param {Object} image The original image model to generate the image src for.
1313
* @param {Object} options An options object containing:
14-
* @param {Integer} options.maxHeight The maximum height for the image.
1514
* @param {Integer} options.maxWidth The maximum width for the image.
15+
* @param {Integer} options.maxHeight The maximum height for the image.
1616
* @return {String} The image src for the resized image.
1717
*/
18-
imageForSize(image, {maxHeight, maxWidth}) {
18+
imageForSize(image, {maxWidth, maxHeight}) {
1919
const splitUrl = image.src.split('?');
2020
const notQuery = splitUrl[0];
2121
const query = splitUrl[1] ? `?${splitUrl[1]}` : '';
@@ -26,7 +26,7 @@ export default {
2626
// Take the token before the file extension and append the dimensions
2727
const imagePathIndex = imageTokens.length - 2;
2828

29-
imageTokens[imagePathIndex] = `${imageTokens[imagePathIndex]}_${maxHeight}x${maxWidth}`;
29+
imageTokens[imagePathIndex] = `${imageTokens[imagePathIndex]}_${maxWidth}x${maxHeight}`;
3030

3131
return `${imageTokens.join('.')}${query}`;
3232
}

test/image-helpers-test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ import imageHelpers from '../src/image-helpers';
33

44
suite('image-helpers-test', () => {
55
test('it returns the image src with the specified width and height', () => {
6-
const resizedImageSrc = imageHelpers.imageForSize({src: 'https://cdn.shopify.com/s/files/1/1510/7238/products/cat.jpg?v=1489515038'}, {maxWidth: 30, maxHeight: 30});
6+
const resizedImageSrc = imageHelpers.imageForSize({src: 'https://cdn.shopify.com/s/files/1/1019/0495/products/babyandco5.jpg?v=1487171332'}, {maxWidth: 280, maxHeight: 560});
77

8-
assert.equal(resizedImageSrc, 'https://cdn.shopify.com/s/files/1/1510/7238/products/cat_30x30.jpg?v=1489515038');
8+
assert.equal(resizedImageSrc, 'https://cdn.shopify.com/s/files/1/1019/0495/products/babyandco5_280x560.jpg?v=1487171332');
99
});
1010

1111
test('it returns the correct url for an image without any url params', () => {
12-
const resizedImageSrc = imageHelpers.imageForSize({src: 'https://cdn.shopify.com/s/files/1/1510/7238/products/cat.jpg'}, {maxWidth: 30, maxHeight: 30});
12+
const resizedImageSrc = imageHelpers.imageForSize({src: 'https://cdn.shopify.com/s/files/1/1019/0495/products/babyandco5.jpg'}, {maxWidth: 280, maxHeight: 560});
1313

14-
assert.equal(resizedImageSrc, 'https://cdn.shopify.com/s/files/1/1510/7238/products/cat_30x30.jpg');
14+
assert.equal(resizedImageSrc, 'https://cdn.shopify.com/s/files/1/1019/0495/products/babyandco5_280x560.jpg');
1515
});
1616

1717
test('it returns the correct url for filenames with .', () => {
18-
const resizedImageSrc = imageHelpers.imageForSize({src: 'https://cdn.shopify.com/s/files/1/1510/7238/products/cat.really.big.jpg?v=1489515038'}, {maxWidth: 30, maxHeight: 30});
18+
const resizedImageSrc = imageHelpers.imageForSize({src: 'https://cdn.shopify.com/s/files/1/1019/0495/products/Ashley.34.51031.test.jpg?v=1505141764'}, {maxWidth: 280, maxHeight: 560});
1919

20-
assert.equal(resizedImageSrc, 'https://cdn.shopify.com/s/files/1/1510/7238/products/cat.really.big_30x30.jpg?v=1489515038');
20+
assert.equal(resizedImageSrc, 'https://cdn.shopify.com/s/files/1/1019/0495/products/Ashley.34.51031.test_280x560.jpg?v=1505141764');
2121
});
2222

2323
test('it returns the correct url for an image src with . in the query param', () => {
24-
const resizedImageSrc = imageHelpers.imageForSize({src: 'https://cdn.shopify.com/s/files/1/1510/7238/products/cat.jpg?v=1.489.51.5038'}, {maxWidth: 30, maxHeight: 30});
24+
const resizedImageSrc = imageHelpers.imageForSize({src: 'https://cdn.shopify.com/s/files/1/1019/0495/products/babyandco5.jpg?v=148.71713.32'}, {maxWidth: 280, maxHeight: 560});
2525

26-
assert.equal(resizedImageSrc, 'https://cdn.shopify.com/s/files/1/1510/7238/products/cat_30x30.jpg?v=1.489.51.5038');
26+
assert.equal(resizedImageSrc, 'https://cdn.shopify.com/s/files/1/1019/0495/products/babyandco5_280x560.jpg?v=148.71713.32');
2727
});
2828
});

0 commit comments

Comments
 (0)