Skip to content

Commit

Permalink
feat: add restart on prev test
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed May 7, 2021
1 parent d18048a commit 924841a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 39 deletions.
23 changes: 23 additions & 0 deletions __tests__/tests/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1858,4 +1858,27 @@ describe('<ReactJkMusicPlayer/>', () => {
expect(wrapper.state('isResetCoverRotate')).toBeFalsy()
})
})
it('should reset audio current time to zero if prev audio button clicked', async () => {
const onPlayIndexChange = jest.fn()
const wrapper = mount(
<ReactJkMusicPlayer
restartCurrentOnPrev
mode="full"
onPlayIndexChange={onPlayIndexChange}
/>,
)
window.HTMLMediaElement.prototype.currentTime = 0
wrapper.find('.prev-audio').simulate('click')
await sleep(100)

expect(onPlayIndexChange).toHaveBeenCalledTimes(1)

window.HTMLMediaElement.prototype.currentTime = 1
wrapper.find('.prev-audio').simulate('click')
await sleep(100)

expect(window.HTMLMediaElement.prototype.currentTime).toEqual(0)

expect(onPlayIndexChange).toHaveBeenCalledTimes(1)
})
})
3 changes: 1 addition & 2 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const options = {
fadeIn: 1000,
fadeOut: 1000,
},
/**
/**
* Restarts the current track when trying to play previous song, if the current time of the song is more than 1 second
Otherwise, plays the previous song in the list
[type `Boolean` default `false`]
Expand Down Expand Up @@ -616,7 +616,6 @@ class Demo extends React.PureComponent {
renderCustomAudioTitle = () => {
this.updateParams({
renderAudioTitle: (audioInfo, isMobile) => {
console.log('audioInfo: ', audioInfo, isMobile)
return (
<>
<a href="#">{audioInfo.name}</a>
Expand Down
74 changes: 37 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@
],
"dependencies": {
"@react-icons/all-files": "^4.1.0",
"classnames": "^2.2.6",
"classnames": "^2.3.1",
"downloadjs": "^1.4.7",
"is-mobile": "^2.2.2",
"prop-types": "^15.7.2",
"rc-slider": "^9.7.1",
"rc-slider": "^9.7.2",
"rc-switch": "^3.2.2",
"react-draggable": "^4.4.3",
"sortablejs": "^1.13.0"
Expand All @@ -116,23 +116,23 @@
}
],
"devDependencies": {
"@babel/cli": "7.12.17",
"@babel/core": "7.12.17",
"@babel/plugin-proposal-class-properties": "7.12.13",
"@babel/plugin-proposal-object-rest-spread": "7.12.13",
"@babel/cli": "7.13.16",
"@babel/core": "7.14.0",
"@babel/plugin-proposal-class-properties": "7.13.0",
"@babel/plugin-proposal-object-rest-spread": "7.13.8",
"@babel/plugin-syntax-dynamic-import": "7.8.3",
"@babel/plugin-syntax-object-rest-spread": "7.8.3",
"@babel/plugin-transform-object-assign": "7.12.13",
"@babel/plugin-transform-runtime": "^7.12.17",
"@babel/preset-env": "7.12.17",
"@babel/preset-react": "^7.12.13",
"@babel/runtime": "7.12.18",
"@commitlint/config-conventional": "^11.0.0",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "7.14.1",
"@babel/preset-react": "^7.13.13",
"@babel/runtime": "7.14.0",
"@commitlint/config-conventional": "^12.1.1",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@types/jest": "^26.0.20",
"@types/jest": "^26.0.23",
"@types/sortablejs": "^1.10.6",
"autoprefixer": "^10.2.4",
"autoprefixer": "^10.2.5",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.3",
Expand All @@ -141,40 +141,40 @@
"babel-plugin-transform-runtime": "^6.23.0",
"bundlesize": "^0.18.1",
"clean-webpack-plugin": "^3.0.0",
"codecov": "^3.8.1",
"codecov": "^3.8.2",
"commitizen": "^4.2.3",
"commitlint": "^11.0.0",
"commitlint": "^12.1.1",
"copy-webpack-plugin": "latest",
"coveralls": "^3.1.0",
"cross-env": "^7.0.3",
"css-loader": "^5.0.2",
"css-minimizer-webpack-plugin": "^1.2.0",
"css-loader": "^5.2.4",
"css-minimizer-webpack-plugin": "^2.0.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"enzyme-to-json": "^3.6.1",
"enzyme-to-json": "^3.6.2",
"esbuild-webpack-plugin": "^1.1.0",
"eslint": "^7.20.0",
"eslint": "^7.25.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^7.2.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-babel": "^5.3.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jest": "^24.1.5",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.23.2",
"file-loader": "^6.2.0",
"html-loader": "^2.0.0",
"html-webpack-plugin": "^5.1.0",
"html-loader": "^2.1.2",
"html-webpack-plugin": "^5.3.1",
"husky": "^5.0.9",
"jest": "^26.6.3",
"jest-environment-jsdom": "^26.6.2",
"jsdom": "^16.4.0",
"jsdom": "^16.5.3",
"less": "^4.1.1",
"less-loader": "^8.0.0",
"less-loader": "^8.1.1",
"lint-staged": "^10.5.4",
"mini-css-extract-plugin": "^1.3.8",
"postcss": "^8.2.6",
"postcss-loader": "^5.0.0",
"mini-css-extract-plugin": "^1.6.0",
"postcss": "^8.2.14",
"postcss-loader": "^5.2.0",
"power-assert": "^1.6.1",
"pre-commit": "^1.2.2",
"prettier": "^2.2.1",
Expand All @@ -184,16 +184,16 @@
"react-hot-loader": "^4.13.0",
"react-loader": "^2.4.7",
"rimraf": "^3.0.2",
"semantic-release": "^17.3.9",
"semantic-release": "^17.4.2",
"style-loader": "~2.0.0",
"stylelint": "^13.10.0",
"stylelint": "^13.13.1",
"stylelint-config-prettier": "^8.0.2",
"stylelint-config-standard": "^20.0.0",
"stylelint-config-standard": "^22.0.0",
"uglifyjs-webpack-plugin": "^2.2.0",
"webpack": "^5.23.0",
"webpack-bundle-analyzer": "^4.4.0",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.11.2"
"webpack": "^5.36.2",
"webpack-bundle-analyzer": "^4.4.1",
"webpack-cli": "^4.7.0",
"webpack-dev-server": "4.0.0-beta.3"
},
"peerDependencies": {
"react": ">=16.9.0",
Expand Down

0 comments on commit 924841a

Please sign in to comment.