require 'rails_helper'

describe 'YouTube support', type: :feature, js: true do
  it 'allows YouTube embed codes' do
    visit new_post_path

    embed = '<iframe width="560" height="315" src="//www.youtube.com/embed/d2Q'\
      'dITRRMHg" frameborder="0" allowfullscreen></iframe>'
    page.execute_script "Bootsy.areas.post_content.editor.setValue('#{embed}')"

    content = page.evaluate_script(
      'Bootsy.areas.post_content.editor.getValue()'
    )

    expected_css = 'iframe[src="//www.youtube.com/embed/d2QdITRRMHg"]'\
      '[allowfullscreen="1"][frameborder="0"][height="315"][width="560"]'

    expect(Capybara.string(content)).to have_css(expected_css)
  end
end
