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-11-29 10:18:58 +00:00
|
|
|
import { fireEvent, screen } from '@testing-library/vue'
|
2022-10-30 23:13:57 +00:00
|
|
|
import { socketService, volumeManager } from '@/services'
|
|
|
|
import { preferenceStore } from '@/stores'
|
2024-01-23 22:50:50 +00:00
|
|
|
import Volume from './VolumeSlider.vue'
|
2022-05-12 17:03:06 +00:00
|
|
|
|
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(() => {
|
2022-11-02 19:25:22 +00:00
|
|
|
preferenceStore.volume = 5
|
2022-10-30 23:13:57 +00:00
|
|
|
volumeManager.init(document.createElement('input'))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-12 17:03:06 +00:00
|
|
|
protected test () {
|
|
|
|
it('mutes and unmutes', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
const { html } = this.render(Volume)
|
2022-10-30 23:13:57 +00:00
|
|
|
expect(html()).toMatchSnapshot()
|
|
|
|
expect(volumeManager.volume.value).toEqual(5)
|
2022-05-12 17:03:06 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTitle('Mute'))
|
2022-10-30 23:13:57 +00:00
|
|
|
expect(html()).toMatchSnapshot()
|
|
|
|
expect(volumeManager.volume.value).toEqual(0)
|
2022-05-12 17:03:06 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.user.click(screen.getByTitle('Unmute'))
|
2022-10-30 23:13:57 +00:00
|
|
|
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')
|
2022-11-29 10:18:58 +00:00
|
|
|
this.render(Volume)
|
2022-05-12 17:03:06 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await fireEvent.update(screen.getByRole('slider'), '4.2')
|
|
|
|
await fireEvent.change(screen.getByRole('slider'))
|
2022-05-12 17:03:06 +00:00
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|