Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit e37113e

Browse files
author
george
committed
Merge branch 'develop'
2 parents c6b7cf2 + e430975 commit e37113e

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

app/components/SideNav/SideNav.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export default class SideNav extends React.Component {
1616
constructor(props) {
1717
super(props)
1818
this.handleMenuVisibility = throttle(this.handleMenuVisibility, 50)
19-
}
2019

21-
state = {
22-
menuIsOpen: window.innerWidth > MENU_COLLAPSE_WIDTH,
20+
this.state = {
21+
menuIsOpen: window.innerWidth > MENU_COLLAPSE_WIDTH,
22+
}
2323
}
2424

2525
static propTypes = {
@@ -51,6 +51,13 @@ export default class SideNav extends React.Component {
5151
Accordions.stop()
5252
}
5353

54+
componentDidUpdate(_, prevState) {
55+
if (prevState.menuIsOpen !== this.state.menuIsOpen) {
56+
Accordions.stop()
57+
Accordions.start()
58+
}
59+
}
60+
5461
handleCollapseClick = () => {
5562
if (window.innerWidth <= MENU_COLLAPSE_WIDTH) {
5663
this.setState({ menuIsOpen: false })

app/components/SideNav/__tests__/SideNav.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import React from "react"
22
import SideNav from "../SideNav"
33
import { BrowserRouter as Router } from "react-router-dom"
4+
import { Accordions } from "undernet"
45

56
jest.mock("react-feather/dist/icons/chevron-right", () => global.simpleMock("ChevronRight"))
67
jest.mock("react-feather/dist/icons/menu", () => global.simpleMock("Menu"))
78
jest.mock("projectRoot/package.json", () => ({
89
version: "9.9.9",
910
}))
1011

12+
Accordions.start = jest.fn()
13+
Accordions.stop = jest.fn()
14+
1115
const MENU_COLLAPSE_WIDTH = 1199
1216
const MENU_EXPAND_WIDTH = MENU_COLLAPSE_WIDTH + 1
1317
const DEFAULT_WIDTH = 1024
@@ -41,6 +45,21 @@ describe.only("<SideNav />", () => {
4145
})
4246
})
4347

48+
describe("#state", () => {
49+
beforeEach(() => {
50+
const wrapper = mountComponent()
51+
wrapper.find("SideNav").setState({ menuIsOpen: true })
52+
})
53+
54+
it("calls Accordions.stop if state.menuIsOpen changes", () => {
55+
expect(Accordions.stop).toHaveBeenCalled()
56+
})
57+
58+
it("calls Accordions.start if state.menuIsOpen changes", () => {
59+
expect(Accordions.start).toHaveBeenCalled()
60+
})
61+
})
62+
4463
describe("#handleMenuVisibility", () => {
4564
afterEach(() => {
4665
updatePageWidth(DEFAULT_WIDTH)

0 commit comments

Comments
 (0)