Skip to content

Commit

Permalink
fix: auto play when audio list changed if autoplayInitLoadPlayList is…
Browse files Browse the repository at this point in the history
… false #154
  • Loading branch information
lijinke666 committed Aug 30, 2020
1 parent 2500d17 commit 3f08c70
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions __tests__/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ global.document = window.document
global.navigator = {
userAgent: 'node.js',
}
global.URL.createObjectURL = jest.fn()
if (typeof window !== 'undefined') {
global.window.resizeTo = (width, height) => {
global.window.innerWidth = width || global.window.innerWidth
Expand All @@ -33,6 +34,7 @@ if (typeof window !== 'undefined') {
global.window.HTMLMediaElement.prototype.load = () => {}
global.window.HTMLMediaElement.prototype.play = () => {}
global.window.HTMLMediaElement.prototype.pause = () => {}
global.window.URL.createObjectURL = jest.fn()
}

Enzyme.configure({ adapter: new Adapter() })
10 changes: 10 additions & 0 deletions __tests__/tests/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,4 +1346,14 @@ describe('<ReactJkMusicPlayer/>', () => {
wrapper.update()
expect(wrapper.state().theme).toEqual('light')
})

it('should cannot set isAutoPlayWhenUserClicked to true if audioList updated', () => {
const wrapper = mount(
<ReactJkMusicPlayer autoPlay={false} clearPriorAudioLists />,
)
wrapper.setProps({
audioLists: [{ musicSrc: 'xxx', name: 'xxx' }],
})
expect(wrapper.state().isAutoPlayWhenUserClicked).toBeFalsy()
})
})
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,7 @@ export default class ReactJkMusicPlayer extends PureComponent {
this.audioListsPlay(currentPlay.id, true)
}
}
this.setState({ isAutoPlayWhenUserClicked: false })
}

playByIndex = (index) => {
Expand Down

0 comments on commit 3f08c70

Please sign in to comment.