Skip to content

Commit

Permalink
fix: cannot toggle mode if drag disabled #147
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Aug 27, 2020
1 parent 80d4667 commit ca5c5ff
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 3 deletions.
24 changes: 24 additions & 0 deletions __tests__/tests/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1291,4 +1291,28 @@ describe('<ReactJkMusicPlayer/>', () => {
wrapper.setProps({ theme: 'auto' })
expect(wrapper.state().theme).toEqual('auto')
})

// https://github.com/lijinke666/react-music-player/issues/147
it('should toggle mode if drag disabled', () => {
const onModeChange = jest.fn()
const onCoverClick = jest.fn()
const wrapper = mount(
<ReactJkMusicPlayer
mode="mini"
drag={false}
onModeChange={onModeChange}
onCoverClick={onCoverClick}
/>,
)
expect(
wrapper.find('.react-jinke-music-player').hasClass('react-draggable'),
).toBeFalsy()
wrapper.find('.react-jinke-music-player').simulate('click')
expect(onModeChange).toHaveBeenCalledTimes(1)
expect(onCoverClick).toHaveBeenCalledTimes(1)
expect(wrapper.find('.music-player-panel')).toHaveLength(1)
expect(wrapper.state().toggle).toBeTruthy()
wrapper.find('.hide-panel').simulate('click')
expect(wrapper.state().toggle).toBeFalsy()
})
})
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"@commitlint/config-conventional": "^9.1.2",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@types/jest": "^26.0.10",
"@types/react": "^16.9.48",
"@types/react-dom": "^16.9.8",
"autoprefixer": "^9.8.6",
Expand Down
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export default class ReactJkMusicPlayer extends PureComponent {
className={cls('react-jinke-music-player')}
style={defaultPosition}
tabIndex="-1"
onClick={!drag ? this.onOpenPanel : undefined}
>
<div className={cls('music-player')}>
{showMiniProcessBar && (
Expand Down Expand Up @@ -968,8 +969,7 @@ export default class ReactJkMusicPlayer extends PureComponent {
this.loadAndPlayAudio()
this.setState({ isNeedMobileHack: false })
}
this.openPanel()
this.onCoverClick(MODE.MINI)
this.onOpenPanel()
}
this.setState({ moveX: x, moveY: y })
}
Expand Down Expand Up @@ -1008,7 +1008,7 @@ export default class ReactJkMusicPlayer extends PureComponent {
}
}

