2020-08-20 20:10:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe WizardSerializer do
|
2020-08-20 20:10:33 -04:00
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
after do
|
|
|
|
ColorScheme.hex_cache.clear
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "color scheme" do
|
2020-08-20 20:10:33 -04:00
|
|
|
it "works with base colors" do
|
|
|
|
expect(Theme.where(id: SiteSetting.default_theme_id).first&.color_scheme).to be_nil
|
|
|
|
|
|
|
|
wizard = Wizard::Builder.new(admin).build
|
|
|
|
serializer = WizardSerializer.new(wizard, scope: Guardian.new(admin))
|
|
|
|
json = MultiJson.load(MultiJson.dump(serializer.as_json))
|
|
|
|
|
2022-06-06 03:22:44 -04:00
|
|
|
expect(json['wizard']['current_color_scheme'][0]['name']).to eq('primary')
|
|
|
|
expect(json['wizard']['current_color_scheme'][0]['hex']).to eq('222222')
|
2020-08-20 20:10:33 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should provide custom colors correctly" do
|
|
|
|
colors = ColorScheme.create_from_base(name: 'Customized', colors: { header_background: '00FF00', header_primary: '20CCFF' })
|
|
|
|
theme = Fabricate(:theme, color_scheme_id: colors.id)
|
|
|
|
|
|
|
|
SiteSetting.default_theme_id = theme.id
|
|
|
|
|
|
|
|
wizard = Wizard::Builder.new(admin).build
|
|
|
|
|
|
|
|
serializer = WizardSerializer.new(wizard, scope: Guardian.new(admin))
|
|
|
|
# serializer.as_json leaves in Ruby objects, force to true json
|
|
|
|
json = MultiJson.load(MultiJson.dump(serializer.as_json))
|
|
|
|
|
2022-06-06 03:22:44 -04:00
|
|
|
expect(json['wizard']['current_color_scheme'].to_s).to include('{"name"=>"header_background", "hex"=>"00FF00"}')
|
2020-08-20 20:10:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 12:14:14 -04:00
|
|
|
describe "steps" do
|
2020-08-20 20:10:33 -04:00
|
|
|
let(:wizard) { Wizard::Builder.new(admin).build }
|
|
|
|
let(:serializer) { WizardSerializer.new(wizard, scope: Guardian.new(admin)) }
|
|
|
|
|
|
|
|
it "has expected steps" do
|
2022-07-26 21:23:01 -04:00
|
|
|
SiteSetting.login_required = true
|
|
|
|
SiteSetting.invite_only = true
|
|
|
|
SiteSetting.must_approve_users = true
|
|
|
|
|
2020-08-20 20:10:33 -04:00
|
|
|
json = MultiJson.load(MultiJson.dump(serializer.as_json))
|
|
|
|
steps = json['wizard']['steps']
|
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
expect(steps.first['id']).to eq('introduction')
|
|
|
|
expect(steps.last['id']).to eq('corporate')
|
2020-08-20 20:10:33 -04:00
|
|
|
|
|
|
|
privacy_step = steps.find { |s| s['id'] == 'privacy' }
|
|
|
|
expect(privacy_step).to_not be_nil
|
2022-06-06 03:22:44 -04:00
|
|
|
|
2022-07-26 21:23:01 -04:00
|
|
|
login_required_field = privacy_step['fields'].find { |f| f['id'] == 'login_required' }
|
|
|
|
expect(login_required_field['value']).to eq(true)
|
|
|
|
|
|
|
|
invite_only_field = privacy_step['fields'].find { |f| f['id'] == 'invite_only' }
|
|
|
|
expect(invite_only_field['value']).to eq(true)
|
|
|
|
|
|
|
|
must_approve_users_field = privacy_step['fields'].find { |f| f['id'] == 'must_approve_users' }
|
|
|
|
expect(must_approve_users_field['value']).to eq(true)
|
2020-08-20 20:10:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|