import { render, screen } from '@testing-library/react'
import { Audio } from './Audio'
import { mock } from 'jest-mock-extended'
import { Track } from '@zocks-communications/client-sdk-js'

test('renders an audio component and attaches the track to it if the track is available', () => {
  const track = mock<Track>()

  render(<Audio audioStream={track} />)

  expect(screen.getByTestId('audioElement')).toBeInTheDocument()
  expect(track.attach).toHaveBeenCalledTimes(1)
  expect(track.attach.mock.calls[0][0]).toBeInstanceOf(HTMLAudioElement)
})

test('does not render anything if the track is not available', () => {
  render(<Audio audioStream={null} />)

  expect(screen.queryByTestId('audioElement')).not.toBeInTheDocument()
})
