|
1 | | -import { describe, expect, it } from 'vitest'; |
| 1 | +import { describe, expect, it, beforeEach, vi, Mock } from 'vitest'; |
2 | 2 | import { render, screen } from '@testing-library/react'; |
3 | 3 | import { Stream } from '@vonage/client-sdk-video'; |
4 | 4 | import ParticipantListItem, { ParticipantListItemProps } from './ParticipantListItem'; |
| 5 | +import useAudioLevels from '../../../hooks/useAudioLevels'; |
| 6 | +import usePublisherContext from '../../../hooks/usePublisherContext'; |
| 7 | +import { PublisherContextType } from '../../../Context/PublisherProvider'; |
| 8 | + |
| 9 | +vi.mock('../../../hooks/useAudioLevels'); |
| 10 | +vi.mock('../../../hooks/usePublisherContext'); |
| 11 | + |
| 12 | +const mockUseAudioLevels = useAudioLevels as Mock<[], number | undefined>; |
| 13 | +const mockUsePublisherContext = usePublisherContext as Mock<[], PublisherContextType>; |
5 | 14 |
|
6 | 15 | describe('ParticipantListItem', () => { |
7 | 16 | const mockStream: Stream = { |
@@ -72,4 +81,47 @@ describe('ParticipantListItem', () => { |
72 | 81 | fontSize: '14px', |
73 | 82 | }); |
74 | 83 | }); |
| 84 | + |
| 85 | + describe('Publisher audio state handling', () => { |
| 86 | + let publisherContext: PublisherContextType; |
| 87 | + beforeEach(() => { |
| 88 | + publisherContext = { |
| 89 | + isAudioEnabled: true, |
| 90 | + } as unknown as PublisherContextType; |
| 91 | + mockUsePublisherContext.mockImplementation(() => publisherContext); |
| 92 | + mockUseAudioLevels.mockReturnValue(50); |
| 93 | + }); |
| 94 | + |
| 95 | + it('shows active audio state for publisher when microphone is enabled', () => { |
| 96 | + mockUsePublisherContext.mockImplementation(() => ({ |
| 97 | + ...publisherContext, |
| 98 | + isAudioEnabled: true, |
| 99 | + })); |
| 100 | + mockUseAudioLevels.mockReturnValue(75); |
| 101 | + |
| 102 | + render(<ParticipantListItem {...defaultProps} audioLevel={undefined} hasAudio />); |
| 103 | + |
| 104 | + const participantItem = screen.getByTestId('participant-list-item'); |
| 105 | + expect(participantItem).toBeInTheDocument(); |
| 106 | + |
| 107 | + const audioIndicator = screen.getByTestId('audio-indicator'); |
| 108 | + expect(audioIndicator).toBeInTheDocument(); |
| 109 | + |
| 110 | + const micIcon = screen.getByTestId('MicIcon'); |
| 111 | + expect(micIcon).toBeInTheDocument(); |
| 112 | + }); |
| 113 | + |
| 114 | + it('shows muted state when hasAudio is false', () => { |
| 115 | + render(<ParticipantListItem {...defaultProps} audioLevel={undefined} hasAudio={false} />); |
| 116 | + |
| 117 | + const participantItem = screen.getByTestId('participant-list-item'); |
| 118 | + expect(participantItem).toBeInTheDocument(); |
| 119 | + |
| 120 | + const audioIndicator = screen.getByTestId('audio-indicator'); |
| 121 | + expect(audioIndicator).toBeInTheDocument(); |
| 122 | + |
| 123 | + const micOffIcon = screen.getByTestId('MicOffIcon'); |
| 124 | + expect(micOffIcon).toBeInTheDocument(); |
| 125 | + }); |
| 126 | + }); |
75 | 127 | }); |
0 commit comments