import expect from 'expect';
import React from 'react';
import shallowRender from './helpers/shallowRender';
import fullRender from './helpers/fullRender';

describe('YouTube', () => {
  it('should render a div with a custom id', () => {
    const { output } = shallowRender({
      id: 'custom-id',
      url: 'https://www.youtube.com/watch?v=XxVg_s8xAms',
    });

    expect(output).toEqual(<div id="custom-id" className="" />);
  });

  it('should render a div with a custom className', () => {
    const { output } = shallowRender({
      id: 'custom-id',
      className: 'custom-class',
      url: 'https://www.youtube.com/watch?v=XxVg_s8xAms',
    });

    expect(output).toEqual(<div id="custom-id" className="custom-class" />);
  });

  it('should create and bind a new youtube player when mounted', () => {
    const { playerMock } = fullRender({
      url: 'https://www.youtube.com/watch?v=XxVg_s8xAms',
    });

    expect(playerMock.on.calls.length).toBe(3);
  });

  it('should load a url', () => {
    const { playerMock } = fullRender({
      url: 'https://www.youtube.com/watch?v=XxVg_s8xAms',
    });

    expect(playerMock.cueVideoById).toHaveBeenCalledWith('XxVg_s8xAms');
  });

  it('should load a new url', () => {
    const { playerMock, rerender } = fullRender({
      url: 'https://www.youtube.com/watch?v=XxVg_s8xAms',
    });

    rerender({
      url: 'https://www.youtube.com/watch?v=-DX3vJiqxm4',
    });

    expect(playerMock.cueVideoById).toHaveBeenCalledWith('XxVg_s8xAms');
    expect(playerMock.cueVideoById).toHaveBeenCalledWith('-DX3vJiqxm4');
  });

  it('should load a url with autoplay enabled', () => {
    const { playerMock } = fullRender({
      url: 'https://www.youtube.com/watch?v=XxVg_s8xAms',
      opts: {
        playerVars: {
          autoplay: 1,
        },
      },
    });

    expect(playerMock.cueVideoById).toNotHaveBeenCalled();
    expect(playerMock.loadVideoById).toHaveBeenCalledWith('XxVg_s8xAms');
  });

  it('should destroy the youtube player', () => {
    const { playerMock, unmount } = fullRender({
      url: 'https://www.youtube.com/watch?v=XxVg_s8xAms',
    });

    unmount();
    expect(playerMock.destroy).toHaveBeenCalled();
  });
});

@@ -26,35 +26,8 @@
 t';%0A
-import React from 'react';%0A
 impo
@@ -75,16 +75,16 @@
 ender';%0A
+
 import f
@@ -354,53 +354,35 @@
 tput
-).toEqual(%3Cdiv id=%22custom-id%22 className=%22%22 /%3E
+.props.id).toBe('custom-id'
 );%0A 
@@ -630,38 +630,15 @@
 tput
-).toEqual(%3Cdiv id=%22custom-id%22 
+.props.
 clas
@@ -646,10 +646,16 @@
 Name
-=%22
+).toBe('
 cust
@@ -666,12 +666,9 @@
 lass
-%22 /%3E
+'
 );%0A 

remove jsx from tests