Skip to content

Commit

Permalink
test: en lien avec la nouvelle manière d'initialiser les drop_down_op…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
Benoit-MINT committed Aug 27, 2024
1 parent 2de093c commit 6eafe99
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
17 changes: 15 additions & 2 deletions spec/components/types_de_champ_editor/editor_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions spec/models/type_de_champ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6eafe99

Please sign in to comment.