0
0
Fork 0

Implement UI for Admin Search of Hashtags (#30880)

This commit is contained in:
Emelia Smith 2024-07-29 17:49:44 +02:00 committed by GitHub
parent 6d2ed0dcba
commit c40e481169
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 316 additions and 11 deletions

View file

@ -0,0 +1,36 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::TagFilter do
describe 'with invalid params' do
it 'raises with key error' do
filter = described_class.new(wrong: true)
expect { filter.results }.to raise_error(/wrong/)
end
it 'raises with status scope error' do
filter = described_class.new(status: 'unknown')
expect { filter.results }.to raise_error(/Unknown status: unknown/)
end
it 'raises with order value error' do
filter = described_class.new(order: 'unknown')
expect { filter.results }.to raise_error(/Unknown order: unknown/)
end
end
describe '#results' do
let(:listable_tag) { Fabricate(:tag, name: 'test1', listable: true) }
let(:not_listable_tag) { Fabricate(:tag, name: 'test2', listable: false) }
it 'returns tags filtered by name' do
filter = described_class.new(name: 'test')
expect(filter.results).to eq([listable_tag, not_listable_tag])
end
end
end

View file

@ -112,6 +112,18 @@ RSpec.describe Tag do
end
end
describe '#formatted_name' do
it 'returns name with a proceeding hash symbol' do
tag = Fabricate(:tag, name: 'foo')
expect(tag.formatted_name).to eq '#foo'
end
it 'returns display_name with a proceeding hash symbol, if display name present' do
tag = Fabricate(:tag, name: 'foobar', display_name: 'FooBar')
expect(tag.formatted_name).to eq '#FooBar'
end
end
describe '.recently_used' do
let(:account) { Fabricate(:account) }
let(:other_person_status) { Fabricate(:status) }
@ -240,5 +252,23 @@ RSpec.describe Tag do
expect(results).to eq [tag, similar_tag]
end
it 'finds only listable tags' do
tag = Fabricate(:tag, name: 'match')
_miss_tag = Fabricate(:tag, name: 'matchunlisted', listable: false)
results = described_class.search_for('match')
expect(results).to eq [tag]
end
it 'finds non-listable tags as well via option' do
tag = Fabricate(:tag, name: 'match')
unlisted_tag = Fabricate(:tag, name: 'matchunlisted', listable: false)
results = described_class.search_for('match', 5, 0, exclude_unlistable: false)
expect(results).to eq [tag, unlisted_tag]
end
end
end