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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# frozen_string_literal: true
require 'rails_helper'
describe ApplicationHelper do
describe 'active_nav_class' do
it 'returns active when on the current page' do
allow(helper).to receive(:current_page?).and_return(true)
result = helper.active_nav_class('/test')
expect(result).to eq 'active'
end
it 'returns active when on a current page' do
allow(helper).to receive(:current_page?).with('/foo').and_return(false)
allow(helper).to receive(:current_page?).with('/test').and_return(true)
result = helper.active_nav_class('/foo', '/test')
expect(result).to eq 'active'
end
it 'returns empty string when not on current page' do
allow(helper).to receive(:current_page?).and_return(false)
result = helper.active_nav_class('/test')
expect(result).to eq ''
end
end
describe 'body_classes' do
context 'with a body class string from a controller' do
before do
without_partial_double_verification do
allow(helper).to receive(:body_class_string).and_return('modal-layout compose-standalone')
allow(helper).to receive(:current_flavour).and_return('glitch')
allow(helper).to receive(:current_skin).and_return('default')
allow(helper).to receive(:current_account).and_return(Fabricate(:account))
end
end
it 'uses the controller body classes in the result' do
expect(helper.body_classes).to match(/modal-layout compose-standalone/)
end
end
end
describe 'locale_direction' do
it 'adds rtl body class if locale is Arabic' do
I18n.with_locale(:ar) do
expect(helper.locale_direction).to eq 'rtl'
end
end
it 'adds rtl body class if locale is Farsi' do
I18n.with_locale(:fa) do
expect(helper.locale_direction).to eq 'rtl'
end
end
it 'adds rtl if locale is Hebrew' do
I18n.with_locale(:he) do
expect(helper.locale_direction).to eq 'rtl'
end
end
it 'does not add rtl if locale is Thai' do
I18n.with_locale(:th) do
expect(helper.locale_direction).to_not eq 'rtl'
end
end
end
describe 'fa_icon' do
it 'returns a tag of fixed-width cog' do
expect(helper.fa_icon('cog fw')).to eq '<i class="fa fa-cog fa-fw"></i>'
end
end
describe 'open_registrations?' do
it 'returns true when open for registrations' do
allow(Setting).to receive(:[]).with('registrations_mode').and_return('open')
expect(helper.open_registrations?).to be true
expect(Setting).to have_received(:[]).with('registrations_mode')
end
it 'returns false when closed for registrations' do
allow(Setting).to receive(:[]).with('registrations_mode').and_return('none')
expect(helper.open_registrations?).to be false
expect(Setting).to have_received(:[]).with('registrations_mode')
end
end
describe 'show_landing_strip?', without_verify_partial_doubles: true do
describe 'when signed in' do
before do
allow(helper).to receive(:user_signed_in?).and_return(true)
end
it 'does not show landing strip' do
expect(helper.show_landing_strip?).to be false
end
end
describe 'when signed out' do
before do
allow(helper).to receive(:user_signed_in?).and_return(false)
end
it 'does not show landing strip on single user instance' do
allow(helper).to receive(:single_user_mode?).and_return(true)
expect(helper.show_landing_strip?).to be false
end
it 'shows landing strip on multi user instance' do
allow(helper).to receive(:single_user_mode?).and_return(false)
expect(helper.show_landing_strip?).to be true
end
end
end
describe 'available_sign_up_path' do
context 'when registrations are closed' do
before do
without_partial_double_verification do
allow(Setting).to receive(:registrations_mode).and_return('none')
end
end
it 'redirects to joinmastodon site' do
expect(helper.available_sign_up_path).to match(/joinmastodon.org/)
end
end
context 'when in omniauth only mode' do
around do |example|
ClimateControl.modify OMNIAUTH_ONLY: 'true' do
example.run
end
end
it 'redirects to joinmastodon site' do
expect(helper.available_sign_up_path).to match(/joinmastodon.org/)
end
end
context 'when registrations are allowed' do
it 'returns a link to the registration page' do
expect(helper.available_sign_up_path).to eq(new_user_registration_path)
end
end
end
describe 'omniauth_only?' do
context 'when env var is set to true' do
around do |example|
ClimateControl.modify OMNIAUTH_ONLY: 'true' do
example.run
end
end
it 'returns true' do
expect(helper).to be_omniauth_only
end
end
context 'when env var is not set' do
around do |example|
ClimateControl.modify OMNIAUTH_ONLY: nil do
example.run
end
end
it 'returns false' do
expect(helper).to_not be_omniauth_only
end
end
end
describe 'quote_wrap' do
it 'indents and quote wraps text' do
text = <<~TEXT
Hello this is a nice message for you to quote.
Be careful because it has two lines.
TEXT
expect(helper.quote_wrap(text)).to eq <<~EXPECTED.strip
> Hello this is a nice message for you to quote.
> Be careful because it has two lines.
EXPECTED
end
end
describe 'storage_host' do
context 'when S3 alias is present' do
around do |example|
ClimateControl.modify S3_ALIAS_HOST: 's3.alias' do
example.run
end
end
it 'returns true' do
expect(helper.storage_host).to eq('https://s3.alias')
end
end
context 'when S3 alias includes a path component' do
around do |example|
ClimateControl.modify S3_ALIAS_HOST: 's3.alias/path' do
example.run
end
end
it 'returns a correct URL' do
expect(helper.storage_host).to eq('https://s3.alias/path')
end
end
context 'when S3 cloudfront is present' do
around do |example|
ClimateControl.modify S3_CLOUDFRONT_HOST: 's3.cloudfront' do
example.run
end
end
it 'returns true' do
expect(helper.storage_host).to eq('https://s3.cloudfront')
end
end
end
describe 'storage_host?' do
context 'when S3 alias is present' do
around do |example|
ClimateControl.modify S3_ALIAS_HOST: 's3.alias' do
example.run
end
end
it 'returns true' do
expect(helper.storage_host?).to be true
end
end
context 'when S3 cloudfront is present' do
around do |example|
ClimateControl.modify S3_CLOUDFRONT_HOST: 's3.cloudfront' do
example.run
end
end
it 'returns true' do
expect(helper.storage_host?).to be true
end
end
context 'when neither env value is present' do
it 'returns false' do
expect(helper.storage_host?).to be false
end
end
end
describe 'visibility_icon' do
it 'returns a globe icon for a public visible status' do
result = helper.visibility_icon Status.new(visibility: 'public')
expect(result).to match(/globe/)
end
it 'returns an unlock icon for a unlisted visible status' do
result = helper.visibility_icon Status.new(visibility: 'unlisted')
expect(result).to match(/unlock/)
end
it 'returns a lock icon for a private visible status' do
result = helper.visibility_icon Status.new(visibility: 'private')
expect(result).to match(/lock/)
end
it 'returns an at icon for a direct visible status' do
result = helper.visibility_icon Status.new(visibility: 'direct')
expect(result).to match(/at/)
end
end
describe 'title' do
around do |example|
site_title = Setting.site_title
example.run
Setting.site_title = site_title
end
it 'returns site title on production environment' do
Setting.site_title = 'site title'
allow(Rails.env).to receive(:production?).and_return(true)
expect(helper.title).to eq 'site title'
expect(Rails.env).to have_received(:production?)
end
end
end