2016-09-15 04:36:08 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'wizard'
|
|
|
|
require 'wizard/builder'
|
2018-12-19 17:20:48 +08:00
|
|
|
require 'global_path'
|
|
|
|
|
|
|
|
class GlobalPathInstance
|
|
|
|
extend GlobalPath
|
|
|
|
end
|
2016-09-15 04:36:08 +08:00
|
|
|
|
|
|
|
describe Wizard::Builder do
|
|
|
|
let(:moderator) { Fabricate.build(:moderator) }
|
2018-11-22 14:19:36 +08:00
|
|
|
let(:wizard) { Wizard::Builder.new(moderator).build }
|
2016-09-15 04:36:08 +08: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
|
|
|
|
|
2018-11-14 20:05:32 +08:00
|
|
|
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
|
|
|
|
|
2018-11-22 14:19:36 +08:00
|
|
|
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')
|
2018-12-19 17:20:48 +08:00
|
|
|
expect(logo_field.value).to eq(GlobalPathInstance.full_cdn_url(upload.url))
|
2018-11-22 14:19:36 +08:00
|
|
|
expect(logo_small_field.id).to eq('logo_small')
|
2018-12-19 17:20:48 +08:00
|
|
|
expect(logo_small_field.value).to eq(GlobalPathInstance.full_cdn_url(upload2.url))
|
2018-11-22 14:19:36 +08:00
|
|
|
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
|
|
|
|
SiteSetting.apple_touch_icon = upload2
|
|
|
|
|
|
|
|
fields = icons_step.fields
|
|
|
|
favicon_field = fields.first
|
|
|
|
apple_touch_icon_field = fields.last
|
|
|
|
|
|
|
|
expect(favicon_field.id).to eq('favicon')
|
2018-12-19 17:20:48 +08:00
|
|
|
expect(favicon_field.value).to eq(GlobalPathInstance.full_cdn_url(upload.url))
|
2018-11-22 14:19:36 +08:00
|
|
|
expect(apple_touch_icon_field.id).to eq('apple_touch_icon')
|
2018-12-19 17:20:48 +08:00
|
|
|
expect(apple_touch_icon_field.value).to eq(GlobalPathInstance.full_cdn_url(upload2.url))
|
2018-11-22 14:19:36 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-15 19:20:48 +08:00
|
|
|
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
|
2019-04-11 22:55:08 +08:00
|
|
|
|
|
|
|
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 = false
|
|
|
|
|
|
|
|
fields = privacy_step.fields
|
|
|
|
login_required_field = fields.first
|
|
|
|
invite_only_field = fields.last
|
|
|
|
|
|
|
|
expect(login_required_field.id).to eq('privacy')
|
|
|
|
expect(login_required_field.value).to eq("restricted")
|
|
|
|
expect(invite_only_field.id).to eq('invite_only')
|
|
|
|
expect(invite_only_field.value).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2016-09-15 04:36:08 +08:00
|
|
|
end
|