openPanel = () => {
onOpenPanel = () => {
const { toggleMode, spaceBar } = this.props
if (toggleMode) {
this.setState({ toggle: true })
Expand All @@ -1017,6 +1017,7 @@ export default class ReactJkMusicPlayer extends PureComponent {
this.player.current.focus({ preventScroll: true })
}
}
this.onCoverClick(MODE.MINI)
}

onHidePanel = () => {
Expand Down
64 changes: 64 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,16 @@
source-map "^0.6.1"
write-file-atomic "^3.0.0"

"@jest/types@^25.5.0":
version "25.5.0"
resolved "https://registry.yarnpkg.com/@jest/types/-/types-25.5.0.tgz#4d6a4793f7b9599fc3680877b856a97dbccf2a9d"
integrity sha512-OXD0RgQ86Tu3MazKo8bnrkDRaDXXMGUqd+kTtLtK1Zb7CRzQcaSRPPPV37SvYTdevXEBVxe0HXylEjs8ibkmCw==
dependencies:
"@types/istanbul-lib-coverage" "^2.0.0"
"@types/istanbul-reports" "^1.1.1"
"@types/yargs" "^15.0.0"
chalk "^3.0.0"

"@jest/types@^26.3.0":
version "26.3.0"
resolved "https://registry.yarnpkg.com/@jest/types/-/types-26.3.0.tgz#97627bf4bdb72c55346eef98e3b3f7ddc4941f71"
Expand Down Expand Up @@ -1991,13 +2001,29 @@
dependencies:
"@types/istanbul-lib-coverage" "*"

"@types/istanbul-reports@^1.1.1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-1.1.2.tgz#e875cc689e47bce549ec81f3df5e6f6f11cfaeb2"
integrity sha512-P/W9yOX/3oPZSpaYOCQzGqgCQRXn0FFO/V8bWrCQs+wLmvVVxk6CRBXALEvNs9OHIatlnlFokfhuDo2ug01ciw==
dependencies:
"@types/istanbul-lib-coverage" "*"
"@types/istanbul-lib-report" "*"

"@types/istanbul-reports@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-3.0.0.tgz#508b13aa344fa4976234e75dddcc34925737d821"
integrity sha512-nwKNbvnwJ2/mndE9ItP/zc2TCzw6uuodnF4EHYWD+gCQDVBuRQL5UzbZD0/ezy1iKsFU2ZQiDqg4M9dN4+wZgA==
dependencies:
"@types/istanbul-lib-report" "*"

"@types/jest@^26.0.10":
version "26.0.10"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.10.tgz#8faf7e9756c033c39014ae76a7329efea00ea607"
integrity sha512-i2m0oyh8w/Lum7wWK/YOZJakYF8Mx08UaKA1CtbmFeDquVhAEdA7znacsVSf2hJ1OQ/OfVMGN90pw/AtzF8s/Q==
dependencies:
jest-diff "^25.2.1"
pretty-format "^25.2.1"

"@types/json-schema@^7.0.4":
version "7.0.5"
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.5.tgz#dcce4430e64b443ba8945f0290fb564ad5bac6dd"
Expand Down Expand Up @@ -3623,6 +3649,14 @@ chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2:
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chalk@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4"
integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.0.0.tgz#6e98081ed2d17faab615eb52ac66ec1fe6209e72"
Expand Down Expand Up @@ -4914,6 +4948,11 @@ diff-match-patch@^1.0.0:
resolved "https://registry.yarnpkg.com/diff-match-patch/-/diff-match-patch-1.0.4.tgz#6ac4b55237463761c4daf0dc603eb869124744b1"
integrity sha512-Uv3SW8bmH9nAtHKaKSanOQmj2DnlH65fUpcrMdfdaOxUG02QQ4YGZ8AE7kKOMisF7UqvOlGKVYWRvezdncW9lg==

diff-sequences@^25.2.6:
version "25.2.6"
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-25.2.6.tgz#5f467c00edd35352b7bca46d7927d60e687a76dd"
integrity sha512-Hq8o7+6GaZeoFjtpgvRBUknSXNeJiCx7V9Fr94ZMljNiCr9n9L8H8aJqgWOQiDDGdyn29fRNcDdRVJ5fdyihfg==

diff-sequences@^26.3.0:
version "26.3.0"
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-26.3.0.tgz#62a59b1b29ab7fd27cef2a33ae52abe73042d0a2"
Expand Down Expand Up @@ -7961,6 +8000,16 @@ jest-config@^26.4.2:
micromatch "^4.0.2"
pretty-format "^26.4.2"

jest-diff@^25.2.1:
version "25.5.0"
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-25.5.0.tgz#1dd26ed64f96667c068cef026b677dfa01afcfa9"
integrity sha512-z1kygetuPiREYdNIumRpAHY6RXiGmp70YHptjdaxTWGmA085W3iCnXNx0DhflK3vwrKmrRWyY1wUpkPMVxMK7A==
dependencies:
chalk "^3.0.0"
diff-sequences "^25.2.6"
jest-get-type "^25.2.6"
pretty-format "^25.5.0"

jest-diff@^26.4.2:
version "26.4.2"
resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-26.4.2.tgz#a1b7b303bcc534aabdb3bd4a7caf594ac059f5aa"
Expand Down Expand Up @@ -8014,6 +8063,11 @@ jest-environment-node@^26.3.0:
jest-mock "^26.3.0"
jest-util "^26.3.0"

jest-get-type@^25.2.6:
version "25.2.6"
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-25.2.6.tgz#0b0a32fab8908b44d508be81681487dbabb8d877"
integrity sha512-DxjtyzOHjObRM+sM1knti6or+eOgcGU4xVSb2HNP1TqO4ahsT+rqZg+nyqHWJSvWgKC5cG3QjGFBqxLghiF/Ig==

jest-get-type@^26.3.0:
version "26.3.0"
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-26.3.0.tgz#e97dc3c3f53c2b406ca7afaed4493b1d099199e0"
Expand Down Expand Up @@ -11373,6 +11427,16 @@ pretty-error@^2.1.1:
renderkid "^2.0.1"
utila "~0.4"

pretty-format@^25.2.1, pretty-format@^25.5.0:
version "25.5.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-25.5.0.tgz#7873c1d774f682c34b8d48b6743a2bf2ac55791a"
integrity sha512-kbo/kq2LQ/A/is0PQwsEHM7Ca6//bGPPvU6UnsdDRSKTWxT/ru/xb88v4BJf6a69H+uTytOEsTusT9ksd/1iWQ==
dependencies:
"@jest/types" "^25.5.0"
ansi-regex "^5.0.0"
ansi-styles "^4.0.0"
react-is "^16.12.0"

pretty-format@^26.4.2:
version "26.4.2"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.4.2.tgz#d081d032b398e801e2012af2df1214ef75a81237"
Expand Down

0 comments on commit ca5c5ff

Please sign in to comment.