|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative '../../lib/inertia_rails/rspec' |
| 4 | +RSpec.describe 'props can be transformed', type: :request, inertia: true do |
| 5 | + let(:headers) do |
| 6 | + { |
| 7 | + 'X-Inertia' => true, |
| 8 | + 'X-Inertia-Partial-Component' => 'TestComponent', |
| 9 | + } |
| 10 | + end |
| 11 | + |
| 12 | + context 'props are provided' do |
| 13 | + it 'transforms the props' do |
| 14 | + get prop_transformer_test_path, headers: headers |
| 15 | + |
| 16 | + expect_inertia.to render_component('TestComponent') |
| 17 | + .and have_exact_props({ |
| 18 | + 'LOWER_PROP' => 'lower_value', |
| 19 | + 'PARENT_HASH' => { |
| 20 | + 'LOWER_CHILD_PROP' => 'lower_child_value', |
| 21 | + }, |
| 22 | + }) |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + context 'props and meta are provided' do |
| 27 | + it 'transforms the props' do |
| 28 | + get prop_transformer_with_meta_test_path, headers: headers |
| 29 | + |
| 30 | + expect_inertia.to render_component('TestComponent') |
| 31 | + .and include_props({ |
| 32 | + 'LOWER_PROP' => 'lower_value', |
| 33 | + }) |
| 34 | + end |
| 35 | + |
| 36 | + it 'does not transform the meta' do |
| 37 | + get prop_transformer_with_meta_test_path, headers: headers |
| 38 | + |
| 39 | + expect(response.parsed_body['props']['_inertia_meta']).to eq( |
| 40 | + [ |
| 41 | + { |
| 42 | + 'tagName' => 'meta', |
| 43 | + 'name' => 'description', |
| 44 | + 'content' => "Don't transform me!", |
| 45 | + 'headKey' => 'meta-name-description', |
| 46 | + } |
| 47 | + ] |
| 48 | + ) |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + context 'no props are provided' do |
| 53 | + it 'does not error' do |
| 54 | + get prop_transformer_no_props_test_path, headers: headers |
| 55 | + |
| 56 | + expect_inertia.to render_component('TestComponent') |
| 57 | + .and have_exact_props({}) |
| 58 | + end |
| 59 | + end |
| 60 | +end |
0 commit comments