diff --git a/spec/components/types_de_champ_editor/editor_component_spec.rb b/spec/components/types_de_champ_editor/editor_component_spec.rb index fb709498363..36c98417b93 100644 --- a/spec/components/types_de_champ_editor/editor_component_spec.rb +++ b/spec/components/types_de_champ_editor/editor_component_spec.rb @@ -2,13 +2,20 @@ let(:revision) { procedure.draft_revision } let(:procedure) { create(:procedure, id: 1, types_de_champ_private:, types_de_champ_public:) } - let(:types_de_champ_private) { [{ type: :drop_down_list, options: [], libelle: 'private' }] } - let(:types_de_champ_public) { [{ type: :drop_down_list, options: [], libelle: 'public' }] } + let(:types_de_champ_private) { [{ type: :drop_down_list, libelle: 'private' }] } + let(:types_de_champ_public) { [{ type: :drop_down_list, libelle: 'public' }] } describe 'render' do subject { render_inline(described_class.new(revision:, is_annotation:)) } + context 'types_de_champ_public' do + before do + drop_down = procedure.draft_revision.types_de_champ_public.find(&:drop_down_list?) + drop_down.update!(drop_down_list_value: "") + end + let(:is_annotation) { false } + it 'does not render private champs errors' do expect(subject).not_to have_text("private") expect(subject).to have_selector("a", text: "public") @@ -17,7 +24,13 @@ end context 'types_de_champ_private' do + before do + drop_down = procedure.draft_revision.types_de_champ_private.find(&:drop_down_list?) + drop_down.update!(drop_down_list_value: "") + end + let(:is_annotation) { true } + it 'does not render public champs errors' do expect(subject).to have_selector("a", text: "private") expect(subject).to have_text("doit comporter au moins un choix sélectionnable") diff --git a/spec/models/type_de_champ_spec.rb b/spec/models/type_de_champ_spec.rb index b3c7f1ce89b..00b439aaedc 100644 --- a/spec/models/type_de_champ_spec.rb +++ b/spec/models/type_de_champ_spec.rb @@ -106,18 +106,21 @@ let(:target_type_champ) { TypeDeChamp.type_champs.fetch(:text) } it { expect(tdc.drop_down_options).to be_present } + it { expect(tdc.drop_down_options).to eq(["val1", "val2", "val3"]) } end context 'when the target type_champ is linked_drop_down_list' do let(:target_type_champ) { TypeDeChamp.type_champs.fetch(:linked_drop_down_list) } it { expect(tdc.drop_down_options).to be_present } + it { expect(tdc.drop_down_options).to eq(['', '--Fromage--', 'bleu de sassenage', 'picodon', '--Dessert--', 'éclair', 'tarte aux pommes']) } end context 'when the target type_champ is multiple_drop_down_list' do let(:target_type_champ) { TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) } it { expect(tdc.drop_down_options).to be_present } + it { expect(tdc.drop_down_options).to eq(["val1", "val2", "val3"]) } end end diff --git a/spec/models/types_de_champ/prefill_multiple_drop_down_list_type_de_champ_spec.rb b/spec/models/types_de_champ/prefill_multiple_drop_down_list_type_de_champ_spec.rb index 3a825b41e61..9855749a586 100644 --- a/spec/models/types_de_champ/prefill_multiple_drop_down_list_type_de_champ_spec.rb +++ b/spec/models/types_de_champ/prefill_multiple_drop_down_list_type_de_champ_spec.rb @@ -10,25 +10,27 @@ end describe '#example_value' do - let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, drop_down_list_value: drop_down_list_value, procedure: procedure) } + let(:type_de_champ) { build(:type_de_champ_multiple_drop_down_list, procedure: procedure) } subject(:example_value) { described_class.new(type_de_champ, procedure.active_revision).example_value } context 'when the multiple drop down list has no option' do - let(:drop_down_list_value) { "" } + before do + type_de_champ.update!(drop_down_list_value: "") + end it { expect(example_value).to eq(nil) } end context 'when the multiple drop down list only has one option' do - let(:drop_down_list_value) { "value" } + before do + type_de_champ.update!(drop_down_list_value: "value") + end it { expect(example_value).to eq("value") } end context 'when the multiple drop down list has two options or more' do - let(:drop_down_list_value) { "value1\r\nvalue2\r\nvalue3" } - - it { expect(example_value).to eq(["value1", "value2"]) } + it { expect(example_value).to eq(["val1", "val2"]) } end end end