fix: volume persisting

This commit is contained in:
Phan An 2022-11-02 15:06:53 +01:00
parent 75a6ef2107
commit b40ffa358a
No known key found for this signature in database
GPG key ID: A81E4477F0BB6FDC
2 changed files with 8 additions and 8 deletions

View file

@ -1,14 +1,14 @@
import { expect, it } from 'vitest'
import UnitTestCase from '@/__tests__/UnitTestCase'
import { volumeManager } from '@/services/volumeManager'
import { preferenceStore } from '@/stores'
import { volumeManager } from '@/services/volumeManager'
let input: HTMLInputElement
new class extends UnitTestCase {
protected beforeEach (cb?: Closure) {
super.beforeEach(() => {
preferenceStore.state.volume = 5
preferenceStore.volume = 5
input = document.createElement('input')
volumeManager.init(input)
})
@ -21,7 +21,7 @@ new class extends UnitTestCase {
volumeManager.set(4.2)
expect(volumeManager.volume.value).toEqual(4.2)
expect(input.value).toEqual('4.2')
expect(preferenceStore.state.volume).toEqual(4.2)
expect(preferenceStore.volume).toEqual(4.2)
})
it('mutes', () => {
@ -30,11 +30,11 @@ new class extends UnitTestCase {
expect(input.value).toEqual('0')
// muting should not persist
expect(preferenceStore.state.volume).toEqual(5)
expect(preferenceStore.volume).toEqual(5)
})
it('unmutes', () => {
preferenceStore.state.volume = 7
preferenceStore.volume = 7
volumeManager.unmute()
expect(volumeManager.volume.value).toEqual(7)
expect(input.value).toEqual('7')

View file

@ -7,7 +7,7 @@ export class VolumeManager {
public init (input: HTMLInputElement) {
this.input = input
this.set(preferenceStore.state.volume)
this.set(preferenceStore.volume)
}
public get () {
@ -16,7 +16,7 @@ export class VolumeManager {
public set (volume: number, persist = true) {
if (persist) {
preferenceStore.state.volume = volume
preferenceStore.volume = volume
}
this.volume.value = volume
@ -28,7 +28,7 @@ export class VolumeManager {
}
public unmute () {
this.set(preferenceStore.state.volume)
this.set(preferenceStore.volume)
}
}