-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
562 additions
and
19 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...s/venia-concept/src/components/ProductOptions/__tests__/__snapshots__/option.spec.js.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders Option component correctly 1`] = ` | ||
<div | ||
className="root" | ||
> | ||
<h3 | ||
className="title" | ||
> | ||
<span> | ||
Color | ||
</span> | ||
</h3> | ||
<div | ||
className="root" | ||
> | ||
<button | ||
className="root" | ||
onBlur={[Function]} | ||
onClick={[Function]} | ||
onFocus={[Function]} | ||
style={ | ||
Object { | ||
"--venia-swatch-bg": "123,123,123", | ||
} | ||
} | ||
title="red" | ||
/> | ||
<button | ||
className="root" | ||
onBlur={[Function]} | ||
onClick={[Function]} | ||
onFocus={[Function]} | ||
style={ | ||
Object { | ||
"--venia-swatch-bg": "123,123,123", | ||
} | ||
} | ||
title="blue" | ||
/> | ||
</div> | ||
</div> | ||
`; |
34 changes: 34 additions & 0 deletions
34
.../venia-concept/src/components/ProductOptions/__tests__/__snapshots__/options.spec.js.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders Options component correctly 1`] = ` | ||
Array [ | ||
<div | ||
className="root" | ||
> | ||
<h3 | ||
className="title" | ||
> | ||
<span> | ||
option-1 | ||
</span> | ||
</h3> | ||
<div | ||
className="root" | ||
/> | ||
</div>, | ||
<div | ||
className="root" | ||
> | ||
<h3 | ||
className="title" | ||
> | ||
<span> | ||
option-1 | ||
</span> | ||
</h3> | ||
<div | ||
className="root" | ||
/> | ||
</div>, | ||
] | ||
`; |
89 changes: 89 additions & 0 deletions
89
...s/venia-concept/src/components/ProductOptions/__tests__/__snapshots__/swatch.spec.js.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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`appends "_focused" to className if hasFocus is true 1`] = ` | ||
<button | ||
className="root_focused" | ||
style={ | ||
Object { | ||
"--venia-swatch-bg": "123,123,123", | ||
} | ||
} | ||
title="red" | ||
/> | ||
`; | ||
|
||
exports[`appends "_selected" to className if isSelected is true 1`] = ` | ||
<button | ||
className="root_selected" | ||
style={ | ||
Object { | ||
"--venia-swatch-bg": "123,123,123", | ||
} | ||
} | ||
title="red" | ||
> | ||
<span | ||
className="root" | ||
> | ||
<svg | ||
fill="none" | ||
height="24" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
viewBox="0 0 24 24" | ||
width="24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<polyline | ||
points="20 6 9 17 4 12" | ||
/> | ||
</svg> | ||
</span> | ||
</button> | ||
`; | ||
|
||
exports[`renders a Swatch correctly 1`] = ` | ||
<button | ||
className="root" | ||
style={ | ||
Object { | ||
"--venia-swatch-bg": "123,123,123", | ||
} | ||
} | ||
title="red" | ||
/> | ||
`; | ||
|
||
exports[`renders an icon if isSelected is true 1`] = ` | ||
<button | ||
className="root_selected" | ||
style={ | ||
Object { | ||
"--venia-swatch-bg": "123,123,123", | ||
} | ||
} | ||
title="red" | ||
> | ||
<span | ||
className="root" | ||
> | ||
<svg | ||
fill="none" | ||
height="24" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
viewBox="0 0 24 24" | ||
width="24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<polyline | ||
points="20 6 9 17 4 12" | ||
/> | ||
</svg> | ||
</span> | ||
</button> | ||
`; |
20 changes: 20 additions & 0 deletions
20
...nia-concept/src/components/ProductOptions/__tests__/__snapshots__/swatchList.spec.js.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders SwatchList component correctly 1`] = ` | ||
<div | ||
className="root" | ||
> | ||
<button | ||
className="root" | ||
onBlur={[Function]} | ||
onClick={[Function]} | ||
onFocus={[Function]} | ||
style={ | ||
Object { | ||
"--venia-swatch-bg": "123,123,123", | ||
} | ||
} | ||
title="foo" | ||
/> | ||
</div> | ||
`; |
31 changes: 31 additions & 0 deletions
31
...ges/venia-concept/src/components/ProductOptions/__tests__/__snapshots__/tile.spec.js.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`appends "_focused" to className if hasFocus is true 1`] = ` | ||
<button | ||
className="root_focused" | ||
> | ||
<span> | ||
red | ||
</span> | ||
</button> | ||
`; | ||
|
||
exports[`appends "_selected" to className if isSelected is true 1`] = ` | ||
<button | ||
className="root_selected" | ||
> | ||
<span> | ||
red | ||
</span> | ||
</button> | ||
`; | ||
|
||
exports[`renders a Tile correctly 1`] = ` | ||
<button | ||
className="root" | ||
> | ||
<span> | ||
red | ||
</span> | ||
</button> | ||
`; |
18 changes: 18 additions & 0 deletions
18
...venia-concept/src/components/ProductOptions/__tests__/__snapshots__/tileList.spec.js.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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders TileList component correctly 1`] = ` | ||
<div | ||
className="root" | ||
> | ||
<button | ||
className="root" | ||
onBlur={[Function]} | ||
onClick={[Function]} | ||
onFocus={[Function]} | ||
> | ||
<span> | ||
foo | ||
</span> | ||
</button> | ||
</div> | ||
`; |
75 changes: 75 additions & 0 deletions
75
packages/venia-concept/src/components/ProductOptions/__tests__/option.spec.js
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,75 @@ | ||
import React from 'react'; | ||
import testRenderer from 'react-test-renderer'; | ||
|
||
import Option from '../option'; | ||
|
||
jest.mock('src/classify'); | ||
jest.mock('src/util/getRandomColor'); | ||
|
||
const onSelectionChangeMock = jest.fn(); | ||
const defaultProps = { | ||
attribute_id: '1', | ||
attribute_code: 'fashion_color', | ||
label: 'Color', | ||
values: [ | ||
{ | ||
label: 'red', | ||
value_index: 0 | ||
}, | ||
{ | ||
label: 'blue', | ||
value_index: 1 | ||
} | ||
] | ||
}; | ||
|
||
test('renders Option component correctly', () => { | ||
const component = testRenderer.create(<Option {...defaultProps} />); | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
test('renders a SwatchList if attribute_code prop is "fashion_color"', () => { | ||
const component = testRenderer.create(<Option {...defaultProps} />); | ||
|
||
// TODO: Is there a better way to do typeof checks for HOC wrapped things? | ||
expect( | ||
component.root.children[0].instance.listComponent.displayName | ||
).toContain('SwatchList'); | ||
}); | ||
|
||
test('renders a TileList if attribute_code prop is not "fashion_color"', () => { | ||
const props = { | ||
...defaultProps, | ||
attribute_code: 'not_fashion_color' | ||
}; | ||
const component = testRenderer.create(<Option {...props} />); | ||
|
||
// TODO: Is there a better way to do typeof checks for HOC wrapped things? | ||
expect( | ||
component.root.children[0].instance.listComponent.displayName | ||
).toContain('TileList'); | ||
}); | ||
|
||
test('does not call onSelectionChange if not provided', () => { | ||
const component = testRenderer.create(<Option {...defaultProps} />); | ||
component.root.children[0].instance.handleSelectionChange('test'); | ||
expect(onSelectionChangeMock).not.toHaveBeenCalled(); | ||
|
||
onSelectionChangeMock.mockReset(); | ||
}); | ||
|
||
test('calls onSelectionChange function with attribute_id and selection', () => { | ||
const props = { | ||
...defaultProps, | ||
onSelectionChange: onSelectionChangeMock | ||
}; | ||
const component = testRenderer.create(<Option {...props} />); | ||
|
||
component.root.children[0].instance.handleSelectionChange('test'); | ||
expect(onSelectionChangeMock).toHaveBeenCalledWith( | ||
defaultProps.attribute_id, | ||
'test' | ||
); | ||
|
||
onSelectionChangeMock.mockReset(); | ||
}); |
49 changes: 49 additions & 0 deletions
49
packages/venia-concept/src/components/ProductOptions/__tests__/options.spec.js
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,49 @@ | ||
import React from 'react'; | ||
import testRenderer from 'react-test-renderer'; | ||
|
||
import Options from '../options'; | ||
|
||
jest.mock('src/classify'); | ||
|
||
const onSelectionChangeMock = jest.fn(); | ||
const defaultProps = { | ||
options: [ | ||
{ | ||
attribute_id: '1', | ||
attribute_code: 'fashion_color', | ||
label: 'option-1', | ||
values: [] | ||
}, | ||
{ | ||
attribute_id: '2', | ||
attribute_code: '', | ||
label: 'option-1', | ||
values: [] | ||
} | ||
] | ||
}; | ||
test('renders Options component correctly', () => { | ||
const component = testRenderer.create(<Options {...defaultProps} />); | ||
expect(component.toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
test('does not call onSelectionChange if not provided', () => { | ||
const component = testRenderer.create(<Options {...defaultProps} />); | ||
component.getInstance().handleSelectionChange(0, 'test'); | ||
expect(onSelectionChangeMock).not.toHaveBeenCalled(); | ||
|
||
onSelectionChangeMock.mockReset(); | ||
}); | ||
|
||
test('calls onSelectionChange function with optionId and selection', () => { | ||
const props = { | ||
...defaultProps, | ||
onSelectionChange: onSelectionChangeMock | ||
}; | ||
const component = testRenderer.create(<Options {...props} />); | ||
|
||
component.getInstance().handleSelectionChange(0, 'test'); | ||
expect(onSelectionChangeMock).toHaveBeenCalledWith(0, 'test'); | ||
|
||
onSelectionChangeMock.mockReset(); | ||
}); |
Oops, something went wrong.