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

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

  render(<Video videoStream={track} />)

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

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

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