mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Wiring for the admin about config page (#27492)
This commit continues work laid out by ffec8163b0 for the admin config page for the /about page. The last commit set up the user interface, and this one sets up all the wiring needed to make the input fields and save buttons actually work.
Internal topic: t/128544.
This commit is contained in:
@@ -826,6 +826,45 @@ RSpec.describe SiteSettingExtension do
|
||||
expect(setting[:default]).to eq(system_upload.url)
|
||||
end
|
||||
end
|
||||
|
||||
context "with the filter_allowed_hidden argument" do
|
||||
it "includes the specified hidden settings only if include_hidden is true" do
|
||||
result =
|
||||
SiteSetting
|
||||
.all_settings(include_hidden: true, filter_allowed_hidden: [:about_banner_image])
|
||||
.map { |ss| ss[:setting] }
|
||||
|
||||
expect(result).to include(:about_banner_image)
|
||||
expect(result).not_to include(:community_owner)
|
||||
|
||||
result =
|
||||
SiteSetting
|
||||
.all_settings(include_hidden: false, filter_allowed_hidden: [:about_banner_image])
|
||||
.map { |ss| ss[:setting] }
|
||||
|
||||
expect(result).not_to include(:about_banner_image)
|
||||
expect(result).not_to include(:community_owner)
|
||||
|
||||
result =
|
||||
SiteSetting
|
||||
.all_settings(include_hidden: true, filter_allowed_hidden: [:community_owner])
|
||||
.map { |ss| ss[:setting] }
|
||||
|
||||
expect(result).not_to include(:about_banner_image)
|
||||
expect(result).to include(:community_owner)
|
||||
|
||||
result =
|
||||
SiteSetting
|
||||
.all_settings(
|
||||
include_hidden: true,
|
||||
filter_allowed_hidden: %i[about_banner_image community_owner],
|
||||
)
|
||||
.map { |ss| ss[:setting] }
|
||||
|
||||
expect(result).to include(:about_banner_image)
|
||||
expect(result).to include(:community_owner)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".client_settings_json_uncached" do
|
||||
|
||||
150
spec/system/admin_about_config_area_spec.rb
Normal file
150
spec/system/admin_about_config_area_spec.rb
Normal file
@@ -0,0 +1,150 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe "Admin About Config Area Page", type: :system do
|
||||
fab!(:admin)
|
||||
fab!(:image_upload)
|
||||
|
||||
let(:config_area) { PageObjects::Pages::AdminAboutConfigArea.new }
|
||||
|
||||
before { sign_in(admin) }
|
||||
|
||||
context "when all fields have existing values" do
|
||||
before do
|
||||
SiteSetting.title = "my forums title"
|
||||
SiteSetting.site_description = "this is a description for my forums"
|
||||
SiteSetting.about_banner_image = image_upload
|
||||
SiteSetting.extended_site_description = "this is an extended description for my forums"
|
||||
|
||||
SiteSetting.community_owner = "kitty"
|
||||
SiteSetting.contact_email = "kitty@litterbox.com"
|
||||
SiteSetting.contact_url = "https://hello.com"
|
||||
SiteSetting.site_contact_username = admin.username
|
||||
SiteSetting.site_contact_group_name = admin.groups.first.name
|
||||
|
||||
SiteSetting.company_name = "kitty company inc."
|
||||
SiteSetting.governing_law = "kitty jurisdiction"
|
||||
SiteSetting.city_for_disputes = "no disputes allowed"
|
||||
end
|
||||
|
||||
it "populates all input fields correctly" do
|
||||
config_area.visit
|
||||
|
||||
expect(config_area.general_settings_section.community_name_input.value).to eq(
|
||||
"my forums title",
|
||||
)
|
||||
expect(config_area.general_settings_section.community_summary_input.value).to eq(
|
||||
"this is a description for my forums",
|
||||
)
|
||||
expect(config_area.general_settings_section.community_description_editor.value).to eq(
|
||||
"this is an extended description for my forums",
|
||||
)
|
||||
expect(config_area.general_settings_section.banner_image_uploader).to have_uploaded_picture
|
||||
|
||||
expect(config_area.contact_information_section.community_owner_input.value).to eq("kitty")
|
||||
expect(config_area.contact_information_section.contact_email_input.value).to eq(
|
||||
"kitty@litterbox.com",
|
||||
)
|
||||
expect(config_area.contact_information_section.contact_url_input.value).to eq(
|
||||
"https://hello.com",
|
||||
)
|
||||
expect(
|
||||
config_area.contact_information_section.site_contact_user_selector,
|
||||
).to have_selected_value(admin.username)
|
||||
expect(
|
||||
config_area.contact_information_section.site_contact_group_selector,
|
||||
).to have_selected_value(admin.groups.first.id)
|
||||
|
||||
expect(config_area.your_organization_section.company_name_input.value).to eq(
|
||||
"kitty company inc.",
|
||||
)
|
||||
expect(config_area.your_organization_section.governing_law_input.value).to eq(
|
||||
"kitty jurisdiction",
|
||||
)
|
||||
expect(config_area.your_organization_section.city_for_disputes_input.value).to eq(
|
||||
"no disputes allowed",
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "the general settings card" do
|
||||
it "can saves its fields to their corresponding site settings" do
|
||||
config_area.visit
|
||||
|
||||
image_file = file_from_fixtures("logo.png", "images")
|
||||
config_area.general_settings_section.community_name_input.fill_in(with: "my community name")
|
||||
config_area.general_settings_section.community_summary_input.fill_in(
|
||||
with: "here's a bit of a summary",
|
||||
)
|
||||
config_area.general_settings_section.community_description_editor.fill_in(
|
||||
with: "here's an extended description for the **community**",
|
||||
)
|
||||
config_area.general_settings_section.banner_image_uploader.select_image(image_file.path)
|
||||
|
||||
config_area.general_settings_section.save_button.click
|
||||
expect(config_area.general_settings_section).to have_saved_successfully
|
||||
|
||||
expect(SiteSetting.title).to eq("my community name")
|
||||
expect(SiteSetting.site_description).to eq("here's a bit of a summary")
|
||||
expect(SiteSetting.extended_site_description).to eq(
|
||||
"here's an extended description for the **community**",
|
||||
)
|
||||
expect(SiteSetting.extended_site_description_cooked).to eq(
|
||||
"<p>here’s an extended description for the <strong>community</strong></p>",
|
||||
)
|
||||
expect(SiteSetting.about_banner_image.sha1).to eq(Upload.generate_digest(image_file))
|
||||
end
|
||||
end
|
||||
|
||||
describe "the contact information card" do
|
||||
it "can saves its fields to their corresponding site settings" do
|
||||
config_area.visit
|
||||
|
||||
config_area.contact_information_section.community_owner_input.fill_in(with: "awesome owner")
|
||||
config_area.contact_information_section.contact_email_input.fill_in(
|
||||
with: "owneremail@owner.com",
|
||||
)
|
||||
config_area.contact_information_section.contact_url_input.fill_in(
|
||||
with: "https://website.owner.com/blah",
|
||||
)
|
||||
|
||||
user_select_kit = config_area.contact_information_section.site_contact_user_selector
|
||||
user_select_kit.expand
|
||||
user_select_kit.search(admin.username)
|
||||
user_select_kit.select_row_by_value(admin.username)
|
||||
user_select_kit.collapse
|
||||
|
||||
group_select_kit = config_area.contact_information_section.site_contact_group_selector
|
||||
group = admin.groups.first
|
||||
group_select_kit.expand
|
||||
group_select_kit.search(group.name)
|
||||
group_select_kit.select_row_by_value(group.id)
|
||||
group_select_kit.collapse
|
||||
|
||||
config_area.contact_information_section.save_button.click
|
||||
expect(config_area.contact_information_section).to have_saved_successfully
|
||||
|
||||
expect(SiteSetting.community_owner).to eq("awesome owner")
|
||||
expect(SiteSetting.contact_email).to eq("owneremail@owner.com")
|
||||
expect(SiteSetting.contact_url).to eq("https://website.owner.com/blah")
|
||||
expect(SiteSetting.site_contact_username).to eq(admin.username)
|
||||
expect(SiteSetting.site_contact_group_name).to eq(group.name)
|
||||
end
|
||||
end
|
||||
|
||||
describe "the your organization card" do
|
||||
it "can saves its fields to their corresponding site settings" do
|
||||
config_area.visit
|
||||
|
||||
config_area.your_organization_section.company_name_input.fill_in(with: "lil' company")
|
||||
config_area.your_organization_section.governing_law_input.fill_in(with: "wild west law")
|
||||
config_area.your_organization_section.city_for_disputes_input.fill_in(with: "teeb el shouq")
|
||||
|
||||
config_area.your_organization_section.save_button.click
|
||||
expect(config_area.your_organization_section).to have_saved_successfully
|
||||
|
||||
expect(SiteSetting.company_name).to eq("lil' company")
|
||||
expect(SiteSetting.governing_law).to eq("wild west law")
|
||||
expect(SiteSetting.city_for_disputes).to eq("teeb el shouq")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,45 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PageObjects
|
||||
module Components
|
||||
class AdminAboutConfigAreaContactInformationCard < PageObjects::Components::Base
|
||||
def community_owner_input
|
||||
card.find(".community-owner-input input")
|
||||
end
|
||||
|
||||
def contact_email_input
|
||||
card.find(".contact-email-input input")
|
||||
end
|
||||
|
||||
def contact_url_input
|
||||
card.find(".contact-url-input input")
|
||||
end
|
||||
|
||||
def site_contact_user_selector
|
||||
PageObjects::Components::SelectKit.new(
|
||||
".admin-config-area-about__contact-information-section .site-contact-username-input .user-chooser",
|
||||
)
|
||||
end
|
||||
|
||||
def site_contact_group_selector
|
||||
PageObjects::Components::SelectKit.new(
|
||||
".admin-config-area-about__contact-information-section .site-contact-group-input .group-chooser",
|
||||
)
|
||||
end
|
||||
|
||||
def save_button
|
||||
card.find(".btn-primary.admin-config-area-card__btn-save")
|
||||
end
|
||||
|
||||
def has_saved_successfully?
|
||||
PageObjects::Components::Toasts.new.has_success?(
|
||||
I18n.t("admin_js.admin.config_areas.about.toasts.contact_information_saved"),
|
||||
)
|
||||
end
|
||||
|
||||
def card
|
||||
find(".admin-config-area-about__contact-information-section")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,37 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PageObjects
|
||||
module Components
|
||||
class AdminAboutConfigAreaGeneralSettingsCard < PageObjects::Components::Base
|
||||
def community_name_input
|
||||
card.find(".community-name-input input")
|
||||
end
|
||||
|
||||
def community_summary_input
|
||||
card.find(".community-summary-input input")
|
||||
end
|
||||
|
||||
def community_description_editor
|
||||
card.find(".community-description-input .d-editor-input")
|
||||
end
|
||||
|
||||
def banner_image_uploader
|
||||
PageObjects::Components::UppyImageUploader.new(card.find(".image-uploader"))
|
||||
end
|
||||
|
||||
def save_button
|
||||
card.find(".btn-primary.admin-config-area-card__btn-save")
|
||||
end
|
||||
|
||||
def has_saved_successfully?
|
||||
PageObjects::Components::Toasts.new.has_success?(
|
||||
I18n.t("admin_js.admin.config_areas.about.toasts.general_settings_saved"),
|
||||
)
|
||||
end
|
||||
|
||||
def card
|
||||
find(".admin-config-area-about__general-settings-section")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,33 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PageObjects
|
||||
module Components
|
||||
class AdminAboutConfigAreaYourOrganizationCard < PageObjects::Components::Base
|
||||
def company_name_input
|
||||
card.find(".company-name-input input")
|
||||
end
|
||||
|
||||
def governing_law_input
|
||||
card.find(".governing-law-input input")
|
||||
end
|
||||
|
||||
def city_for_disputes_input
|
||||
card.find(".city-for-disputes-input input")
|
||||
end
|
||||
|
||||
def save_button
|
||||
card.find(".btn-primary.admin-config-area-card__btn-save")
|
||||
end
|
||||
|
||||
def has_saved_successfully?
|
||||
PageObjects::Components::Toasts.new.has_success?(
|
||||
I18n.t("admin_js.admin.config_areas.about.toasts.your_organization_saved"),
|
||||
)
|
||||
end
|
||||
|
||||
def card
|
||||
find(".admin-config-area-about__your-organization-section")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
19
spec/system/page_objects/components/uppy_image_uploader.rb
Normal file
19
spec/system/page_objects/components/uppy_image_uploader.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PageObjects
|
||||
module Components
|
||||
class UppyImageUploader < PageObjects::Components::Base
|
||||
def initialize(element)
|
||||
@element = element
|
||||
end
|
||||
|
||||
def select_image(path)
|
||||
attach_file(path) { @element.find("label.btn-default").click }
|
||||
end
|
||||
|
||||
def has_uploaded_picture?
|
||||
@element.has_css?(".uploaded-image-preview")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
23
spec/system/page_objects/pages/admin_about_config_area.rb
Normal file
23
spec/system/page_objects/pages/admin_about_config_area.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module PageObjects
|
||||
module Pages
|
||||
class AdminAboutConfigArea < PageObjects::Pages::Base
|
||||
def visit
|
||||
page.visit("/admin/config/about")
|
||||
end
|
||||
|
||||
def general_settings_section
|
||||
PageObjects::Components::AdminAboutConfigAreaGeneralSettingsCard.new
|
||||
end
|
||||
|
||||
def contact_information_section
|
||||
PageObjects::Components::AdminAboutConfigAreaContactInformationCard.new
|
||||
end
|
||||
|
||||
def your_organization_section
|
||||
PageObjects::Components::AdminAboutConfigAreaYourOrganizationCard.new
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user