Skip to content

Commit

Permalink
Merge pull request #821 from shopgate/PWA-2230-variant-options
Browse files Browse the repository at this point in the history
Reset selected options of product context, when changing a product on Product details page
  • Loading branch information
devbucket committed Sep 2, 2019
2 parents 92ed72d + 441e089 commit ad88b7f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 11 deletions.
4 changes: 4 additions & 0 deletions themes/theme-gmd/pages/Product/components/Content/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ class ProductContent extends PureComponent {
variantId,
currency: nextProps.currency,
quantity: 1,
...productIdChanged && {
options: {},
optionsPrices: {},
},
});
}

Expand Down
33 changes: 28 additions & 5 deletions themes/theme-gmd/pages/Product/components/Content/spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand All @@ -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(<Content productId="SG100" />);
expect(wrapper.find('ContextProvider').prop('value')).toEqual(expect.objectContaining(expectedContext));
});

it('should reset options on product update', () => {
const wrapper = shallow(<Content productId="SG100" />);

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',
}));
});
});
4 changes: 4 additions & 0 deletions themes/theme-ios11/pages/Product/components/Content/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class ProductContent extends PureComponent {
variantId,
currency: nextProps.currency,
quantity: 1,
...productIdChanged && {
options: {},
optionsPrices: {},
},
});
}

Expand Down
32 changes: 26 additions & 6 deletions themes/theme-ios11/pages/Product/components/Content/spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand All @@ -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(<Content productId="SG100" />);
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(<Content productId="SG100" />);
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',
}));
});
});

0 comments on commit ad88b7f

Please sign in to comment.