-
Notifications
You must be signed in to change notification settings - Fork 0
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 #12 from shopgate/CCP-2192
Add product context around product cards
- Loading branch information
Showing
5 changed files
with
101 additions
and
177 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@shopgate/eslint-config" | ||
} |
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
100 changes: 22 additions & 78 deletions
100
frontend/components/PDPSlider/__snapshots__/index.spec.jsx.snap
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,87 +1,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`PDPSlider should render with price and names 1`] = ` | ||
<Provider | ||
store={ | ||
Object { | ||
"clearActions": [Function], | ||
"dispatch": [Function], | ||
"getActions": [Function], | ||
"getState": [Function], | ||
"replaceReducer": [Function], | ||
"subscribe": [Function], | ||
} | ||
} | ||
<PDPSlider | ||
productId="mockedProductId" | ||
> | ||
<Component> | ||
<PDPSlider | ||
productId="mockedProductId" | ||
> | ||
<Component | ||
headline="mockedHeadline" | ||
productId="mockedProductId" | ||
showName={true} | ||
showPrice={true} | ||
titleRows={2} | ||
type="mockedType" | ||
> | ||
<MockedDummyComponent | ||
headline="mockedHeadline" | ||
productId="mockedProductId" | ||
showName={true} | ||
showPrice={true} | ||
titleRows={2} | ||
type="mockedType" | ||
> | ||
<div> | ||
Mocked Slider | ||
</div> | ||
</MockedDummyComponent> | ||
</Component> | ||
</PDPSlider> | ||
</Component> | ||
</Provider> | ||
<Slider | ||
headline="mockedHeadline" | ||
productId="mockedProductId" | ||
showName={true} | ||
showPrice={true} | ||
titleRows={2} | ||
type="mockedType" | ||
/> | ||
</PDPSlider> | ||
`; | ||
|
||
exports[`PDPSlider should render without price and names as default 1`] = ` | ||
<Provider | ||
store={ | ||
Object { | ||
"clearActions": [Function], | ||
"dispatch": [Function], | ||
"getActions": [Function], | ||
"getState": [Function], | ||
"replaceReducer": [Function], | ||
"subscribe": [Function], | ||
} | ||
} | ||
<PDPSlider | ||
productId="mockedProductId" | ||
> | ||
<Component> | ||
<PDPSlider | ||
productId="mockedProductId" | ||
> | ||
<Component | ||
headline="mockedHeadline" | ||
productId="mockedProductId" | ||
showName={false} | ||
showPrice={false} | ||
titleRows={2} | ||
type="mockedType" | ||
> | ||
<MockedDummyComponent | ||
headline="mockedHeadline" | ||
productId="mockedProductId" | ||
showName={false} | ||
showPrice={false} | ||
titleRows={2} | ||
type="mockedType" | ||
> | ||
<div> | ||
Mocked Slider | ||
</div> | ||
</MockedDummyComponent> | ||
</Component> | ||
</PDPSlider> | ||
</Component> | ||
</Provider> | ||
<Slider | ||
headline="mockedHeadline" | ||
productId="mockedProductId" | ||
showName={false} | ||
showPrice={false} | ||
titleRows={2} | ||
type="mockedType" | ||
/> | ||
</PDPSlider> | ||
`; |
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,75 +1,50 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import configureStore from 'redux-mock-store'; | ||
import { mount } from 'enzyme'; | ||
import getConfig from '../../helpers/getConfig'; | ||
import PDPSlider from './index'; | ||
|
||
const mockedConfig = { | ||
jest.mock('react', () => ({ | ||
...jest.requireActual('react'), | ||
memo: cmp => cmp, | ||
})); | ||
let mockedShowPrice = true; | ||
let mockedShowName = true; | ||
jest.mock('../../helpers/getConfig', () => () => ({ | ||
productPage: { | ||
type: 'mockedType', | ||
headline: 'mockedHeadline', | ||
showPrice: true, | ||
showName: true, | ||
get showPrice() { return mockedShowPrice; }, | ||
get showName() { return mockedShowName; }, | ||
}, | ||
}; | ||
|
||
jest.mock('../../helpers/getConfig', () => () => mockedConfig); | ||
// eslint-disable-next-line require-jsdoc, react/prop-types | ||
const MockedDummyComponent = props => (<div>{props.children}</div>); | ||
|
||
jest.mock('../Slider', () => props => (( | ||
<MockedDummyComponent {...props}> | ||
Mocked Slider | ||
</MockedDummyComponent> | ||
))); | ||
|
||
let mockedProductId = 'mockedProductId'; | ||
jest.mock('@shopgate/pwa-common-commerce/product/selectors/product', () => ({ | ||
getCurrentBaseProductId: () => mockedProductId, | ||
})); | ||
|
||
jest.mock('@shopgate-ps/pwa-extension-kit/connectors', () => ({ | ||
withPageProductId: ({ WrappedComponent }) => props => | ||
<WrappedComponent productId={mockedProductId} {...props} />, | ||
jest.mock('../Slider', () => function Slider() { | ||
return null; | ||
}); | ||
jest.mock('../connectors', () => ({ | ||
makeConnectProductWithRelations: () => PDPSheetComponent => PDPSheetComponent, | ||
})); | ||
|
||
describe('PDPSlider', () => { | ||
// eslint-disable-next-line global-require | ||
const PDPSlider = require('./index').default; | ||
// eslint-disable-next-line require-jsdoc | ||
const makeComponent = () => mount(( | ||
<Provider store={configureStore()({})}> | ||
<PDPSlider /> | ||
</Provider> | ||
)); | ||
|
||
it('should render with price and names', () => { | ||
const component = makeComponent(); | ||
const component = mount(<PDPSlider productId="mockedProductId" />); | ||
|
||
expect(component.find('PDPSlider').props().productId).toBe(mockedProductId); | ||
expect(component.find('MockedDummyComponent').props()).toMatchObject(mockedConfig.productPage); | ||
// Component should never update once rendered something. | ||
expect(component.find('PDPSlider').instance().shouldComponentUpdate()).toBe(false); | ||
expect(component.find('PDPSlider').props().productId).toBe('mockedProductId'); | ||
expect(component.find('Slider').props()).toMatchObject(getConfig().productPage); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render without price and names as default', () => { | ||
delete mockedConfig.productPage.showName; | ||
delete mockedConfig.productPage.showPrice; | ||
const component = makeComponent(); | ||
mockedShowPrice = null; | ||
mockedShowName = null; | ||
const component = mount(<PDPSlider productId="mockedProductId" />); | ||
|
||
expect(component.find('PDPSlider').props().productId).toBe(mockedProductId); | ||
expect(component.find('MockedDummyComponent').props()).toMatchObject(mockedConfig.productPage); | ||
expect(component.find('MockedDummyComponent').props().showPrice).toBe(false); | ||
expect(component.find('MockedDummyComponent').props().showName).toBe(false); | ||
expect(component.find('Slider').props().showPrice).toBe(false); | ||
expect(component.find('Slider').props().showName).toBe(false); | ||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render nothing when productId is not ready', () => { | ||
mockedProductId = undefined; | ||
const component = makeComponent(); | ||
|
||
expect(component.html()).toBe(''); | ||
expect(component.find('PDPSlider').instance().shouldComponentUpdate()).toBe(true); | ||
expect(component.find('PDPSlider').instance().shouldComponentUpdate()).toBe(true); | ||
const component = mount(<PDPSlider />); | ||
expect(component.html()).toBe(null); | ||
}); | ||
}); |