about summary refs log tree commit diff
path: root/spec/helpers/home_helper_spec.rb
blob: 3d2c5fe24830f01f60b1373adc71f86e37b845b9 (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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe HomeHelper, type: :helper do
  describe 'default_props' do
    it 'returns default properties according to the context' do
      expect(helper.default_props).to eq locale: I18n.locale
    end
  end

  describe 'account_link_to' do
    context 'with a missing account' do
      let(:account) { nil }

      it 'returns a button' do
        result = helper.account_link_to(account)

        expect(result).to match t('about.contact_missing')
      end
    end

    context 'with a valid account' do
      let(:account) { Fabricate(:account) }

      it 'returns a link to the account' do
        without_partial_double_verification do
          allow(helper).to receive(:current_account).and_return(account)
          allow(helper).to receive(:prefers_autoplay?).and_return(false)
          result = helper.account_link_to(account)

          expect(result).to match "@#{account.acct}"
        end
      end
    end
  end

  describe 'obscured_counter' do
    context 'with a value of less than zero' do
      let(:count) { -10 }

      it 'returns the correct string' do
        expect(helper.obscured_counter(count)).to eq '0'
      end
    end

    context 'with a value of zero' do
      let(:count) { 0 }

      it 'returns the correct string' do
        expect(helper.obscured_counter(count)).to eq '0'
      end
    end

    context 'with a value of one' do
      let(:count) { 1 }

      it 'returns the correct string' do
        expect(helper.obscured_counter(count)).to eq '1'
      end
    end

    context 'with a value of more than one' do
      let(:count) { 10 }

      it 'returns the correct string' do
        expect(helper.obscured_counter(count)).to eq '1+'
      end
    end
  end

  describe 'custom_field_classes' do
    context 'with a verified field' do
      let(:field) { instance_double(Account::Field, verified?: true) }

      it 'returns verified string' do
        result = helper.custom_field_classes(field)
        expect(result).to eq 'verified'
      end
    end

    context 'with a non-verified field' do
      let(:field) { instance_double(Account::Field, verified?: false) }

      it 'returns verified string' do
        result = helper.custom_field_classes(field)
        expect(result).to eq 'emojify'
      end
    end
  end

  describe 'sign_up_messages' do
    context 'with closed registrations' do
      it 'returns correct sign up message' do
        allow(helper).to receive(:closed_registrations?).and_return(true)
        result = helper.sign_up_message

        expect(result).to eq t('auth.registration_closed', instance: 'cb6e6126.ngrok.io')
      end
    end

    context 'with open registrations' do
      it 'returns correct sign up message' do
        allow(helper).to receive(:closed_registrations?).and_return(false)
        allow(helper).to receive(:open_registrations?).and_return(true)
        result = helper.sign_up_message

        expect(result).to eq t('auth.register')
      end
    end

    context 'with approved registrations' do
      it 'returns correct sign up message' do
        allow(helper).to receive(:closed_registrations?).and_return(false)
        allow(helper).to receive(:open_registrations?).and_return(false)
        allow(helper).to receive(:approved_registrations?).and_return(true)
        result = helper.sign_up_message

        expect(result).to eq t('auth.apply_for_account')
      end
    end
  end
end