form: add number to section headers

This commit is contained in:
Pierre de La Morinerie 2020-02-10 19:15:42 +01:00
parent 2b47013798
commit f42977e40a
3 changed files with 37 additions and 0 deletions

View file

@ -2,4 +2,11 @@ class Champs::HeaderSectionChamp < Champ
def search_terms
# The user cannot enter any information here so it doesnt make much sense to search
end
def section_index
dossier
.champs
.filter { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:header_section) }
.index(self) + 1
end
end

View file

@ -1,2 +1,6 @@
- section_index = champ.section_index
%h2.header-section
- if section_index
= "#{section_index}."
= champ.libelle

View file

@ -0,0 +1,26 @@
require 'spec_helper'
describe Champs::CheckboxChamp do
let(:types_de_champ) do
[
create(:type_de_champ_header_section),
create(:type_de_champ_civilite),
create(:type_de_champ_text),
create(:type_de_champ_header_section),
create(:type_de_champ_email)
]
end
let(:procedure) { create(:procedure, types_de_champ: types_de_champ) }
let(:dossier) { create(:dossier, procedure: procedure) }
describe '#section_index' do
let(:first_header) { dossier.champs[0] }
let(:second_header) { dossier.champs[3] }
it 'returns the index of the section (starting from 1)' do
expect(first_header.section_index).to eq 1
expect(second_header.section_index).to eq 2
end
end
end