Skip to content

Commit

Permalink
Update Menu contents when root property changes (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevhender authored May 12, 2020
1 parent a224654 commit e0c14f4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-storefront",
"version": "8.0.0",
"version": "8.0.1",
"description": "Build and deploy e-commerce progressive web apps (PWAs) in record time.",
"module": "./index.js",
"license": "Apache-2.0",
Expand Down
7 changes: 7 additions & 0 deletions src/menu/Menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ const Menu = React.memo(props => {
stateRef.current = state
}, [state])

useEffect(() => {
setState({
card: 0,
cards: [{ ...root, root: true }],
})
}, [root])

// this ensures that the expanded state is reset when showing a new card
const nextKey = useRef(0)

Expand Down
26 changes: 26 additions & 0 deletions test/menu/Menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,32 @@ describe('Menu', () => {
expect(wrapper.find(ListItem).length).toBe(3)
})

it('should update contents when root property is updated', () => {
wrapper = mount(
<Menu
root={{
items: [
{ text: 'item1', href: '/item1', as: '/item1', items: [] },
{ text: 'item2', href: '/item2', as: '/item2' },
{ text: 'item3', href: '/item3', as: '/item3' },
],
}}
/>,
)
wrapper.setProps({
root: {
items: [
{ text: 'item1', href: '/item1', as: '/item1' },
{ text: 'item2', href: '/item2', as: '/item2' },
{ text: 'item3', href: '/item3', as: '/item3' },
{ text: 'item4', href: '/item4', as: '/item4' },
],
},
})
wrapper.update()
expect(wrapper.find(ListItem).length).toBe(4)
})

it('should use menu back to come back from submenu', () => {
wrapper = mount(
<Menu
Expand Down

0 comments on commit e0c14f4

Please sign in to comment.