1
0

react_component_helper_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe ReactComponentHelper do
  4. describe 'react_component' do
  5. context 'with no block passed in' do
  6. let(:result) { helper.react_component('name', { one: :two }) }
  7. it 'returns a tag with data attributes' do
  8. expect(parsed_html.div['data-component']).to eq('Name')
  9. expect(parsed_html.div['data-props']).to eq('{"one":"two"}')
  10. end
  11. end
  12. context 'with a block passed in' do
  13. let(:result) do
  14. helper.react_component('name', { one: :two }) do
  15. helper.content_tag(:nav, 'ok')
  16. end
  17. end
  18. it 'returns a tag with data attributes' do
  19. expect(parsed_html.div['data-component']).to eq('Name')
  20. expect(parsed_html.div['data-props']).to eq('{"one":"two"}')
  21. expect(parsed_html.div.nav.content).to eq('ok')
  22. end
  23. end
  24. end
  25. describe 'react_admin_component' do
  26. let(:result) { helper.react_admin_component('name', { one: :two }) }
  27. it 'returns a tag with data attributes' do
  28. expect(parsed_html.div['data-admin-component']).to eq('Name')
  29. expect(parsed_html.div['data-props']).to eq('{"one":"two"}')
  30. end
  31. end
  32. private
  33. def parsed_html
  34. Nokogiri::Slop(result)
  35. end
  36. end