From e2e5f7f7a5968588c2776de20c56c8ce008347b7 Mon Sep 17 00:00:00 2001 From: Karolka Date: Thu, 19 Nov 2020 18:07:42 +0100 Subject: [PATCH] Add rating input at Create/Edit Product page (#828) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add rating input at Create/Edit Product page * Fix cypress tests Co-authored-by: Karolina Kuźniewicz Co-authored-by: Krzysztof Wolski --- cypress/elements/catalog/product-selectors.js | 2 +- cypress/integration/products.js | 4 +- locale/defaultMessages.json | 4 + src/components/messages/MessageManager.tsx | 1 + src/fragments/products.ts | 1 + src/fragments/types/Product.ts | 1 + .../components/ProductCreatePage/form.tsx | 2 + .../ProductDetailsForm/ProductDetailsForm.tsx | 22 +- .../components/ProductUpdatePage/form.tsx | 1 + src/products/fixtures.ts | 1 + .../types/ProductChannelListingUpdate.ts | 1 + src/products/types/ProductCreate.ts | 1 + src/products/types/ProductDetails.ts | 1 + src/products/types/ProductImageCreate.ts | 1 + src/products/types/ProductImageUpdate.ts | 1 + src/products/types/ProductUpdate.ts | 1 + src/products/types/ProductVariantReorder.ts | 1 + .../types/ProductVariantSetDefault.ts | 1 + src/products/types/SimpleProductUpdate.ts | 1 + src/products/utils/data.ts | 2 + src/products/views/ProductCreate/handlers.ts | 1 + src/products/views/ProductUpdate/handlers.ts | 1 + .../__snapshots__/Stories.test.ts.snap | 535 ++++++++++++++++++ 23 files changed, 582 insertions(+), 5 deletions(-) diff --git a/cypress/elements/catalog/product-selectors.js b/cypress/elements/catalog/product-selectors.js index b52e0ca0d..de68973b0 100644 --- a/cypress/elements/catalog/product-selectors.js +++ b/cypress/elements/catalog/product-selectors.js @@ -10,6 +10,6 @@ export const PRODUCTS_SELECTORS = { firstCategoryItem: "#downshift-0-item-0", visibleRadioBtn: "[name='isPublished']", saveBtn: "[data-test='button-bar-confirm']", - confirmationMsg: "[data-test='notification']", + confirmationMsg: "[data-test='notification-success']", channelAvailabilityItem: "[data-test='channel-availability-item']" }; diff --git a/cypress/integration/products.js b/cypress/integration/products.js index dd8c787a2..f4405fc44 100644 --- a/cypress/integration/products.js +++ b/cypress/integration/products.js @@ -44,9 +44,7 @@ describe("Products", () => { .click() .get(PRODUCTS_SELECTORS.saveBtn) .click() - .get(PRODUCTS_SELECTORS.confirmationMsg, { - timeout: 1000 - }) + .get(PRODUCTS_SELECTORS.confirmationMsg) .contains("Product created"); }); }); diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index 596e15ca1..6e92ebff9 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -4428,6 +4428,10 @@ "context": "product label", "string": "Published" }, + "src_dot_products_dot_components_dot_ProductDetailsForm_dot_3416636340": { + "context": "product rating", + "string": "Product Rating" + }, "src_dot_products_dot_components_dot_ProductDetailsForm_dot_636461959": { "context": "product name", "string": "Name" diff --git a/src/components/messages/MessageManager.tsx b/src/components/messages/MessageManager.tsx index fd2953607..3ebe96cc7 100644 --- a/src/components/messages/MessageManager.tsx +++ b/src/components/messages/MessageManager.tsx @@ -35,6 +35,7 @@ export const MessageManagerTemplate: React.FC = props => { className={classes.snackbarContainer} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} + data-test={`notification-${status}`} > = ({ }) => { const intl = useIntl(); - const formErrors = getFormErrors(["name", "descriptionJson"], errors); + const formErrors = getFormErrors( + ["name", "descriptionJson", "rating"], + errors + ); return ( @@ -65,6 +70,21 @@ export const ProductDetailsForm: React.FC = ({ name="description" onChange={onDescriptionChange} /> +
+ +
); diff --git a/src/products/components/ProductUpdatePage/form.tsx b/src/products/components/ProductUpdatePage/form.tsx index c83e17b4f..048151149 100644 --- a/src/products/components/ProductUpdatePage/form.tsx +++ b/src/products/components/ProductUpdatePage/form.tsx @@ -47,6 +47,7 @@ export interface ProductUpdateFormData extends MetadataFormData { collections: string[]; isAvailable: boolean; name: string; + rating: number; slug: string; seoDescription: string; seoTitle: string; diff --git a/src/products/fixtures.ts b/src/products/fixtures.ts index 39580d37a..c9b1d018b 100644 --- a/src/products/fixtures.ts +++ b/src/products/fixtures.ts @@ -263,6 +263,7 @@ export const product: ( localized: "678.78 NZD" } }, + rating: 100, seoDescription: "Seo description", seoTitle: "Seo title", sku: "59661-34207", diff --git a/src/products/types/ProductChannelListingUpdate.ts b/src/products/types/ProductChannelListingUpdate.ts index 1cb1a786d..267909c36 100644 --- a/src/products/types/ProductChannelListingUpdate.ts +++ b/src/products/types/ProductChannelListingUpdate.ts @@ -204,6 +204,7 @@ export interface ProductChannelListingUpdate_productChannelListingUpdate_product descriptionJson: any; seoTitle: string | null; seoDescription: string | null; + rating: number | null; defaultVariant: ProductChannelListingUpdate_productChannelListingUpdate_product_defaultVariant | null; category: ProductChannelListingUpdate_productChannelListingUpdate_product_category | null; collections: (ProductChannelListingUpdate_productChannelListingUpdate_product_collections | null)[] | null; diff --git a/src/products/types/ProductCreate.ts b/src/products/types/ProductCreate.ts index ce83caf3d..c1104b07b 100644 --- a/src/products/types/ProductCreate.ts +++ b/src/products/types/ProductCreate.ts @@ -211,6 +211,7 @@ export interface ProductCreate_productCreate_product { descriptionJson: any; seoTitle: string | null; seoDescription: string | null; + rating: number | null; defaultVariant: ProductCreate_productCreate_product_defaultVariant | null; category: ProductCreate_productCreate_product_category | null; collections: (ProductCreate_productCreate_product_collections | null)[] | null; diff --git a/src/products/types/ProductDetails.ts b/src/products/types/ProductDetails.ts index 0d81e2f8e..b30b22b83 100644 --- a/src/products/types/ProductDetails.ts +++ b/src/products/types/ProductDetails.ts @@ -204,6 +204,7 @@ export interface ProductDetails_product { descriptionJson: any; seoTitle: string | null; seoDescription: string | null; + rating: number | null; defaultVariant: ProductDetails_product_defaultVariant | null; category: ProductDetails_product_category | null; collections: (ProductDetails_product_collections | null)[] | null; diff --git a/src/products/types/ProductImageCreate.ts b/src/products/types/ProductImageCreate.ts index 9074d1f99..7c4ee1b69 100644 --- a/src/products/types/ProductImageCreate.ts +++ b/src/products/types/ProductImageCreate.ts @@ -210,6 +210,7 @@ export interface ProductImageCreate_productImageCreate_product { descriptionJson: any; seoTitle: string | null; seoDescription: string | null; + rating: number | null; defaultVariant: ProductImageCreate_productImageCreate_product_defaultVariant | null; category: ProductImageCreate_productImageCreate_product_category | null; collections: (ProductImageCreate_productImageCreate_product_collections | null)[] | null; diff --git a/src/products/types/ProductImageUpdate.ts b/src/products/types/ProductImageUpdate.ts index b2e8a1c3d..5d0d5a32c 100644 --- a/src/products/types/ProductImageUpdate.ts +++ b/src/products/types/ProductImageUpdate.ts @@ -210,6 +210,7 @@ export interface ProductImageUpdate_productImageUpdate_product { descriptionJson: any; seoTitle: string | null; seoDescription: string | null; + rating: number | null; defaultVariant: ProductImageUpdate_productImageUpdate_product_defaultVariant | null; category: ProductImageUpdate_productImageUpdate_product_category | null; collections: (ProductImageUpdate_productImageUpdate_product_collections | null)[] | null; diff --git a/src/products/types/ProductUpdate.ts b/src/products/types/ProductUpdate.ts index 378008e24..273518f1e 100644 --- a/src/products/types/ProductUpdate.ts +++ b/src/products/types/ProductUpdate.ts @@ -211,6 +211,7 @@ export interface ProductUpdate_productUpdate_product { descriptionJson: any; seoTitle: string | null; seoDescription: string | null; + rating: number | null; defaultVariant: ProductUpdate_productUpdate_product_defaultVariant | null; category: ProductUpdate_productUpdate_product_category | null; collections: (ProductUpdate_productUpdate_product_collections | null)[] | null; diff --git a/src/products/types/ProductVariantReorder.ts b/src/products/types/ProductVariantReorder.ts index 7fc8b77c2..2a255249e 100644 --- a/src/products/types/ProductVariantReorder.ts +++ b/src/products/types/ProductVariantReorder.ts @@ -210,6 +210,7 @@ export interface ProductVariantReorder_productVariantReorder_product { descriptionJson: any; seoTitle: string | null; seoDescription: string | null; + rating: number | null; defaultVariant: ProductVariantReorder_productVariantReorder_product_defaultVariant | null; category: ProductVariantReorder_productVariantReorder_product_category | null; collections: (ProductVariantReorder_productVariantReorder_product_collections | null)[] | null; diff --git a/src/products/types/ProductVariantSetDefault.ts b/src/products/types/ProductVariantSetDefault.ts index 1b765a784..76505e034 100644 --- a/src/products/types/ProductVariantSetDefault.ts +++ b/src/products/types/ProductVariantSetDefault.ts @@ -210,6 +210,7 @@ export interface ProductVariantSetDefault_productVariantSetDefault_product { descriptionJson: any; seoTitle: string | null; seoDescription: string | null; + rating: number | null; defaultVariant: ProductVariantSetDefault_productVariantSetDefault_product_defaultVariant | null; category: ProductVariantSetDefault_productVariantSetDefault_product_category | null; collections: (ProductVariantSetDefault_productVariantSetDefault_product_collections | null)[] | null; diff --git a/src/products/types/SimpleProductUpdate.ts b/src/products/types/SimpleProductUpdate.ts index aebfc4f61..bd50129c4 100644 --- a/src/products/types/SimpleProductUpdate.ts +++ b/src/products/types/SimpleProductUpdate.ts @@ -211,6 +211,7 @@ export interface SimpleProductUpdate_productUpdate_product { descriptionJson: any; seoTitle: string | null; seoDescription: string | null; + rating: number | null; defaultVariant: SimpleProductUpdate_productUpdate_product_defaultVariant | null; category: SimpleProductUpdate_productUpdate_product_category | null; collections: (SimpleProductUpdate_productUpdate_product_collections | null)[] | null; diff --git a/src/products/utils/data.ts b/src/products/utils/data.ts index 5b32e2fdb..e342e3da8 100644 --- a/src/products/utils/data.ts +++ b/src/products/utils/data.ts @@ -178,6 +178,7 @@ export interface ProductUpdatePageFormData extends MetadataFormData { isAvailable: boolean; name: string; slug: string; + rating: number; seoDescription: string; seoTitle: string; sku: string; @@ -208,6 +209,7 @@ export function getProductUpdatePageFormData( metadata: product?.metadata?.map(mapMetadataItemToInput), name: maybe(() => product.name, ""), privateMetadata: product?.privateMetadata?.map(mapMetadataItemToInput), + rating: maybe(() => product.rating, null), seoDescription: maybe(() => product.seoDescription, ""), seoTitle: maybe(() => product.seoTitle, ""), sku: maybe( diff --git a/src/products/views/ProductCreate/handlers.ts b/src/products/views/ProductCreate/handlers.ts index 96e26f8b5..2b1f20577 100644 --- a/src/products/views/ProductCreate/handlers.ts +++ b/src/products/views/ProductCreate/handlers.ts @@ -81,6 +81,7 @@ export function createHandler( descriptionJson: JSON.stringify(formData.description), name: formData.name, productType: formData.productType?.id, + rating: formData.rating, seo: { description: formData.seoDescription, title: formData.seoTitle diff --git a/src/products/views/ProductUpdate/handlers.ts b/src/products/views/ProductUpdate/handlers.ts index 79d439494..5a62c6744 100644 --- a/src/products/views/ProductUpdate/handlers.ts +++ b/src/products/views/ProductUpdate/handlers.ts @@ -125,6 +125,7 @@ export function createUpdateHandler( collections: data.collections, descriptionJson: JSON.stringify(data.description), name: data.name, + rating: data.rating, seo: { description: data.seoDescription, title: data.seoTitle diff --git a/src/storybook/__snapshots__/Stories.test.ts.snap b/src/storybook/__snapshots__/Stories.test.ts.snap index 1355f675f..106ac3ef9 100644 --- a/src/storybook/__snapshots__/Stories.test.ts.snap +++ b/src/storybook/__snapshots__/Stories.test.ts.snap @@ -152851,6 +152851,48 @@ exports[`Storyshots Views / Products / Create product When loading 1`] = ` class="MuiFormHelperText-root-id MuiFormHelperText-contained-id MuiFormHelperText-disabled-id" /> +
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+
+
+
+
+ +
+ + +
+