2024-03-18 22:04:01 +00:00
|
|
|
import { expect, it, vi } from 'vitest'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2024-04-04 22:20:42 +00:00
|
|
|
import { fireEvent, screen } from '@testing-library/vue'
|
2022-10-30 23:13:57 +00:00
|
|
|
import { socketService, volumeManager } from '@/services'
|
2024-01-23 22:50:50 +00:00
|
|
|
import Volume from './VolumeSlider.vue'
|
2024-03-18 22:04:01 +00:00
|
|
|
import { preferenceStore } from '@/stores'
|
2022-05-12 17:03:06 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2024-03-18 22:04:01 +00:00
|
|
|
protected beforeEach () {
|
2022-10-30 23:13:57 +00:00
|
|
|
super.beforeEach(() => {
|
2024-03-18 22:04:01 +00:00
|
|
|
vi.useFakeTimers()
|
2022-11-02 19:25:22 +00:00
|
|
|
preferenceStore.volume = 5
|
2022-10-30 23:13:57 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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 () => {
|
2024-03-18 22:04:01 +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')
|
2024-03-18 22:04:01 +00:00
|
|
|
vi.runAllTimers()
|
2022-05-12 17:03:06 +00:00
|
|
|
|
2024-03-18 22:04:01 +00:00
|
|
|
expect(volumeManager.volume.value).toBe(4.2)
|
|
|
|
expect(broadcastMock).toHaveBeenCalledWith('SOCKET_VOLUME_CHANGED', 4.2)
|
2022-05-12 17:03:06 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|