~cytrogen/masto-fe

ref: 685270f3f7ea6d4a8a48ec641e8fdfd9fc2e2d7f masto-fe/spec/helpers/media_component_helper_spec.rb -rw-r--r-- 2.5 KiB
685270f3 — Claire [Glitch] Fix clicking “Explore” or “Live feeds” column headers to scroll in advanced mode 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# frozen_string_literal: true

require 'rails_helper'

describe MediaComponentHelper do
  describe 'render_video_component' do
    let(:media) { Fabricate(:media_attachment, type: :video, status: Fabricate(:status)) }
    let(:result) { helper.render_video_component(media.status) }

    before do
      without_partial_double_verification do
        allow(helper).to receive(:current_account).and_return(media.account)
      end
    end

    it 'renders a react component for the video' do
      expect(parsed_html.div['data-component']).to eq('Video')
    end
  end

  describe 'render_audio_component' do
    let(:media) { Fabricate(:media_attachment, type: :audio, status: Fabricate(:status)) }
    let(:result) { helper.render_audio_component(media.status) }

    before do
      without_partial_double_verification do
        allow(helper).to receive(:current_account).and_return(media.account)
      end
    end

    it 'renders a react component for the audio' do
      expect(parsed_html.div['data-component']).to eq('Audio')
    end
  end

  describe 'render_media_gallery_component' do
    let(:media) { Fabricate(:media_attachment, type: :audio, status: Fabricate(:status)) }
    let(:result) { helper.render_media_gallery_component(media.status) }

    before do
      without_partial_double_verification do
        allow(helper).to receive(:current_account).and_return(media.account)
      end
    end

    it 'renders a react component for the media gallery' do
      expect(parsed_html.div['data-component']).to eq('MediaGallery')
    end
  end

  describe 'render_card_component' do
    let(:status) { Fabricate(:status, preview_cards: [Fabricate(:preview_card)]) }
    let(:result) { helper.render_card_component(status) }

    before do
      without_partial_double_verification do
        allow(helper).to receive(:current_account).and_return(status.account)
      end
    end

    it 'returns the correct react component markup' do
      expect(parsed_html.div['data-component']).to eq('Card')
    end
  end

  describe 'render_poll_component' do
    let(:status) { Fabricate(:status, poll: Fabricate(:poll)) }
    let(:result) { helper.render_poll_component(status) }

    before do
      without_partial_double_verification do
        allow(helper).to receive(:current_account).and_return(status.account)
      end
    end

    it 'returns the correct react component markup' do
      expect(parsed_html.div['data-component']).to eq('Poll')
    end
  end

  private

  def parsed_html
    Nokogiri::Slop(result)
  end
end