mirror of
https://github.com/koel/koel
synced 2024-12-13 06:02:27 +00:00
31 lines
1,002 B
TypeScript
31 lines
1,002 B
TypeScript
import { expect, it } from 'vitest'
|
|
import factory from '@/__tests__/factory'
|
|
import { localStorageService } from '@/services'
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
import { preferenceStore } from '.'
|
|
|
|
new class extends UnitTestCase {
|
|
protected beforeEach () {
|
|
super.beforeEach(() => preferenceStore.init(factory<User>('user', { id: 1 })))
|
|
}
|
|
|
|
protected test () {
|
|
it('sets preferences', () => {
|
|
const mock = this.mock(localStorageService, 'set')
|
|
preferenceStore.set('volume', 5)
|
|
expect(mock).toHaveBeenCalledWith('preferences_1', expect.objectContaining({ volume: 5 }))
|
|
|
|
// test the proxy
|
|
preferenceStore.volume = 6
|
|
expect(mock).toHaveBeenCalledWith('preferences_1', expect.objectContaining({ volume: 6 }))
|
|
})
|
|
|
|
it('returns preference values', () => {
|
|
preferenceStore.set('volume', 4.2)
|
|
expect(preferenceStore.get('volume')).toBe(4.2)
|
|
|
|
// test the proxy
|
|
expect(preferenceStore.volume).toBe(4.2)
|
|
})
|
|
}
|
|
}
|