2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-14 16:36:08 -04:00
|
|
|
require 'wizard'
|
|
|
|
require 'wizard/builder'
|
2018-12-19 04:20:48 -05:00
|
|
|
require 'global_path'
|
|
|
|
|
|
|
|
class GlobalPathInstance
|
|
|
|
extend GlobalPath
|
|
|
|
end
|
2016-09-14 16:36:08 -04:00
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Wizard::Builder do
|
2016-09-14 16:36:08 -04:00
|
|
|
let(:moderator) { Fabricate.build(:moderator) }
|
2018-11-22 01:19:36 -05:00
|
|
|
let(:wizard) { Wizard::Builder.new(moderator).build }
|
2016-09-14 16:36:08 -04:00
|
|
|
|
|
|
|
it "returns a wizard with steps when enabled" do
|
|
|
|
SiteSetting.wizard_enabled = true
|
|
|
|
|
|
|
|
expect(wizard).to be_present
|
|
|
|
expect(wizard.steps).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a wizard without steps when enabled, but not staff" do
|
|
|
|
wizard = Wizard::Builder.new(Fabricate.build(:user)).build
|
|
|
|
expect(wizard).to be_present
|
|
|
|
expect(wizard.steps).to be_blank
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a wizard without steps when disabled" do
|
|
|
|
SiteSetting.wizard_enabled = false
|
|
|
|
|
|
|
|
expect(wizard).to be_present
|
|
|
|
expect(wizard.steps).to be_blank
|
|
|
|
end
|
|
|
|
|
2022-10-06 02:32:48 -04:00
|
|
|
describe 'introduction' do
|
|
|
|
let(:introduction_step) { wizard.steps.find { |s| s.id == 'introduction' } }
|
|
|
|
|
|
|
|
it 'should not prefill default site setting values' do
|
|
|
|
fields = introduction_step.fields
|
|
|
|
title_field = fields.first
|
|
|
|
description_field = fields.second
|
|
|
|
contact_email_field = fields.third
|
|
|
|
|
|
|
|
expect(title_field.id).to eq('title')
|
|
|
|
expect(title_field.value).to eq("")
|
|
|
|
expect(description_field.id).to eq('site_description')
|
|
|
|
expect(description_field.value).to eq("")
|
|
|
|
expect(contact_email_field.id).to eq('contact_email')
|
|
|
|
expect(contact_email_field.value).to eq("")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should prefill overridden site setting values' do
|
|
|
|
SiteSetting.title = "foobar"
|
|
|
|
SiteSetting.site_description = "lorem ipsum"
|
|
|
|
SiteSetting.contact_email = "foobar@example.com"
|
|
|
|
|
|
|
|
fields = introduction_step.fields
|
|
|
|
title_field = fields.first
|
|
|
|
description_field = fields.second
|
|
|
|
contact_email_field = fields.third
|
|
|
|
|
|
|
|
expect(title_field.id).to eq('title')
|
|
|
|
expect(title_field.value).to eq("foobar")
|
|
|
|
expect(description_field.id).to eq('site_description')
|
|
|
|
expect(description_field.value).to eq("lorem ipsum")
|
|
|
|
expect(contact_email_field.id).to eq('contact_email')
|
|
|
|
expect(contact_email_field.value).to eq("foobar@example.com")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe 'privacy step' do
|
2022-07-26 21:23:01 -04:00
|
|
|
let(:privacy_step) { wizard.steps.find { |s| s.id == 'privacy' } }
|
2018-11-14 07:05:32 -05:00
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
it 'should set the right default value for the fields' do
|
|
|
|
SiteSetting.login_required = true
|
|
|
|
SiteSetting.invite_only = false
|
|
|
|
SiteSetting.must_approve_users = true
|
2022-12-12 16:30:21 -05:00
|
|
|
SiteSetting.chat_enabled = true if defined?(::Chat)
|
|
|
|
SiteSetting.navigation_menu = NavigationMenuSiteSetting::SIDEBAR
|
2022-07-26 21:23:01 -04:00
|
|
|
|
|
|
|
fields = privacy_step.fields
|
|
|
|
login_required_field = fields.first
|
|
|
|
invite_only_field = fields.second
|
2022-12-12 16:30:21 -05:00
|
|
|
must_approve_users_field = fields.third
|
|
|
|
chat_enabled_field = fields.second_to_last if defined?(::Chat)
|
|
|
|
navigation_menu_field = fields.last
|
2022-07-26 21:23:01 -04:00
|
|
|
|
2022-12-12 16:30:21 -05:00
|
|
|
count = defined?(::Chat) ? 5 : 4
|
|
|
|
expect(fields.length).to eq(count)
|
2022-07-26 21:23:01 -04:00
|
|
|
expect(login_required_field.id).to eq('login_required')
|
|
|
|
expect(login_required_field.value).to eq(true)
|
|
|
|
expect(invite_only_field.id).to eq('invite_only')
|
|
|
|
expect(invite_only_field.value).to eq(false)
|
|
|
|
expect(must_approve_users_field.id).to eq('must_approve_users')
|
|
|
|
expect(must_approve_users_field.value).to eq(true)
|
2022-12-12 16:30:21 -05:00
|
|
|
if defined?(::Chat)
|
|
|
|
expect(chat_enabled_field.id).to eq('chat_enabled')
|
|
|
|
expect(chat_enabled_field.value).to eq(true)
|
|
|
|
end
|
|
|
|
expect(navigation_menu_field.id).to eq('enable_sidebar')
|
|
|
|
expect(navigation_menu_field.value).to eq(true)
|
2022-07-26 21:23:01 -04:00
|
|
|
end
|
2018-11-14 07:05:32 -05:00
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe 'styling' do
|
2021-08-25 17:10:12 -04:00
|
|
|
let(:styling_step) { wizard.steps.find { |s| s.id == 'styling' } }
|
|
|
|
let(:font_field) { styling_step.fields[1] }
|
|
|
|
fab!(:theme) { Fabricate(:theme) }
|
|
|
|
let(:colors_field) { styling_step.fields.first }
|
2020-08-31 06:14:09 -04:00
|
|
|
|
2021-08-25 17:10:12 -04:00
|
|
|
it 'has the full list of available fonts' do
|
|
|
|
expect(font_field.choices.size).to eq(DiscourseFonts.fonts.size)
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "with colors" do
|
|
|
|
context "when the default theme has not been override" do
|
2021-08-25 17:10:12 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.find_by(name: "default_theme_id").destroy!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should set the right default values' do
|
|
|
|
expect(colors_field.required).to eq(true)
|
|
|
|
expect(colors_field.value).to eq(ColorScheme::LIGHT_THEME_ID)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when the default theme has been override and the color scheme doesn't have a base scheme" do
|
2021-08-25 17:10:12 -04:00
|
|
|
let(:color_scheme) { Fabricate(:color_scheme, base_scheme_id: nil) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.default_theme_id = theme.id
|
|
|
|
theme.update(color_scheme: color_scheme)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'fallbacks to the color scheme name' do
|
|
|
|
expect(colors_field.required).to eq(false)
|
|
|
|
expect(colors_field.value).to eq(color_scheme.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when the default theme has been overridden by a theme without a color scheme" do
|
2021-08-25 17:10:12 -04:00
|
|
|
before do
|
|
|
|
theme.set_default!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should set the right default values' do
|
|
|
|
expect(colors_field.required).to eq(false)
|
|
|
|
expect(colors_field.value).to eq("Light")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
context "when the default theme has been overridden by a theme with a color scheme" do
|
2021-08-25 17:10:12 -04:00
|
|
|
before do
|
|
|
|
theme.update(color_scheme_id: ColorScheme.find_by_name("Dark").id)
|
|
|
|
theme.set_default!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should set the right default values' do
|
|
|
|
expect(colors_field.required).to eq(false)
|
|
|
|
expect(colors_field.value).to eq("Dark")
|
|
|
|
end
|
|
|
|
end
|
2020-08-31 06:14:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe 'branding' do
|
2022-07-26 21:23:01 -04:00
|
|
|
let(:branding_step) { wizard.steps.find { |s| s.id == 'branding' } }
|
2018-11-22 01:19:36 -05:00
|
|
|
|
|
|
|
it 'should set the right default value for the fields' do
|
|
|
|
upload = Fabricate(:upload)
|
|
|
|
upload2 = Fabricate(:upload)
|
|
|
|
|
|
|
|
SiteSetting.logo = upload
|
|
|
|
SiteSetting.logo_small = upload2
|
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
fields = branding_step.fields
|
2018-11-22 01:19:36 -05:00
|
|
|
logo_field = fields.first
|
|
|
|
logo_small_field = fields.last
|
|
|
|
|
|
|
|
expect(logo_field.id).to eq('logo')
|
2018-12-19 04:20:48 -05:00
|
|
|
expect(logo_field.value).to eq(GlobalPathInstance.full_cdn_url(upload.url))
|
2018-11-22 01:19:36 -05:00
|
|
|
expect(logo_small_field.id).to eq('logo_small')
|
2018-12-19 04:20:48 -05:00
|
|
|
expect(logo_small_field.value).to eq(GlobalPathInstance.full_cdn_url(upload2.url))
|
2018-11-22 01:19:36 -05:00
|
|
|
end
|
|
|
|
end
|
2016-09-14 16:36:08 -04:00
|
|
|
end
|