~cytrogen/masto-fe

ref: 0cb343eec2086809564455319b4bc3f1343c5dd4 masto-fe/spec/helpers/react_component_helper_spec.rb -rw-r--r-- 1.2 KiB
0cb343ee — Claire Tag nightly images as `latest` in glitch-soc, as it has no proper releases (#2414) 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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('{"one":"two"}')
    end
  end

  private

  def parsed_html
    Nokogiri::Slop(result)
  end
end