From d00c8fc91688ce7231bead09d6aaab901d385a45 Mon Sep 17 00:00:00 2001 From: "O.Bilenko" Date: Fri, 30 Aug 2019 15:28:17 +0200 Subject: [PATCH] PWA-2230 In many cases it's not possible to put items with options into cart --- .../Product/components/Content/index.jsx | 4 +++ .../pages/Product/components/Content/spec.jsx | 33 ++++++++++++++++--- .../Product/components/Content/index.jsx | 4 +++ .../pages/Product/components/Content/spec.jsx | 32 ++++++++++++++---- 4 files changed, 62 insertions(+), 11 deletions(-) diff --git a/themes/theme-gmd/pages/Product/components/Content/index.jsx b/themes/theme-gmd/pages/Product/components/Content/index.jsx index f802836a09..8eb812135c 100644 --- a/themes/theme-gmd/pages/Product/components/Content/index.jsx +++ b/themes/theme-gmd/pages/Product/components/Content/index.jsx @@ -80,6 +80,10 @@ class ProductContent extends PureComponent { variantId, currency: nextProps.currency, quantity: 1, + ...productIdChanged && { + options: {}, + optionsPrices: {}, + }, }); } diff --git a/themes/theme-gmd/pages/Product/components/Content/spec.jsx b/themes/theme-gmd/pages/Product/components/Content/spec.jsx index 5e31bf3c6b..9a46959b4e 100644 --- a/themes/theme-gmd/pages/Product/components/Content/spec.jsx +++ b/themes/theme-gmd/pages/Product/components/Content/spec.jsx @@ -2,8 +2,13 @@ import React from 'react'; import { shallow } from 'enzyme'; import Content from './index'; +jest.mock('@shopgate/engage/a11y', () => ({ + Section: () => null, +})); + jest.mock('@shopgate/engage/product', () => ({ ProductProperties: () => null, + RelationsSlider: () => null, })); jest.mock('@shopgate/pwa-core', () => ({ @@ -22,14 +27,32 @@ jest.mock('Components/Reviews', () => () => null); jest.mock('./connector', () => Component => Component); describe('Product / Content', () => { + const expectedContext = { + productId: 'SG100', + quantity: 1, + options: {}, + optionsPrices: {}, + }; + it('should provide correct context value', () => { const wrapper = shallow(); + expect(wrapper.find('ContextProvider').prop('value')).toEqual(expect.objectContaining(expectedContext)); + }); + + it('should reset options on product update', () => { + const wrapper = shallow(); - const expected = expect.objectContaining({ - productId: 'SG100', - quantity: 1, - }); + wrapper.update(wrapper.instance().setOption('op1', 'OP_V', 0)); + expect(wrapper.find('ContextProvider').prop('value')).toEqual(expect.objectContaining({ + ...expectedContext, + options: { op1: 'OP_V' }, + optionsPrices: { op1: 0 }, + })); - expect(wrapper.find('ContextProvider').prop('value')).toEqual(expected); + wrapper.update(wrapper.setProps({ productId: 'SG200' })); + expect(wrapper.find('ContextProvider').prop('value')).toEqual(expect.objectContaining({ + ...expectedContext, + productId: 'SG200', + })); }); }); diff --git a/themes/theme-ios11/pages/Product/components/Content/index.jsx b/themes/theme-ios11/pages/Product/components/Content/index.jsx index 20725c0a84..6dd4c94bee 100644 --- a/themes/theme-ios11/pages/Product/components/Content/index.jsx +++ b/themes/theme-ios11/pages/Product/components/Content/index.jsx @@ -81,6 +81,10 @@ class ProductContent extends PureComponent { variantId, currency: nextProps.currency, quantity: 1, + ...productIdChanged && { + options: {}, + optionsPrices: {}, + }, }); } diff --git a/themes/theme-ios11/pages/Product/components/Content/spec.jsx b/themes/theme-ios11/pages/Product/components/Content/spec.jsx index 4aec1b29e2..67e39d826c 100644 --- a/themes/theme-ios11/pages/Product/components/Content/spec.jsx +++ b/themes/theme-ios11/pages/Product/components/Content/spec.jsx @@ -2,8 +2,12 @@ import React from 'react'; import { shallow } from 'enzyme'; import Content from './index'; +jest.mock('@shopgate/engage/a11y', () => ({ + Section: () => null, +})); jest.mock('@shopgate/engage/product', () => ({ ProductProperties: () => null, + RelationsSlider: () => null, })); jest.mock('@shopgate/pwa-core', () => ({ @@ -23,14 +27,30 @@ jest.mock('Components/Reviews', () => () => null); jest.mock('./connector', () => Component => Component); describe('Product / Content', () => { + const expectedContext = { + productId: 'SG100', + quantity: 1, + options: {}, + optionsPrices: {}, + }; + it('should provide correct context value', () => { const wrapper = shallow(); + expect(wrapper.find('ContextProvider').prop('value')).toEqual(expect.objectContaining(expectedContext)); + }); - const expected = expect.objectContaining({ - productId: 'SG100', - quantity: 1, - }); - - expect(wrapper.find('ContextProvider').prop('value')).toEqual(expected); + it('should reset options on product update', () => { + const wrapper = shallow(); + wrapper.update(wrapper.instance().setOption('op1', 'OP_V', 0)); + expect(wrapper.find('ContextProvider').prop('value')).toEqual(expect.objectContaining({ + ...expectedContext, + options: { op1: 'OP_V' }, + optionsPrices: { op1: 0 }, + })); + wrapper.update(wrapper.setProps({ productId: 'SG200' })); + expect(wrapper.find('ContextProvider').prop('value')).toEqual(expect.objectContaining({ + ...expectedContext, + productId: 'SG200', + })); }); });