require 'test_helper'

# The transformer is inserting a newline after the docblock for some reason...
EXPECTED_JS = <<eos
/** @jsx React.DOM */

React.DOM.div(null);
eos

EXPECTED_JS_2 = <<eos
/** @jsx React.DOM*/


(function() {
  var Component;

  Component = React.createClass({
    render: function() {
      return ExampleComponent( {videos:this.props.videos} );
    }
  });

}).call(this);
eos

class JSXTransformTest < ActionDispatch::IntegrationTest

  test 'asset pipeline should transform JSX' do
    get 'assets/example.js'
    assert_response :success
    assert_equal EXPECTED_JS, @response.body
  end

  test 'asset pipeline should transform JSX + Coffeescript' do
    get 'assets/example2.js'
    assert_response :success
    assert_equal EXPECTED_JS_2, @response.body
  end

end

require 'test_helper'

# The transformer is inserting a newline after the docblock for some reason...
EXPECTED_JS = <<eos
/** @jsx React.DOM */

React.DOM.div(null);
eos

EXPECTED_JS_2 = <<eos
/** @jsx React.DOM */

(function() {
  var Component;

  Component = React.createClass({
    render: function() {
      return ExampleComponent( {videos:this.props.videos} );
    }
  });

}).call(this);
eos

class JSXTransformTest < ActionDispatch::IntegrationTest

  test 'asset pipeline should transform JSX' do
    get 'assets/example.js'
    assert_response :success
    assert_equal EXPECTED_JS, @response.body
  end

  test 'asset pipeline should transform JSX + Coffeescript' do
    get 'assets/example2.js'
    assert_response :success
    # Different coffee-script may generate slightly different outputs:
    #  1. Some version inserts an extra "\n" at the beginning.
    #  2. "/** @jsx React.DOM */" and "/** @jsx React.DOM*/" are both possible.
    #
    # Because appraisal is used, multiple versions of coffee-script are treated
    # together. Remove all spaces to make test pass.
    assert_equal EXPECTED_JS_2.gsub(/\s/, ''), @response.body.gsub(/\s/, '')
  end

end

Update JSXTransform test case, fix travis test.
Update JSXTransform test case, fix travis test.

Newer coffee-script generates slightly different output, accept it
in JSX coffee script test case.
