discourse/plugins/chat/spec/requests/application_controller_spec.rb
Martin Brennan 61c1d35f17
FEATURE: Convert chat plugin UI to new show plugin and admin UI guidelines (#28632)
This commit converts the current chat plugin UI into the
new "show plugin" UI already followed by AI and Gamification.

In the process, I also:

* Made a dedicated /new route to create new webhooks
* Converted the webhook form to FormKit
* Made some fixes and improvements to the `AdminPluginConfigPage`, `AdminPageHeader`,
   and `AdminPageSubheader` generic components, so more plugins can
   adopt the UI guidelines too. This includes adding a header outlet so plugins
   can add action buttons to the plugin show page header.
* Fixes the submit button loading state for FormKit (by Joffrey)

---------

Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2024-09-10 15:16:16 +10:00

44 lines
1.0 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",
"admin_route" => {
"label" => "chat.admin.title",
"location" => "chat",
"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