mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Allow typed objects theme settings to be saved via settings editor (#26100)
Why this change? On the `/admin/customize/themes/<:id>` route, we allow admins to edit all settings via a settings editor. Prior to this change, trying to edit and save a typed objects theme settings will result in an error on the server.
This commit is contained in:
committed by
GitHub
parent
17a60be189
commit
8d4f405da4
@@ -1040,7 +1040,7 @@ RSpec.describe Admin::ThemesController do
|
||||
end
|
||||
|
||||
describe "#update_single_setting" do
|
||||
let(:theme) { Fabricate(:theme) }
|
||||
fab!(:theme)
|
||||
|
||||
before do
|
||||
theme.set_field(target: :settings, name: :yaml, value: "bg: red")
|
||||
@@ -1063,6 +1063,38 @@ RSpec.describe Admin::ThemesController do
|
||||
expect(user_history.action).to eq(UserHistory.actions[:change_theme_setting])
|
||||
end
|
||||
|
||||
it "should be able to update a theme setting of `objects` typed" do
|
||||
SiteSetting.experimental_objects_type_for_theme_settings = true
|
||||
|
||||
field =
|
||||
theme.set_field(
|
||||
target: :settings,
|
||||
name: "yaml",
|
||||
value: File.read("#{Rails.root}/spec/fixtures/theme_settings/objects_settings.yaml"),
|
||||
)
|
||||
|
||||
theme.save!
|
||||
|
||||
put "/admin/themes/#{theme.id}/setting.json",
|
||||
params: {
|
||||
name: "objects_setting",
|
||||
value: [
|
||||
{ name: "new_section", links: [{ name: "new link", url: "https://some.url.com" }] },
|
||||
].to_json,
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
expect(theme.settings[:objects_setting].value).to eq(
|
||||
[
|
||||
{
|
||||
"name" => "new_section",
|
||||
"links" => [{ "name" => "new link", "url" => "https://some.url.com" }],
|
||||
},
|
||||
],
|
||||
)
|
||||
end
|
||||
|
||||
it "should clear a theme setting" do
|
||||
put "/admin/themes/#{theme.id}/setting.json", params: { name: "bg" }
|
||||
theme.reload
|
||||
|
||||
@@ -110,5 +110,43 @@ describe "Admin Customize Themes", type: :system do
|
||||
"/admin/customize/themes/#{theme.id}/schema/objects_setting",
|
||||
)
|
||||
end
|
||||
|
||||
it "allows an admin to edit a theme setting of objects type via the settings editor" do
|
||||
visit "/admin/customize/themes/#{theme.id}"
|
||||
|
||||
theme_settings_editor = admin_customize_themes_page.click_theme_settings_editor_button
|
||||
|
||||
theme_settings_editor.fill_in(<<~SETTING)
|
||||
[
|
||||
{
|
||||
"setting": "objects_setting",
|
||||
"value": [
|
||||
{
|
||||
"name": "new section",
|
||||
"links": [
|
||||
{
|
||||
"name": "new link",
|
||||
"url": "https://example.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
SETTING
|
||||
|
||||
theme_settings_editor.save
|
||||
|
||||
try_until_success do
|
||||
expect(theme.reload.settings[:objects_setting].value).to eq(
|
||||
[
|
||||
{
|
||||
"links" => [{ "name" => "new link", "url" => "https://example.com" }],
|
||||
"name" => "new section",
|
||||
},
|
||||
],
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,9 @@ module PageObjects
|
||||
end
|
||||
|
||||
def fill_input(content)
|
||||
# Clear the input before filling it in because capybara's fill_in method doesn't seem to replace existing content
|
||||
# unless the content is a blank string.
|
||||
editor_input.fill_in(with: "")
|
||||
editor_input.fill_in(with: content)
|
||||
self
|
||||
end
|
||||
@@ -18,7 +21,10 @@ module PageObjects
|
||||
end
|
||||
|
||||
def editor_input
|
||||
find(".ace-wrapper .ace_text-input", visible: false)
|
||||
find(".ace-wrapper .ace:not(.hidden)", visible: true).find(
|
||||
".ace_text-input",
|
||||
visible: false,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PageObjects
|
||||
module Components
|
||||
class AdminThemeSettingsEditor < Base
|
||||
def fill_in(settings)
|
||||
editor.fill_input(settings)
|
||||
self
|
||||
end
|
||||
|
||||
def save
|
||||
click_button(I18n.t("admin_js.admin.customize.theme.save"))
|
||||
self
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def editor
|
||||
@editor ||= within(".settings-editor") { AceEditor.new }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -42,6 +42,11 @@ module PageObjects
|
||||
def click_edit_objects_theme_setting_button(setting_name)
|
||||
find(".theme-setting[data-setting=\"#{setting_name}\"] .setting-value-edit-button").click
|
||||
end
|
||||
|
||||
def click_theme_settings_editor_button
|
||||
click_button(I18n.t("admin_js.admin.customize.theme.settings_editor"))
|
||||
PageObjects::Components::AdminThemeSettingsEditor.new
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user