mirror of
https://github.com/koel/koel
synced 2024-11-10 14:44:13 +00:00
feat(test): add settingStore tests
This commit is contained in:
parent
7dc16a3883
commit
7a0c05ab47
2 changed files with 22 additions and 2 deletions
19
resources/assets/js/stores/settingStore.spec.ts
Normal file
19
resources/assets/js/stores/settingStore.spec.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import { expect, it } from 'vitest'
|
||||
import UnitTestCase from '@/__tests__/UnitTestCase'
|
||||
import { settingStore } from '@/stores/settingStore'
|
||||
import { httpService } from '@/services'
|
||||
|
||||
new class extends UnitTestCase {
|
||||
protected test () {
|
||||
it('initializes the store', () => {
|
||||
settingStore.init({ media_path: '/media/path' })
|
||||
expect(settingStore.state.media_path).toEqual('/media/path')
|
||||
})
|
||||
|
||||
it('updates the media path', async () => {
|
||||
this.mock(httpService, 'put')
|
||||
await settingStore.update({ media_path: '/dev/null' })
|
||||
expect(settingStore.state.media_path).toEqual('/dev/null')
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import { reactive } from 'vue'
|
||||
import { httpService } from '@/services'
|
||||
import { merge } from 'lodash'
|
||||
|
||||
export const settingStore = {
|
||||
state: reactive<Settings>({
|
||||
|
@ -7,11 +8,11 @@ export const settingStore = {
|
|||
}),
|
||||
|
||||
init (settings: Settings) {
|
||||
Object.assign(this.state, settings)
|
||||
merge(this.state, settings)
|
||||
},
|
||||
|
||||
async update (settings: Settings) {
|
||||
await httpService.put('settings', settings)
|
||||
Object.assign(this.state, settings)
|
||||
merge(this.state, settings)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue