discourse/spec/serializers/admin_plugin_serializer_spec.rb
Martin Brennan 312a930ac8
UX: Disable plugin list settings button for some plugins (#27124)
For plugins with only an "enabled" site setting, it doesn't
make sense to take them to the site settings page, since the
toggle switch in the list can be used to change enabled/disabled.

This will not be the case for plugins that have their own custom
config page (like Automation), but we will deal with this when
we actually overhaul this plugin to use the new show page.

Also adds another rspec fixture of a test plugin.
2024-05-23 12:04:26 +10:00

95 lines
3.0 KiB
Ruby

# frozen_string_literal: true
RSpec.describe AdminPluginSerializer do
subject(:serializer) { described_class.new(instance) }
let(:all_test_plugins) { Plugin::Instance.find_all("#{Rails.root}/spec/fixtures/plugins") }
let(:instance) { all_test_plugins.find { |plugin| plugin.name == "color_definition" } }
describe "admin_route" do
it "returns the correct values when use_new_show_route is false" do
instance.expects(:admin_route).returns(
location: "admin",
label: "admin.test",
use_new_show_route: false,
)
expect(serializer.admin_route).to eq(
location: "admin",
label: "admin.test",
full_location: "adminPlugins.admin",
)
end
it "returns the correct values when use_new_show_route is true" do
instance.expects(:admin_route).returns(
location: "admin",
label: "admin.test",
use_new_show_route: true,
)
expect(serializer.admin_route).to eq(
location: "admin",
label: "admin.test",
full_location: "adminPlugins.show",
use_new_show_route: true,
)
end
end
describe "has_settings" do
it "is false for plugins with no settings" do
expect(described_class.new(instance).has_settings).to eq(false)
end
it "is true for plugins with settings" do
SiteSetting.expects(:plugins).returns(
{
"color_definition_enabled" => "color_definition",
"color_definition_api_key" => "color_definition",
},
)
expect(described_class.new(instance).has_settings).to eq(true)
end
end
describe "has_only_enabled_settings" do
it "is false for plugins with no settings" do
expect(described_class.new(instance).has_settings).to eq(false)
end
it "is true if only enabled_site_setting is present for the plugin" do
SiteSetting.expects(:plugins).returns({ "color_definition_enabled" => "color_definition" })
expect(described_class.new(instance).has_settings).to eq(true)
end
it "is false if there are other settings for the plugin" do
SiteSetting.expects(:plugins).returns(
{
"color_definition_enabled" => "color_definition",
"color_definition_api_key" => "color_definition",
},
)
expect(described_class.new(instance).has_only_enabled_setting).to eq(false)
end
end
describe "enabled_setting" do
it "should return the right value" do
instance.enabled_site_setting("test")
expect(serializer.enabled_setting).to eq("test")
end
end
describe "commit_hash" do
it "should return commit_hash and commit_url" do
git_repo = instance.git_repo
git_repo.stubs(:latest_local_commit).returns("123456")
git_repo.stubs(:url).returns("http://github.com/discourse/discourse-plugin")
expect(serializer.commit_hash).to eq("123456")
expect(serializer.commit_url).to eq(
"http://github.com/discourse/discourse-plugin/commit/123456",
)
end
end
end