koel/resources/assets/js/services/volumeManager.spec.ts

39 lines
960 B
TypeScript
Raw Normal View History

import { expect, it } from 'vitest'
import UnitTestCase from '@/__tests__/UnitTestCase'
2024-04-04 22:20:42 +00:00
import { volumeManager } from '@/services'
let input: HTMLInputElement
new class extends UnitTestCase {
2024-03-18 22:04:01 +00:00
protected beforeEach () {
super.beforeEach(() => {
input = document.createElement('input')
2024-03-18 22:04:01 +00:00
volumeManager.init(input, 5)
})
}
protected test () {
it('gets volume', () => expect(volumeManager.get()).toEqual(5))
it('sets volume', () => {
volumeManager.set(4.2)
expect(volumeManager.volume.value).toEqual(4.2)
expect(input.value).toEqual('4.2')
})
it('mutes', () => {
volumeManager.mute()
expect(volumeManager.volume.value).toEqual(0)
expect(input.value).toEqual('0')
})
it('unmutes', () => {
2024-03-18 22:04:01 +00:00
volumeManager.set(7)
volumeManager.mute()
volumeManager.unmute()
expect(volumeManager.volume.value).toEqual(7)
expect(input.value).toEqual('7')
})
}
}