2022-05-12 17:03:06 +00:00
|
|
|
import { expect, it } from 'vitest'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-12 17:03:06 +00:00
|
|
|
import { fireEvent } from '@testing-library/vue'
|
2022-10-30 23:13:57 +00:00
|
|
|
import { socketService, volumeManager } from '@/services'
|
|
|
|
import { preferenceStore } from '@/stores'
|
2022-05-12 17:03:06 +00:00
|
|
|
import Volume from './Volume.vue'
|
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-10-30 23:13:57 +00:00
|
|
|
protected beforeEach (cb?: Closure) {
|
|
|
|
super.beforeEach(() => {
|
|
|
|
preferenceStore.state.volume = 5
|
|
|
|
volumeManager.init(document.createElement('input'))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-12 17:03:06 +00:00
|
|
|
protected test () {
|
|
|
|
it('mutes and unmutes', async () => {
|
2022-10-30 23:13:57 +00:00
|
|
|
const { getByTitle, html } = this.render(Volume)
|
|
|
|
expect(html()).toMatchSnapshot()
|
|
|
|
expect(volumeManager.volume.value).toEqual(5)
|
2022-05-12 17:03:06 +00:00
|
|
|
|
2022-10-30 23:13:57 +00:00
|
|
|
await fireEvent.click(getByTitle('Mute'))
|
|
|
|
expect(html()).toMatchSnapshot()
|
|
|
|
expect(volumeManager.volume.value).toEqual(0)
|
2022-05-12 17:03:06 +00:00
|
|
|
|
2022-10-30 23:13:57 +00:00
|
|
|
await fireEvent.click(getByTitle('Unmute'))
|
|
|
|
expect(html()).toMatchSnapshot()
|
|
|
|
expect(volumeManager.volume.value).toEqual(5)
|
2022-05-12 17:03:06 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('sets and broadcasts volume', async () => {
|
2022-10-30 23:13:57 +00:00
|
|
|
const setMock = this.mock(volumeManager, 'set')
|
2022-05-12 17:03:06 +00:00
|
|
|
const broadCastMock = this.mock(socketService, 'broadcast')
|
|
|
|
const { getByRole } = this.render(Volume)
|
|
|
|
|
|
|
|
await fireEvent.update(getByRole('slider'), '4.2')
|
|
|
|
await fireEvent.change(getByRole('slider'))
|
|
|
|
|
2022-10-30 23:13:57 +00:00
|
|
|
expect(setMock).toHaveBeenCalledWith(4.2)
|
2022-05-12 17:03:06 +00:00
|
|
|
expect(broadCastMock).toHaveBeenCalledWith('SOCKET_VOLUME_CHANGED', 4.2)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|