2018-12-27 11:41:16 +01:00
|
|
|
require 'rails_helper'
|
2016-12-16 14:40:20 +01:00
|
|
|
|
2018-12-27 11:41:16 +01:00
|
|
|
RSpec.describe ChampHelper, type: :helper do
|
2018-02-14 15:12:57 +01:00
|
|
|
let(:type_de_champ) { create(:type_de_champ) }
|
2018-02-13 17:00:19 +01:00
|
|
|
let(:champ) { type_de_champ.champ.create }
|
2016-12-16 14:40:20 +01:00
|
|
|
|
2018-12-27 11:41:16 +01:00
|
|
|
describe '.formatted_value' do
|
|
|
|
subject { formatted_value(champ) }
|
2016-12-16 14:40:20 +01:00
|
|
|
|
2017-03-15 17:51:12 +01:00
|
|
|
describe 'for a checkbox' do
|
2018-02-14 15:12:57 +01:00
|
|
|
let(:type_de_champ) { create(:type_de_champ_checkbox) }
|
2016-12-16 14:40:20 +01:00
|
|
|
|
|
|
|
context 'when value is on' do
|
2017-03-15 17:51:12 +01:00
|
|
|
before { champ.update value: 'on' }
|
2016-12-16 14:40:20 +01:00
|
|
|
it { is_expected.to eq 'Oui' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when value is other' do
|
|
|
|
it { is_expected.to eq 'Non' }
|
|
|
|
end
|
|
|
|
end
|
2017-03-15 17:51:12 +01:00
|
|
|
|
2017-09-14 10:57:40 +02:00
|
|
|
describe 'for a engagement' do
|
2018-02-14 15:12:57 +01:00
|
|
|
let(:type_de_champ) { create(:type_de_champ_engagement) }
|
2017-09-14 10:57:40 +02:00
|
|
|
|
|
|
|
context 'when value is on' do
|
|
|
|
before { champ.update value: 'on' }
|
|
|
|
it { is_expected.to eq 'Oui' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when value is other' do
|
|
|
|
it { is_expected.to eq 'Non' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-15 17:51:12 +01:00
|
|
|
describe 'for a multiple_drop_down_list' do
|
2018-02-14 15:12:57 +01:00
|
|
|
let(:type_de_champ) { create(:type_de_champ_multiple_drop_down_list) }
|
2017-03-15 17:51:12 +01:00
|
|
|
|
|
|
|
context 'when value is an array' do
|
|
|
|
before { champ.update value: '["1", "2"]' }
|
|
|
|
it { is_expected.to eq '1, 2' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when value is empty' do
|
|
|
|
before { champ.update value: '' }
|
|
|
|
it { is_expected.to eq '' }
|
|
|
|
end
|
|
|
|
end
|
2017-06-09 11:45:50 +02:00
|
|
|
|
|
|
|
describe "for a date" do
|
2018-02-14 15:12:57 +01:00
|
|
|
let(:type_de_champ) { create(:type_de_champ_date) }
|
2017-06-09 11:45:50 +02:00
|
|
|
|
|
|
|
context "when value is an ISO date" do
|
|
|
|
before { champ.update value: "2017-12-31" }
|
|
|
|
it { is_expected.to eq "31/12/2017" }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when value is empty" do
|
|
|
|
before { champ.update value: nil }
|
|
|
|
it { is_expected.to eq nil }
|
|
|
|
end
|
|
|
|
end
|
2016-12-16 14:40:20 +01:00
|
|
|
end
|
|
|
|
end
|