Add tests for settings.vue

This commit is contained in:
Phan An 2017-12-16 23:57:32 +01:00
parent 648fc9f232
commit fac40bc501
4 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,39 @@
import Component from '@/components/main-wrapper/main-content/settings.vue'
import { sharedStore, settingStore } from '@/stores'
import { alerts } from '@/utils'
describe('components/main-wrapper/main-content/settings', () => {
beforeEach(() => {
settingStore.state = {
settings: {
media_path: '/foo/'
}
}
})
it('renders a settings form', () => {
const wrapper = shallow(Component)
wrapper.findAll('form').should.have.lengthOf(1)
})
it('warns if changing a non-empty media path', () => {
sharedStore.state.originalMediaPath = '/bar'
const wrapper = shallow(Component)
const stub = sinon.stub(alerts, 'confirm')
wrapper.find('form').trigger('submit')
stub.called.should.be.true
stub.restore()
})
it("doesn't warn if changing an empty media path", () => {
sharedStore.state.originalMediaPath = ''
const wrapper = shallow(Component)
const confirmStub = sinon.stub(alerts, 'confirm')
const updateStub = sinon.stub(settingStore, 'update')
wrapper.find('form').trigger('submit')
confirmStub.called.should.be.false
updateStub.called.should.be.true
confirmStub.restore()
updateStub.restore()
})
})

View file

@ -19,6 +19,10 @@ export function loadMainView (view, ...args) {
* This is handy for certain cases, for example Last.fm connect/disconnect.
*/
export function forceReloadWindow () {
if (window.__UNIT_TESTING__) {
return
}
window.onbeforeunload = function () {}
window.location.reload()
}