Skip to content

Commit

Permalink
fix: theme is reset to dark when audio list changed if theme is auto #…
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 committed Aug 28, 2020
1 parent 2c225da commit 7103183
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
37 changes: 23 additions & 14 deletions __tests__/tests/player.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
/* eslint-disable no-console */
import React from 'react'
import { mount, shallow } from 'enzyme'
import assert from 'power-assert'
import { shallow, mount } from 'enzyme'

import React from 'react'
import ReactJkMusicPlayer from '../../src'

import AudioListsPanel from '../../src/components/AudioListsPanel'
import CircleProcessBar from '../../src/components/CircleProcessBar'
import {
AnimatePlayIcon,
AnimatePauseIcon,
AnimatePlayIcon,
MdVolumeDownIcon,
MdVolumeMuteIcon,
} from '../../src/components/Icon'
import PlayerMobile from '../../src/components/PlayerMobile'
import PlayModel from '../../src/components/PlayModel'
import PlayModeTip from '../../src/components/PlayModeTip'
import { SPACE_BAR_KEYCODE } from '../../src/config/keycode'
import { MEDIA_QUERY } from '../../src/config/mediaQuery'
import {
createRandomNum,
formatTime,
arrayEqual,
createRandomNum,
distinct,
formatTime,
} from '../../src/utils'
import PlayerMobile from '../../src/components/PlayerMobile'
import PlayModeTip from '../../src/components/PlayModeTip'
import AudioListsPanel from '../../src/components/AudioListsPanel'
import PlayModel from '../../src/components/PlayModel'
import CircleProcessBar from '../../src/components/CircleProcessBar'
import { SPACE_BAR_KEYCODE } from '../../src/config/keycode'
import { sleep } from '../utils'
import { MEDIA_QUERY } from '../../src/config/mediaQuery'

describe('<ReactJkMusicPlayer/>', () => {
it('should render a <ReactJkMusicPlayer/> components', () => {
Expand Down Expand Up @@ -1337,4 +1335,15 @@ describe('<ReactJkMusicPlayer/>', () => {
expect(wrapper.find('.music-player-panel')).toHaveLength(0)
expect(wrapper.state().toggle).toBeFalsy()
})

// https://github.com/lijinke666/react-music-player/issues/149
it('should not change theme to dark when audio list changed if theme is auto', () => {
const wrapper = mount(<ReactJkMusicPlayer theme="auto" />)
wrapper.setProps({
audioList: [{ musicSrc: 'xxx', name: 'xxx' }],
clearPriorAudioLists: true,
})
wrapper.update()
expect(wrapper.state().theme).toEqual('light')
})
})
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1787,10 +1787,13 @@ export default class ReactJkMusicPlayer extends PureComponent {
? this.getLastPlayStatus()
: {
playMode: playMode || PLAY_MODE.order,
theme,
playIndex: playIndex || 0,
}

if (theme !== THEME.AUTO) {
lastPlayStatus.theme = theme
}

const audioInfo = {
...info,
...lastPlayStatus,
Expand All @@ -1812,6 +1815,7 @@ export default class ReactJkMusicPlayer extends PureComponent {
break
default:
this.setState(audioInfo, () => {
// 预加载, 防止非自动播放, 直接点击播放列表无法播放的情况
this.audio.load()
})
}
Expand Down

0 comments on commit 7103183

Please sign in to comment.