0
0
Fork 0

React component helper specs (#24072)

This commit is contained in:
Matt Jankowski 2023-04-26 12:21:32 -04:00 committed by GitHub
parent 3029aeb838
commit 91a8cd21d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 266 additions and 83 deletions

View file

@ -0,0 +1,45 @@
# frozen_string_literal: true
require 'rails_helper'
describe ReactComponentHelper do
describe 'react_component' do
context 'with no block passed in' do
let(:result) { helper.react_component('name', { one: :two }) }
it 'returns a tag with data attributes' do
expect(parsed_html.div['data-component']).to eq('Name')
expect(parsed_html.div['data-props']).to eq('{"one":"two"}')
end
end
context 'with a block passed in' do
let(:result) do
helper.react_component('name', { one: :two }) do
helper.content_tag(:nav, 'ok')
end
end
it 'returns a tag with data attributes' do
expect(parsed_html.div['data-component']).to eq('Name')
expect(parsed_html.div['data-props']).to eq('{"one":"two"}')
expect(parsed_html.div.nav.content).to eq('ok')
end
end
end
describe 'react_admin_component' do
let(:result) { helper.react_admin_component('name', { one: :two }) }
it 'returns a tag with data attributes' do
expect(parsed_html.div['data-admin-component']).to eq('Name')
expect(parsed_html.div['data-props']).to eq('{"locale":"en","one":"two"}')
end
end
private
def parsed_html
Nokogiri::Slop(result)
end
end