-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Kazuki-tam/feature/img_url-filter
Feature/img url filter
- Loading branch information
Showing
7 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { imgUrl } from '../imgUrl'; | ||
|
||
const productItem = { | ||
image: '/assets/product/product_cropped_img.jpg', | ||
product: { | ||
title: 'Aviator sunglasses', | ||
}, | ||
quantity: 1, | ||
refunded_quantity: 0, | ||
original_line_price: 200, | ||
original_price: 200, | ||
final_line_price: 200, | ||
final_price: 200, | ||
line_price: 200, | ||
title: 'Aviator sunglasses', | ||
}; | ||
|
||
/** | ||
* Shopify img_url filter test | ||
*/ | ||
|
||
test('Generates Image URL from a character string', () => { | ||
expect(imgUrl('/assets/product/product_cropped_img.jpg')).toBe( | ||
'/assets/product/product_cropped_img.jpg', | ||
); | ||
}); | ||
|
||
test('Generates Image URL from a product object', () => { | ||
expect(imgUrl(productItem)).toBe('/assets/product/product_cropped_img.jpg'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { ProductType } from '@/types/product'; | ||
|
||
/** | ||
* img_url filter | ||
* @param { ProductType } productItem - Target url or Object | ||
* @returns { string } - Formatted url | ||
* https://shopify.dev/api/liquid/filters/img_url | ||
*/ | ||
|
||
const imgUrl = (productItem: ProductType | string): string | undefined => { | ||
let url; | ||
if (typeof productItem === 'object') { | ||
url = productItem.image; | ||
} | ||
if (typeof productItem === 'string') { | ||
url = productItem; | ||
} | ||
return url; | ||
}; | ||
|
||
export { imgUrl }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
type ProductType = { | ||
image: string; | ||
product: { | ||
title: string; | ||
}; | ||
quantity: number; | ||
refunded_quantity: number; | ||
original_line_price: number; | ||
original_price: number; | ||
final_line_price: number; | ||
final_price: number; | ||
line_price: number; | ||
title: string; | ||
}; | ||
|
||
export { ProductType }; |