mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
DEV: Add choices only to relevant wizard fields (#16993)
This commit is contained in:
parent
eb40173121
commit
0a2eb7e2f4
@ -1,7 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class WizardFieldSerializer < ApplicationSerializer
|
||||
|
||||
attributes :id, :type, :required, :value, :label, :placeholder, :description, :extra_description, :show_in_sidebar
|
||||
has_many :choices, serializer: WizardFieldChoiceSerializer, embed: :objects
|
||||
|
||||
@ -76,4 +75,7 @@ class WizardFieldSerializer < ApplicationSerializer
|
||||
object.show_in_sidebar.present?
|
||||
end
|
||||
|
||||
def include_choices?
|
||||
object.type == "dropdown" || object.type == "radio"
|
||||
end
|
||||
end
|
||||
|
@ -14,10 +14,9 @@ describe WizardSerializer do
|
||||
wizard = Wizard::Builder.new(admin).build
|
||||
serializer = WizardSerializer.new(wizard, scope: Guardian.new(admin))
|
||||
json = MultiJson.load(MultiJson.dump(serializer.as_json))
|
||||
wjson = json['wizard']
|
||||
|
||||
expect(wjson['current_color_scheme'][0]['name']).to eq('primary')
|
||||
expect(wjson['current_color_scheme'][0]['hex']).to eq('222222')
|
||||
expect(json['wizard']['current_color_scheme'][0]['name']).to eq('primary')
|
||||
expect(json['wizard']['current_color_scheme'][0]['hex']).to eq('222222')
|
||||
end
|
||||
|
||||
it "should provide custom colors correctly" do
|
||||
@ -31,9 +30,8 @@ describe WizardSerializer do
|
||||
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))
|
||||
wjson = json['wizard']
|
||||
|
||||
expect(wjson['current_color_scheme'].to_s).to include('{"name"=>"header_background", "hex"=>"00FF00"}')
|
||||
expect(json['wizard']['current_color_scheme'].to_s).to include('{"name"=>"header_background", "hex"=>"00FF00"}')
|
||||
end
|
||||
end
|
||||
|
||||
@ -50,7 +48,9 @@ describe WizardSerializer do
|
||||
|
||||
privacy_step = steps.find { |s| s['id'] == 'privacy' }
|
||||
expect(privacy_step).to_not be_nil
|
||||
expect(privacy_step['fields'].find { |f| f['id'] == 'privacy' }['choices'].find { |c| c['id'] == 'open' }).to_not be_nil
|
||||
|
||||
privacy_field = privacy_step['fields'].find { |f| f['id'] == 'privacy' }
|
||||
expect(privacy_field['choices'].find { |c| c['id'] == 'open' }).to_not be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user