koel/resources/assets/js/components/ui/VolumeSlider.spec.ts

43 lines
1.3 KiB
TypeScript
Raw Normal View History

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'
import { socketService, volumeManager } from '@/services'
import Volume from './VolumeSlider.vue'
2024-03-18 22:04:01 +00:00
import { preferenceStore } from '@/stores'
2022-05-13 17:58:38 +00:00
new class extends UnitTestCase {
2024-03-18 22:04:01 +00:00
protected beforeEach () {
super.beforeEach(() => {
2024-03-18 22:04:01 +00:00
vi.useFakeTimers()
2022-11-02 19:25:22 +00:00
preferenceStore.volume = 5
})
}
protected test () {
it('mutes and unmutes', async () => {
const { html } = this.render(Volume)
expect(html()).toMatchSnapshot()
expect(volumeManager.volume.value).toEqual(5)
await this.user.click(screen.getByTitle('Mute'))
expect(html()).toMatchSnapshot()
expect(volumeManager.volume.value).toEqual(0)
await this.user.click(screen.getByTitle('Unmute'))
expect(html()).toMatchSnapshot()
expect(volumeManager.volume.value).toEqual(5)
})
it('sets and broadcasts volume', async () => {
2024-03-18 22:04:01 +00:00
const broadcastMock = this.mock(socketService, 'broadcast')
this.render(Volume)
await fireEvent.update(screen.getByRole('slider'), '4.2')
2024-03-18 22:04:01 +00:00
vi.runAllTimers()
2024-03-18 22:04:01 +00:00
expect(volumeManager.volume.value).toBe(4.2)
expect(broadcastMock).toHaveBeenCalledWith('SOCKET_VOLUME_CHANGED', 4.2)
})
}
}