This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(helper): add params, update productView
- Loading branch information
Maciej Kucmus
committed
Nov 27, 2019
1 parent
d95f46b
commit f1ac5b5
Showing
9 changed files
with
110 additions
and
16 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
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
45 changes: 45 additions & 0 deletions
45
packages/helpers/__tests__/product/getProductReviews.spec.ts
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,45 @@ | ||
import { getProductReviews } from "@shopware-pwa/helpers"; | ||
|
||
describe("Shopware helpers - getProductReviews", () => { | ||
|
||
it("should return an array of UiProductReview objects", () => { | ||
const productWithReviews: any = { | ||
productReviews: [ | ||
{ | ||
id: "3858d1baf2544a379c92535ea3d2fe53", | ||
customerId: "4ac7c8a40f6bc49e24d26f0ccb15e5e6", | ||
externalUser: "Joe Doe", | ||
points: 4, | ||
content: "Great quality!", | ||
createdAt: "2019-10-08T09:42:19+00:00", | ||
}, | ||
{ | ||
id: "3f06d7747f904336a78bf75e86a64535", | ||
customerId: "3f06d7747f904336a78bf75e86a6450f", | ||
externalUser: null, | ||
points: 5, | ||
content: "I'm impressed!", | ||
createdAt: "2019-11-14T10:22:15+00:00", | ||
} | ||
] | ||
} | ||
|
||
const reviews = getProductReviews({product: productWithReviews}) | ||
expect(reviews).toHaveLength(2); | ||
const firstReview = reviews[0]; | ||
const secondReview = reviews[1]; | ||
expect(firstReview.id).toBe("3858d1baf2544a379c92535ea3d2fe53") | ||
expect(firstReview.date).toBe("2019-10-08T09:42:19+00:00") | ||
expect(firstReview.message).toBe("Great quality!") | ||
expect(firstReview.rating).toBe(4) | ||
|
||
expect(secondReview.author).toBe("3f06d7747f904336a78bf75e86a6450f") | ||
|
||
}); | ||
it("should return no reviews if do not exist", () => { | ||
const productWithoutReviews: any = {} | ||
const reviews = getProductReviews({product: productWithoutReviews}) | ||
expect(reviews).toHaveLength(0); | ||
}); | ||
|
||
}); |
23 changes: 23 additions & 0 deletions
23
packages/helpers/__tests__/product/isProductSimple.spec.ts
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,23 @@ | ||
import { isProductSimple } from "@shopware-pwa/helpers"; | ||
|
||
describe("Shopware helpers - isProductSimple", () => { | ||
|
||
it("should return true if product has a parent", () => { | ||
const productWithParent: any = { | ||
parentId: "3f06d7747f904336a78bf75e86a6450f" | ||
} | ||
|
||
const isSimple = isProductSimple({product: productWithParent}) | ||
expect(isSimple).toBe(true); | ||
|
||
}); | ||
it("should return true if product has no parent", () => { | ||
const productWithoutParent: any = { | ||
parentId: null | ||
} | ||
|
||
const isSimple = isProductSimple({product: productWithoutParent}) | ||
expect(isSimple).toBe(false); | ||
}); | ||
|
||
}); |
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
import { Product } from "@shopware-pwa/shopware-6-client"; | ||
|
||
interface Parameters { | ||
product: Product | ||
} | ||
/** | ||
* gets the cover image | ||
*/ | ||
export default function getProductMainImageUrl(product: Product): string | null { | ||
export default function getProductMainImageUrl(params: Parameters): string | null { | ||
const { product } = params | ||
return (product && product.cover && product.cover.media) ? product.cover.media.url : null | ||
} |
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import { Product } from "@shopware-pwa/shopware-6-client"; | ||
|
||
export default function isProductSimple(product: Product): boolean { | ||
interface Parameters { | ||
product: Product | ||
} | ||
|
||
export default function isProductSimple(params: Parameters): boolean { | ||
const { product } = params | ||
return !!product.parentId | ||
} |