First tests for prefill repetition

This commit is contained in:
Damien Le Thiec 2023-02-03 12:14:18 +01:00
parent e7c78321d9
commit 63e7c17fda
8 changed files with 47 additions and 7 deletions

View file

@ -7,7 +7,7 @@ module DossierPrefillableConcern
return unless champs_public_attributes.any?
attr = { prefilled: true }
attr[:champs_public_all_attributes] = champs_public_attributes.compact.map { |h| h.merge(prefilled: true) }
attr[:champs_public_all_attributes] = champs_public_attributes.map { |h| h.merge(prefilled: true) }
assign_attributes(attr)
save(validate: false)

View file

@ -198,6 +198,7 @@ FactoryBot.define do
parent = revision.revision_types_de_champ.find { |rtdc| rtdc.type_de_champ == type_de_champ_repetition }
build(:type_de_champ, procedure: evaluator.procedure, libelle: 'sub type de champ', parent: parent, position: 0)
build(:type_de_champ, type_champ: TypeDeChamp.type_champs.fetch(:integer_number), procedure: evaluator.procedure, libelle: 'sub type de champ2', parent: parent, position: 1)
end
end
end

View file

@ -545,12 +545,12 @@ describe Champ do
champ.champs << champ_integer
first_row = champ.reload.rows.first
expect(first_row.size).to eq(2)
expect(first_row.size).to eq(3)
expect(first_row.second).to eq(champ_integer)
champ.champs << champ_text
first_row = champ.reload.rows.first
expect(first_row.size).to eq(2)
expect(first_row.size).to eq(3)
expect(first_row.first).to eq(champ_text)
expect(champ.rows.size).to eq(2)

View file

@ -1861,7 +1861,7 @@ describe Dossier do
let(:champ_repetition) { create(:champ_repetition, type_de_champ: type_de_champ_repetition, dossier: dossier) }
before { dossier.champs_public << champ_repetition }
it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.count).to eq(2) }
it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.count).to eq(4) }
it { expect(Champs::RepetitionChamp.where(dossier: new_dossier).first.champs.ids).not_to eq(champ_repetition.champs.ids) }
end

View file

@ -22,6 +22,12 @@ RSpec.describe TypesDeChamp::PrefillTypeDeChamp, type: :model do
it { expect(built).to be_kind_of(TypesDeChamp::PrefillRegionTypeDeChamp) }
end
context 'when the type de champ is a repetition' do
let(:type_de_champ) { build(:type_de_champ_repetition) }
it { expect(built).to be_kind_of(TypesDeChamp::PrefillRepetitionTypeDeChamp) }
end
context 'when any other type de champ' do
let(:type_de_champ) { build(:type_de_champ_date) }

View file

@ -18,5 +18,8 @@ shared_examples "the user has got a prefilled dossier, owned by themselves" do
expect(page).to have_field(type_de_champ_text.libelle, with: text_value)
expect(page).to have_field(type_de_champ_phone.libelle, with: phone_value)
expect(page).to have_css('label', text: type_de_champ_phone.libelle)
expect(page).to have_css('h3', text: type_de_champ_repetition.libelle)
expect(page).to have_field(text_repetition_libelle, with: text_repetition_value)
expect(page).to have_field(integer_repetition_libelle, with: integer_repetition_value)
end
end

View file

@ -6,8 +6,14 @@ describe 'Prefilling a dossier (with a GET request):' do
let(:type_de_champ_text) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_phone) { create(:type_de_champ_phone, procedure: procedure) }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure) }
let(:text_value) { "My Neighbor Totoro is the best movie ever" }
let(:phone_value) { "invalid phone value" }
let(:sub_type_de_champs_repetition) { type_de_champ_repetition.active_revision_type_de_champ.revision_types_de_champ.map(&:type_de_champ) }
let(:text_repetition_libelle) { sub_type_de_champs_repetition.first.libelle }
let(:integer_repetition_libelle) { sub_type_de_champs_repetition.second.libelle }
let(:text_repetition_value) { "First repetition text" }
let(:integer_repetition_value) { "42" }
context 'when authenticated' do
it_behaves_like "the user has got a prefilled dossier, owned by themselves" do
@ -20,7 +26,13 @@ describe 'Prefilling a dossier (with a GET request):' do
visit commencer_path(
path: procedure.path,
"champ_#{type_de_champ_text.to_typed_id}" => text_value,
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_repetition.to_typed_id}" => [
"{
\"#{sub_type_de_champs_repetition.first.libelle}\": \"#{text_repetition_value}\",
\"#{sub_type_de_champs_repetition.second.libelle}\": \"#{integer_repetition_value}\"
}"
]
)
click_on "Commencer la démarche"
@ -33,7 +45,13 @@ describe 'Prefilling a dossier (with a GET request):' do
visit commencer_path(
path: procedure.path,
"champ_#{type_de_champ_text.to_typed_id}" => text_value,
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_repetition.to_typed_id}" => [
"{
\"#{sub_type_de_champs_repetition.first.libelle}\": \"#{text_repetition_value}\",
\"#{sub_type_de_champs_repetition.second.libelle}\": \"#{integer_repetition_value}\"
}"
]
)
end

View file

@ -6,8 +6,14 @@ describe 'Prefilling a dossier (with a POST request):' do
let(:type_de_champ_text) { create(:type_de_champ_text, procedure: procedure) }
let(:type_de_champ_phone) { create(:type_de_champ_phone, procedure: procedure) }
let(:type_de_champ_repetition) { create(:type_de_champ_repetition, :with_types_de_champ, procedure: procedure) }
let(:text_value) { "My Neighbor Totoro is the best movie ever" }
let(:phone_value) { "invalid phone value" }
let(:sub_type_de_champs_repetition) { type_de_champ_repetition.active_revision_type_de_champ.revision_types_de_champ.map(&:type_de_champ) }
let(:text_repetition_libelle) { sub_type_de_champs_repetition.first.libelle }
let(:integer_repetition_libelle) { sub_type_de_champs_repetition.second.libelle }
let(:text_repetition_value) { "First repetition text" }
let(:integer_repetition_value) { "42" }
scenario "the user get the URL of a prefilled orphan brouillon dossier" do
dossier_url = create_and_prefill_dossier_with_post_request
@ -95,7 +101,13 @@ describe 'Prefilling a dossier (with a POST request):' do
headers: { "Content-Type" => "application/json" },
params: {
"champ_#{type_de_champ_text.to_typed_id}" => text_value,
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value
"champ_#{type_de_champ_phone.to_typed_id}" => phone_value,
"champ_#{type_de_champ_repetition.to_typed_id}" => [
"{
\"#{sub_type_de_champs_repetition.first.libelle}\": \"#{text_repetition_value}\",
\"#{sub_type_de_champs_repetition.second.libelle}\": \"#{integer_repetition_value}\"
}"
]
}.to_json
JSON.parse(session.response.body)["dossier_url"].gsub("http://www.example.com", "")
end