mirror of
https://github.com/discourse/discourse.git
synced 2026-03-04 01:15:08 +08:00
Introduction of system themes. System themes are local themes which: - Cannot be deleted; - Cannot have “custom code” added, components only; - Cannot have uploads; - Cannot edit color palettes; - Are updated on deploy, like core plugins. This PR added the Foundation system theme, which is an empty theme like Default. The Foundation theme will be added in the next PR. In a development environment, when system theme files are changed/added/deleted, the theme is reuploaded and the page is reloaded to make it a good experience for the engineer working on improvements. System themes are not visible until `SiteSetting.experimental_system_theme` is enabled.
91 lines
2.9 KiB
Ruby
91 lines
2.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "theme_settings_parser"
|
|
|
|
RSpec.describe ThemeSettingsParser do
|
|
after { ThemeField.destroy_all }
|
|
|
|
def types
|
|
ThemeSetting.types
|
|
end
|
|
|
|
class Loader
|
|
def initialize
|
|
@settings = []
|
|
load_settings
|
|
end
|
|
|
|
def load_settings
|
|
yaml = File.read("#{Rails.root}/spec/fixtures/theme_settings/valid_settings.yaml")
|
|
field = ThemeField.create!(theme_id: -1, target_id: 3, name: "yaml", value: yaml)
|
|
|
|
ThemeSettingsParser
|
|
.new(field)
|
|
.load { |name, default, type, opts| @settings << setting(name, default, type, opts) }
|
|
end
|
|
|
|
def setting(name, default, type, opts = {})
|
|
{ name: name, default: default, type: type, opts: opts }
|
|
end
|
|
|
|
def find_by_name(name)
|
|
@settings.find { |setting| setting[:name] == name }
|
|
end
|
|
end
|
|
|
|
let(:loader) { Loader.new }
|
|
|
|
it "guesses types correctly" do
|
|
expect(loader.find_by_name(:boolean_setting)[:type]).to eq(types[:bool])
|
|
expect(loader.find_by_name(:boolean_setting_02)[:type]).to eq(types[:bool])
|
|
expect(loader.find_by_name(:string_setting)[:type]).to eq(types[:string])
|
|
expect(loader.find_by_name(:integer_setting)[:type]).to eq(types[:integer])
|
|
expect(loader.find_by_name(:integer_setting_03)[:type]).to eq(types[:integer])
|
|
expect(loader.find_by_name(:float_setting)[:type]).to eq(types[:float])
|
|
expect(loader.find_by_name(:list_setting)[:type]).to eq(types[:list])
|
|
expect(loader.find_by_name(:enum_setting)[:type]).to eq(types[:enum])
|
|
end
|
|
|
|
describe "description locale" do
|
|
it "favors I18n.locale" do
|
|
I18n.locale = :ar
|
|
SiteSetting.default_locale = "en"
|
|
expect(loader.find_by_name(:enum_setting_02)[:opts][:description]).to eq("Arabic text")
|
|
end
|
|
|
|
it "uses SiteSetting.default_locale if I18n.locale isn't supported" do
|
|
I18n.locale = :en
|
|
SiteSetting.default_locale = "es"
|
|
expect(loader.find_by_name(:integer_setting_02)[:opts][:description]).to eq("Spanish text")
|
|
end
|
|
|
|
it "finds the first supported locale and uses it as a last resort" do
|
|
I18n.locale = :de
|
|
SiteSetting.default_locale = "it"
|
|
expect(loader.find_by_name(:integer_setting_02)[:opts][:description]).to eq("French text")
|
|
end
|
|
|
|
it "doesn't set locale if no supported locale is provided" do
|
|
expect(loader.find_by_name(:integer_setting_03)[:opts][:description]).to be_nil
|
|
end
|
|
end
|
|
|
|
describe "enum setting" do
|
|
it "should never have less than 1 choices" do
|
|
choices = loader.find_by_name(:enum_setting)[:opts][:choices]
|
|
expect(choices.class).to eq(Array)
|
|
expect(choices.length).to eq(3)
|
|
|
|
choices = loader.find_by_name(:enum_setting_02)[:opts][:choices]
|
|
expect(choices.class).to eq(Array)
|
|
expect(choices.length).to eq(1)
|
|
end
|
|
end
|
|
|
|
describe "list setting" do
|
|
it "supports list type" do
|
|
list_type = loader.find_by_name(:compact_list_setting)[:opts][:list_type]
|
|
expect(list_type).to eq("compact")
|
|
end
|
|
end
|
|
end
|