import React from 'react';
import renderer from 'react-test-renderer';
import { render, fireEvent } from '@testing-library/react';
import { Video } from './Video';
const imgurOgTestData = {
site_name: 'imgur',
title: 'Video title',
description: 'Video description',
url: 'https://imgur.com/gallery/hkj7IZQ',
videos: [
{
type: 'video/mp4',
video: 'https://i.imgur.com/pi2FUNN.mp4',
},
],
};
const youtubeOgTestData = {
site_name: 'YouTube',
videos: [
{
type: 'text/html',
video: 'https://www.youtube.com/watch?v=IVkOFxrKRjA',
width: 596,
height: 335,
},
],
};
describe('Video', () => {
it('renders with default props', () => {
const tree = renderer.create( ).toJSON();
expect(tree).toMatchInlineSnapshot(`null`);
});
it('renders YouTube video (iframe)', () => {
const tree = renderer.create( ).toJSON();
expect(tree).toMatchInlineSnapshot(`
VIDEO
`);
});
it('renders MP4 video with poster attribute (image URL specified)', () => {
const tree = renderer
.create(
,
)
.toJSON();
expect(tree).toMatchInlineSnapshot(`
Video title
Video description
`);
});
it('renders as GIF (different video options, with default urlsThatAreGifs property)', () => {
const tree = renderer.create( ).toJSON();
expect(tree).toMatchInlineSnapshot(`
Video title
Video description
`);
});
it('renders with GIF URL but as MP4 (normal video settings) with empty urlsThatAreGifs array', () => {
const tree = renderer.create( ).toJSON();
expect(tree).toMatchInlineSnapshot(`
Video title
Video description
`);
});
it('checks if handleClose callback has been called', () => {
const onClick = jest.fn();
const { getByRole } = render( );
fireEvent.click(getByRole('button'));
expect(onClick).toHaveBeenCalledTimes(1);
});
});