|
1 | | -require 'test_helper' |
2 | | -class ReactTest < ActionDispatch::IntegrationTest |
3 | | - setup do |
4 | | - clear_sprockets_cache |
5 | | - end |
6 | | - |
7 | | - teardown do |
8 | | - clear_sprockets_cache |
9 | | - end |
10 | | - |
11 | | - test 'asset pipeline should deliver drop-in react file replacement' do |
12 | | - app_react_file_path = File.expand_path("../dummy/vendor/assets/javascripts/react.js", __FILE__) |
13 | | - react_file_token = "'test_confirmation_token_react_content_non_production';\n" |
14 | | - File.write(app_react_file_path, react_file_token) |
15 | | - manually_expire_asset("react.js") |
16 | | - react_asset = Rails.application.assets['react.js'] |
17 | | - |
18 | | - get '/assets/react.js' |
19 | | - |
20 | | - File.unlink(app_react_file_path) |
21 | | - |
22 | | - assert_response :success |
23 | | - assert_equal react_file_token.length, react_asset.to_s.length, "The asset pipeline serves the drop-in file" |
24 | | - assert_equal react_file_token.length, @response.body.length, "The asset route serves the drop-in file" |
25 | | - end |
26 | | - |
27 | | - test 'precompiling assets works' do |
28 | | - begin |
29 | | - precompile_assets |
30 | | - ensure |
31 | | - clear_precompiled_assets |
32 | | - end |
33 | | - end |
34 | | - |
35 | | - test "the development version with addons is loaded" do |
36 | | - asset = Rails.application.assets.find_asset('react') |
37 | | - assert asset.pathname.to_s.end_with?('development-with-addons/react.js') |
38 | | - end |
39 | | - |
40 | | - test "the production build is optimized for production" do |
41 | | - production_path = File.expand_path("../../lib/assets/react-source/production/react.js", __FILE__) |
42 | | - production_js = File.read(production_path) |
43 | | - env_checks = production_js.scan("NODE_ENV") |
44 | | - assert_equal(0, env_checks.length, "Dead code is removed for production") |
| 1 | +require "test_helper" |
| 2 | + |
| 3 | +class ReactTest < ActiveSupport::TestCase |
| 4 | + def test_it_camelizes_props |
| 5 | + raw_props = { |
| 6 | + multi_word_sym: { |
| 7 | + nested_key: [ |
| 8 | + {double_nested: true}, |
| 9 | + 1, |
| 10 | + "string item", |
| 11 | + [ { nested_array: {} }], |
| 12 | + ] |
| 13 | + }, |
| 14 | + "alreadyCamelized" => :ok, |
| 15 | + } |
| 16 | + |
| 17 | + expected_props = { |
| 18 | + "multiWordSym" => { |
| 19 | + "nestedKey" => [ |
| 20 | + { "doubleNested" => true }, |
| 21 | + 1, |
| 22 | + "string item", |
| 23 | + [ { "nestedArray" => {} }], |
| 24 | + ] |
| 25 | + }, |
| 26 | + "alreadyCamelized" => :ok |
| 27 | + } |
| 28 | + |
| 29 | + assert_equal expected_props, React.camelize_props(raw_props) |
45 | 30 | end |
46 | 31 | end |
0 commit comments