discourse/plugins/chat/spec/requests/application_controller_spec.rb
Ted Johansson 503f9b6f02
DEV: Use default admin routes for plugins with settings (#30941)
This change adds a sidebar link for each plugin that fulfils the following criteria:

- Does not have an explicit admin route defined in the plugin.
- Has at least one site setting (not including enabled/disabled.)

That sidebar link leads to the automatically generated plugin show settings page.
2025-02-04 14:57:28 +08:00

46 lines
1.1 KiB
Ruby

# frozen_string_literal: true
RSpec.describe ApplicationController do
fab!(:user)
fab!(:admin)
def preloaded_json
JSON.parse(
Nokogiri::HTML5.fragment(response.body).css("div#data-preloaded").first["data-preloaded"],
)
end
before do
SiteSetting.chat_enabled = true
SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:trust_level_0]
end
context "when user is admin" do
it "has correctly loaded preloaded data for visiblePlugins" do
sign_in(admin)
get "/latest"
expect(JSON.parse(preloaded_json["visiblePlugins"])).to include(
{
"name" => "chat",
"humanized_name" => "Chat",
"admin_route" => {
"label" => "chat.admin.title",
"location" => "chat",
"full_location" => "adminPlugins.show",
"use_new_show_route" => true,
},
"enabled" => true,
},
)
end
end
context "when user is not admin" do
it "does not include preloaded data for visiblePlugins" do
sign_in(user)
get "/latest"
expect(preloaded_json["visiblePlugins"]).to eq(nil)
end
end
end