2016-12-16 10:07:40 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe DropDownList do
|
2017-03-15 17:47:26 +01:00
|
|
|
let(:dropdownlist) { create :drop_down_list, value: value }
|
|
|
|
|
2016-12-16 10:07:40 +01:00
|
|
|
describe '#options' do
|
2018-01-15 19:22:02 +01:00
|
|
|
let(:value) do
|
|
|
|
<<~EOS
|
|
|
|
Cohésion sociale
|
|
|
|
Dév.Eco / Emploi
|
|
|
|
Cadre de vie / Urb.
|
|
|
|
Pilotage / Ingénierie
|
|
|
|
EOS
|
|
|
|
end
|
2016-12-16 10:07:40 +01:00
|
|
|
|
2017-03-15 17:47:26 +01:00
|
|
|
it { expect(dropdownlist.options).to eq ['', 'Cohésion sociale', 'Dév.Eco / Emploi', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
|
2016-12-16 10:07:40 +01:00
|
|
|
|
|
|
|
context 'when one value is empty' do
|
2018-01-15 19:22:02 +01:00
|
|
|
let(:value) do
|
|
|
|
<<~EOS
|
|
|
|
Cohésion sociale
|
|
|
|
Cadre de vie / Urb.
|
|
|
|
Pilotage / Ingénierie
|
|
|
|
EOS
|
|
|
|
end
|
2016-12-16 10:07:40 +01:00
|
|
|
|
2017-03-15 17:47:26 +01:00
|
|
|
it { expect(dropdownlist.options).to eq ['', 'Cohésion sociale', 'Cadre de vie / Urb.', 'Pilotage / Ingénierie'] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'disabled_options' do
|
2018-01-15 19:22:02 +01:00
|
|
|
let(:value) do
|
|
|
|
<<~EOS
|
|
|
|
tip
|
|
|
|
--top--
|
|
|
|
--troupt--
|
|
|
|
ouaich
|
|
|
|
EOS
|
|
|
|
end
|
2017-03-15 17:47:26 +01:00
|
|
|
|
|
|
|
it { expect(dropdownlist.disabled_options).to match(['--top--', '--troupt--']) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'selected_options' do
|
|
|
|
let(:dropdownlist) do
|
|
|
|
create(:drop_down_list, type_de_champ: type_de_champ)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when multiple' do
|
2018-02-13 17:00:19 +01:00
|
|
|
let(:type_de_champ) { build(:type_de_champ, type_champ: 'multiple_drop_down_list') }
|
2018-02-09 17:50:10 +01:00
|
|
|
let(:champ) { type_de_champ.champ.build(value: '["1","2"]').decorate }
|
2017-03-15 17:47:26 +01:00
|
|
|
|
|
|
|
it { expect(dropdownlist.selected_options(champ)).to match(['1', '2']) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when simple' do
|
2018-02-13 17:00:19 +01:00
|
|
|
let(:type_de_champ) { build(:type_de_champ, type_champ: 'drop_down_list') }
|
2018-02-09 17:50:10 +01:00
|
|
|
let(:champ) { type_de_champ.champ.build(value: '1').decorate }
|
2017-03-15 17:47:26 +01:00
|
|
|
|
|
|
|
it { expect(dropdownlist.selected_options(champ)).to match(['1']) }
|
2016-12-16 10:07:40 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|