about summary refs log tree commit diff
path: root/spec/helpers/admin/trends/statuses_helper_spec.rb
blob: 92caae6909960e465733ad8a6edfa3726e050fa4 (plain) (blame)
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
# frozen_string_literal: true

require 'rails_helper'

describe Admin::Trends::StatusesHelper do
  describe '.one_line_preview' do
    before do
      allow(helper).to receive(:current_user).and_return(Fabricate.build(:user))
    end

    context 'with a local status' do
      let(:status) { Fabricate.build(:status, text: 'Test local status') }

      it 'renders a correct preview text' do
        result = helper.one_line_preview(status)

        expect(result).to eq 'Test local status'
      end
    end

    context 'with a remote status' do
      let(:status) { Fabricate.build(:status, uri: 'https://sfd.sdf', text: '<html><body><p>Test remote status</p><p>text</p></body></html>') }

      it 'renders a correct preview text' do
        result = helper.one_line_preview(status)

        expect(result).to eq 'Test remote status'
      end
    end

    context 'with a status that has empty text' do
      let(:status) { Fabricate.build(:status, text: '') }

      it 'renders a correct preview text' do
        result = helper.one_line_preview(status)

        expect(result).to eq ''
      end
    end

    context 'with a status that has emoji' do
      before { Fabricate(:custom_emoji, shortcode: 'florpy') }

      let(:status) { Fabricate(:status, text: 'hello there :florpy:') }

      it 'renders a correct preview text' do
        result = helper.one_line_preview(status)

        expect(result).to match 'hello there'
        expect(result).to match '<img rel="emoji"'
      end
    end
  end
end