Helpers specs coverage improvement (#23937)
This commit is contained in:
parent
00eb2269b6
commit
2f606ba122
5 changed files with 216 additions and 10 deletions
|
@ -42,13 +42,11 @@ RSpec.describe Admin::AccountModerationNotesHelper, type: :helper do
|
|||
let(:account) { Fabricate(:account) }
|
||||
|
||||
it 'calls #link_to' do
|
||||
expect(helper).to receive(:link_to).with(
|
||||
admin_account_path(account.id),
|
||||
class: name_tag_classes(account, true),
|
||||
title: account.acct
|
||||
)
|
||||
result = helper.admin_account_inline_link_to(account)
|
||||
|
||||
helper.admin_account_inline_link_to(account)
|
||||
expect(result).to match(name_tag_classes(account, true))
|
||||
expect(result).to match(account.acct)
|
||||
expect(result).to match(admin_account_path(account.id))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
69
spec/helpers/admin/dashboard_helper_spec.rb
Normal file
69
spec/helpers/admin/dashboard_helper_spec.rb
Normal file
|
@ -0,0 +1,69 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::DashboardHelper do
|
||||
describe 'relevant_account_timestamp' do
|
||||
context 'with an account with older sign in' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:stamp) { 10.days.ago }
|
||||
|
||||
it 'returns a time element' do
|
||||
account.user.update(current_sign_in_at: stamp)
|
||||
result = helper.relevant_account_timestamp(account)
|
||||
|
||||
expect(result).to match('time-ago')
|
||||
expect(result).to match(I18n.l(stamp))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an account with newer sign in' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
it 'returns a time element' do
|
||||
account.user.update(current_sign_in_at: 10.hours.ago)
|
||||
result = helper.relevant_account_timestamp(account)
|
||||
|
||||
expect(result).to eq(I18n.t('generic.today'))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an account where the user is pending' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
it 'returns a time element' do
|
||||
account.user.update(current_sign_in_at: nil)
|
||||
account.user.update(approved: false)
|
||||
result = helper.relevant_account_timestamp(account)
|
||||
|
||||
expect(result).to match('time-ago')
|
||||
expect(result).to match(I18n.l(account.user.created_at))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an account with a last status value' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:stamp) { 5.minutes.ago }
|
||||
|
||||
it 'returns a time element' do
|
||||
account.user.update(current_sign_in_at: nil)
|
||||
account.account_stat.update(last_status_at: stamp)
|
||||
result = helper.relevant_account_timestamp(account)
|
||||
|
||||
expect(result).to match('time-ago')
|
||||
expect(result).to match(I18n.l(stamp))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with an account without sign in or last status or pending' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
it 'returns a time element' do
|
||||
account.user.update(current_sign_in_at: nil)
|
||||
result = helper.relevant_account_timestamp(account)
|
||||
|
||||
expect(result).to eq('-')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,14 +10,54 @@ describe LanguagesHelper do
|
|||
end
|
||||
|
||||
describe 'native_locale_name' do
|
||||
context 'with a blank locale' do
|
||||
it 'defaults to a generic value' do
|
||||
expect(helper.native_locale_name(nil)).to eq(I18n.t('generic.none'))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a locale of `und`' do
|
||||
it 'defaults to a generic value' do
|
||||
expect(helper.native_locale_name('und')).to eq(I18n.t('generic.none'))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a supported locale' do
|
||||
it 'finds the human readable native name from a key' do
|
||||
expect(helper.native_locale_name(:de)).to eq('Deutsch')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a regional locale' do
|
||||
it 'finds the human readable regional name from a key' do
|
||||
expect(helper.native_locale_name('en-GB')).to eq('English (British)')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a non-existent locale' do
|
||||
it 'returns the supplied locale value' do
|
||||
expect(helper.native_locale_name(:xxx)).to eq(:xxx)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'standard_locale_name' do
|
||||
context 'with a blank locale' do
|
||||
it 'defaults to a generic value' do
|
||||
expect(helper.standard_locale_name(nil)).to eq(I18n.t('generic.none'))
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a non-existent locale' do
|
||||
it 'returns the supplied locale value' do
|
||||
expect(helper.standard_locale_name(:xxx)).to eq(:xxx)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a supported locale' do
|
||||
it 'finds the human readable standard name from a key' do
|
||||
expect(helper.standard_locale_name(:de)).to eq('German')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
37
spec/helpers/settings_helper_spec.rb
Normal file
37
spec/helpers/settings_helper_spec.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe SettingsHelper do
|
||||
describe 'session_device_icon' do
|
||||
context 'with a mobile device' do
|
||||
let(:session) { SessionActivation.new(user_agent: 'Mozilla/5.0 (iPhone)') }
|
||||
|
||||
it 'detects the device and returns a descriptive string' do
|
||||
result = helper.session_device_icon(session)
|
||||
|
||||
expect(result).to eq('mobile')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a tablet device' do
|
||||
let(:session) { SessionActivation.new(user_agent: 'Mozilla/5.0 (iPad)') }
|
||||
|
||||
it 'detects the device and returns a descriptive string' do
|
||||
result = helper.session_device_icon(session)
|
||||
|
||||
expect(result).to eq('tablet')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a desktop device' do
|
||||
let(:session) { SessionActivation.new(user_agent: 'Mozilla/5.0 (Macintosh)') }
|
||||
|
||||
it 'detects the device and returns a descriptive string' do
|
||||
result = helper.session_device_icon(session)
|
||||
|
||||
expect(result).to eq('desktop')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -3,6 +3,68 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe StatusesHelper, type: :helper do
|
||||
describe 'link_to_newer' do
|
||||
it 'returns a link to newer content' do
|
||||
url = 'https://example.com'
|
||||
result = helper.link_to_newer(url)
|
||||
|
||||
expect(result).to match('load-more')
|
||||
expect(result).to match(I18n.t('statuses.show_newer'))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'link_to_older' do
|
||||
it 'returns a link to older content' do
|
||||
url = 'https://example.com'
|
||||
result = helper.link_to_older(url)
|
||||
|
||||
expect(result).to match('load-more')
|
||||
expect(result).to match(I18n.t('statuses.show_older'))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'fa_visibility_icon' do
|
||||
context 'with a status that is public' do
|
||||
let(:status) { Status.new(visibility: 'public') }
|
||||
|
||||
it 'returns the correct fa icon' do
|
||||
result = helper.fa_visibility_icon(status)
|
||||
|
||||
expect(result).to match('fa-globe')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a status that is unlisted' do
|
||||
let(:status) { Status.new(visibility: 'unlisted') }
|
||||
|
||||
it 'returns the correct fa icon' do
|
||||
result = helper.fa_visibility_icon(status)
|
||||
|
||||
expect(result).to match('fa-unlock')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a status that is private' do
|
||||
let(:status) { Status.new(visibility: 'private') }
|
||||
|
||||
it 'returns the correct fa icon' do
|
||||
result = helper.fa_visibility_icon(status)
|
||||
|
||||
expect(result).to match('fa-lock')
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a status that is direct' do
|
||||
let(:status) { Status.new(visibility: 'direct') }
|
||||
|
||||
it 'returns the correct fa icon' do
|
||||
result = helper.fa_visibility_icon(status)
|
||||
|
||||
expect(result).to match('fa-at')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#stream_link_target' do
|
||||
it 'returns nil if it is not an embedded view' do
|
||||
set_not_embedded_view
|
||||
|
|
Loading…
Reference in a new issue