mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
FIX: Sort plugins by their setting category name (#25128)
Some plugins have names (e.g. discourse-x-yz) that are totally different from what they are actually called, and that causes issues when showing them in a sorted way in the admin plugin list. Now, we should use the setting category name from client.en.yml if it exists, otherwise fall back to the name, for sorting. This is what we do on the client to determine what text to show for the plugin name as well.
This commit is contained in:
@ -1,10 +1,60 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Plugin::Instance do
|
||||
subject(:plugin_instance) { described_class.new }
|
||||
subject(:plugin_instance) { described_class.new(metadata) }
|
||||
|
||||
let(:metadata) { Plugin::Metadata.parse <<TEXT }
|
||||
# name: discourse-sample-plugin
|
||||
# about: about: my plugin
|
||||
# version: 0.1
|
||||
# authors: Frank Zappa
|
||||
# contact emails: frankz@example.com
|
||||
# url: http://discourse.org
|
||||
# required version: 1.3.0beta6+48
|
||||
# meta_topic_id: 1234
|
||||
# label: experimental
|
||||
|
||||
some_ruby
|
||||
TEXT
|
||||
|
||||
after { DiscoursePluginRegistry.reset! }
|
||||
|
||||
# NOTE: sample_plugin_site_settings.yml is always loaded in tests in site_setting.rb
|
||||
|
||||
describe ".humanized_name" do
|
||||
before do
|
||||
TranslationOverride.upsert!(
|
||||
"en",
|
||||
"admin_js.admin.site_settings.categories.discourse_sample_plugin",
|
||||
"Sample Plugin Category Name",
|
||||
)
|
||||
end
|
||||
|
||||
it "defaults to using the plugin name with the discourse- prefix removed" do
|
||||
expect(plugin_instance.humanized_name).to eq("sample-plugin")
|
||||
end
|
||||
|
||||
it "uses the plugin setting category name if it exists" do
|
||||
plugin_instance.enabled_site_setting(:discourse_sample_plugin_enabled)
|
||||
expect(plugin_instance.humanized_name).to eq("Sample Plugin Category Name")
|
||||
end
|
||||
|
||||
it "the plugin name the plugin site settings are still under the generic plugins: category" do
|
||||
plugin_instance.stubs(:setting_catgory).returns("plugins")
|
||||
expect(plugin_instance.humanized_name).to eq("sample-plugin")
|
||||
end
|
||||
|
||||
it "removes any Discourse prefix from the setting category name" do
|
||||
TranslationOverride.upsert!(
|
||||
"en",
|
||||
"admin_js.admin.site_settings.categories.discourse_sample_plugin",
|
||||
"Discourse Sample Plugin Category Name",
|
||||
)
|
||||
plugin_instance.enabled_site_setting(:discourse_sample_plugin_enabled)
|
||||
expect(plugin_instance.humanized_name).to eq("Sample Plugin Category Name")
|
||||
end
|
||||
end
|
||||
|
||||
describe "find_all" do
|
||||
it "can find plugins correctly" do
|
||||
plugins = Plugin::Instance.find_all("#{Rails.root}/spec/fixtures/plugins")
|
||||
|
Reference in New Issue
Block a user