discourse/spec/components/wizard/wizard_builder_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

211 lines
6.5 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'rails_helper'
require 'wizard'
require 'wizard/builder'
require 'global_path'
class GlobalPathInstance
extend GlobalPath
end
describe Wizard::Builder do
let(:moderator) { Fabricate.build(:moderator) }
let(:wizard) { Wizard::Builder.new(moderator).build }
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
it "returns wizard with disabled invites step when local_logins are off" do
SiteSetting.enable_local_logins = false
invites_step = wizard.steps.find { |s| s.id == "invites" }
expect(invites_step.fields).to be_blank
expect(invites_step.disabled).to be_truthy
end
context 'styling step' do
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 }
it 'has the full list of available fonts' do
expect(font_field.choices.size).to eq(DiscourseFonts.fonts.size)
end
context "colors" do
describe "when the default theme has not been override" do
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
describe "when the default theme has been override and the color scheme doesn't have a base scheme" do
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
describe "when the default theme has been overridden by a theme without a color scheme" do
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
describe "when the default theme has been overridden by a theme with a color scheme" do
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
end
end
context 'logos step' do
let(:logos_step) { wizard.steps.find { |s| s.id == 'logos' } }
it 'should set the right default value for the fields' do
upload = Fabricate(:upload)
upload2 = Fabricate(:upload)
SiteSetting.logo = upload
SiteSetting.logo_small = upload2
fields = logos_step.fields
logo_field = fields.first
logo_small_field = fields.last
expect(logo_field.id).to eq('logo')
expect(logo_field.value).to eq(GlobalPathInstance.full_cdn_url(upload.url))
expect(logo_small_field.id).to eq('logo_small')
expect(logo_small_field.value).to eq(GlobalPathInstance.full_cdn_url(upload2.url))
end
end
context 'icons step' do
let(:icons_step) { wizard.steps.find { |s| s.id == 'icons' } }
it 'should set the right default value for the fields' do
upload = Fabricate(:upload)
upload2 = Fabricate(:upload)
SiteSetting.favicon = upload
FEATURE: Automatically generate optimized site metadata icons (#7372) This change automatically resizes icons for various purposes. Admins can now upload `logo` and `logo_small`, and everything else will be auto-generated. Specific icons can still be uploaded separately if required. ## Core - Adds an SiteIconManager module which manages automatic resizing and fallback - Icons are looked up in the OptimizedImage table at runtime, and then cached in Redis. If the resized version is missing for some reason, then most icons will fall back to the original files. Some icons (e.g. PWA Manifest) will return `nil` (because an incorrectly sized icon is worse than a missing icon). - `SiteSetting.site_large_icon_url` will return the optimized version, including any fallback. `SiteSetting.large_icon` continues to return the upload object. This means that (almost) no changes are required in core/plugins to support this new system. - Icons are resized whenever a relevant site setting is changed, and during post-deploy migrations ## Wizard - Allows `requiresRefresh` wizard steps to reload data via AJAX instead of a full page reload - Add placeholders to the **icons** step of the wizard, which automatically update from the "Square Logo" - Various copy updates to support the changes - Remove the "upload-time" resizing for `large_icon`. This is no longer required. ## Site Settings UX - Move logo/icon settings under a new "Branding" tab - Various copy changes to support the changes - Adds placeholder support to the `image-uploader` component - Automatically reloads site settings after saving. This allows setting placeholders to change based on changes to other settings - Upload site settings will be assigned a placeholder if SiteIconManager `responds_to?` an icon of the same name ## Dashboard Warnings - Remove PWA icon and PWA title warnings. Both are now handled automatically. ## Bonus - Updated the sketch logos to use @awesomerobot's new high-res designs
2019-05-01 21:44:45 +08:00
SiteSetting.large_icon = upload2
fields = icons_step.fields
favicon_field = fields.first
FEATURE: Automatically generate optimized site metadata icons (#7372) This change automatically resizes icons for various purposes. Admins can now upload `logo` and `logo_small`, and everything else will be auto-generated. Specific icons can still be uploaded separately if required. ## Core - Adds an SiteIconManager module which manages automatic resizing and fallback - Icons are looked up in the OptimizedImage table at runtime, and then cached in Redis. If the resized version is missing for some reason, then most icons will fall back to the original files. Some icons (e.g. PWA Manifest) will return `nil` (because an incorrectly sized icon is worse than a missing icon). - `SiteSetting.site_large_icon_url` will return the optimized version, including any fallback. `SiteSetting.large_icon` continues to return the upload object. This means that (almost) no changes are required in core/plugins to support this new system. - Icons are resized whenever a relevant site setting is changed, and during post-deploy migrations ## Wizard - Allows `requiresRefresh` wizard steps to reload data via AJAX instead of a full page reload - Add placeholders to the **icons** step of the wizard, which automatically update from the "Square Logo" - Various copy updates to support the changes - Remove the "upload-time" resizing for `large_icon`. This is no longer required. ## Site Settings UX - Move logo/icon settings under a new "Branding" tab - Various copy changes to support the changes - Adds placeholder support to the `image-uploader` component - Automatically reloads site settings after saving. This allows setting placeholders to change based on changes to other settings - Upload site settings will be assigned a placeholder if SiteIconManager `responds_to?` an icon of the same name ## Dashboard Warnings - Remove PWA icon and PWA title warnings. Both are now handled automatically. ## Bonus - Updated the sketch logos to use @awesomerobot's new high-res designs
2019-05-01 21:44:45 +08:00
large_icon_field = fields.last
expect(favicon_field.id).to eq('favicon')
expect(favicon_field.value).to eq(GlobalPathInstance.full_cdn_url(upload.url))
FEATURE: Automatically generate optimized site metadata icons (#7372) This change automatically resizes icons for various purposes. Admins can now upload `logo` and `logo_small`, and everything else will be auto-generated. Specific icons can still be uploaded separately if required. ## Core - Adds an SiteIconManager module which manages automatic resizing and fallback - Icons are looked up in the OptimizedImage table at runtime, and then cached in Redis. If the resized version is missing for some reason, then most icons will fall back to the original files. Some icons (e.g. PWA Manifest) will return `nil` (because an incorrectly sized icon is worse than a missing icon). - `SiteSetting.site_large_icon_url` will return the optimized version, including any fallback. `SiteSetting.large_icon` continues to return the upload object. This means that (almost) no changes are required in core/plugins to support this new system. - Icons are resized whenever a relevant site setting is changed, and during post-deploy migrations ## Wizard - Allows `requiresRefresh` wizard steps to reload data via AJAX instead of a full page reload - Add placeholders to the **icons** step of the wizard, which automatically update from the "Square Logo" - Various copy updates to support the changes - Remove the "upload-time" resizing for `large_icon`. This is no longer required. ## Site Settings UX - Move logo/icon settings under a new "Branding" tab - Various copy changes to support the changes - Adds placeholder support to the `image-uploader` component - Automatically reloads site settings after saving. This allows setting placeholders to change based on changes to other settings - Upload site settings will be assigned a placeholder if SiteIconManager `responds_to?` an icon of the same name ## Dashboard Warnings - Remove PWA icon and PWA title warnings. Both are now handled automatically. ## Bonus - Updated the sketch logos to use @awesomerobot's new high-res designs
2019-05-01 21:44:45 +08:00
expect(large_icon_field.id).to eq('large_icon')
expect(large_icon_field.value).to eq(GlobalPathInstance.full_cdn_url(upload2.url))
end
end
context 'introduction step' do
let(:wizard) { Wizard::Builder.new(moderator).build }
let(:introduction_step) { wizard.steps.find { |s| s.id == 'introduction' } }
context 'step has not been completed' do
it 'enables the step' do
expect(introduction_step.disabled).to be_nil
end
end
context 'step has been completed' do
before do
wizard = Wizard::Builder.new(moderator).build
introduction_step = wizard.steps.find { |s| s.id == 'introduction' }
# manually sets the step as completed
logger = StaffActionLogger.new(moderator)
logger.log_wizard_step(introduction_step)
end
it 'disables step if no welcome topic' do
expect(introduction_step.disabled).to eq(true)
end
it 'enables step if welcome topic is present' do
topic = Fabricate(:topic, title: 'Welcome to Discourse')
welcome_post = Fabricate(:post, topic: topic, raw: "this will be the welcome topic post\n\ncool!")
expect(introduction_step.disabled).to be_nil
end
end
end
context 'privacy step' do
let(:privacy_step) { wizard.steps.find { |s| s.id == 'privacy' } }
it 'should set the right default value for the fields' do
SiteSetting.login_required = true
SiteSetting.invite_only = true
fields = privacy_step.fields
login_required_field = fields.first
privacy_options_field = fields.last
expect(fields.length).to eq(2)
expect(login_required_field.id).to eq('privacy')
expect(login_required_field.value).to eq("restricted")
expect(privacy_options_field.id).to eq('privacy_options')
expect(privacy_options_field.value).to eq("invite_only")
end
it 'should not show privacy_options field on special case' do
SiteSetting.invite_only = true
SiteSetting.must_approve_users = true
fields = privacy_step.fields
login_required_field = fields.first
expect(fields.length).to eq(1)
expect(login_required_field.id).to eq('privacy')
end
end
end