Merge pull request #8465 from mfo/US/fix-repetition

Us/fix repetition
This commit is contained in:
mfo 2023-01-19 11:04:12 +01:00 committed by GitHub
commit 51e97b2d89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 8 deletions

View file

@ -1,9 +1,9 @@
- row_id = "row-#{@row.first.row_id}"
- row_id = "safe-row-selector-#{@row.first.row_id}"
.row{ id: row_id }
- @row.each do |champ|
= fields_for champ.input_name, champ do |form|
= render EditableChamp::EditableChampComponent.new form: form, champ: champ, seen_at: @seen_at
.flex.row-reverse{ 'data-turbo': 'true' }
= link_to champs_repetition_path(@champ.id, row_id:), data: { turbo_method: :delete }, class: 'fr-btn fr-btn--sm fr-btn--tertiary fr-text-action-high--red-marianne' do
= link_to champs_repetition_path(@champ.id, row_id: @row.first.row_id), data: { turbo_method: :delete }, class: 'fr-btn fr-btn--sm fr-btn--tertiary fr-text-action-high--red-marianne' do
Supprimer lélément

View file

@ -1 +1 @@
= turbo_stream.remove @row_id
= turbo_stream.remove "safe-row-selector-#{@row_id}"

View file

@ -0,0 +1,13 @@
describe Champs::RepetitionController, type: :controller do
describe '#remove' do
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :repetition, children: [{ libelle: 'Nom' }, { type: :integer_number, libelle: 'Age' }] }]) }
let(:dossier) { create(:dossier, procedure: procedure) }
before { sign_in dossier.user }
it 'removes repetition' do
rows, repetitions = dossier.champs.partition { _1.parent_id.present? }
expect { delete :remove, params: { champ_id: repetitions.first.id, row_id: rows.first.row_id }, format: :turbo_stream }
.to change { dossier.reload.champs.size }.from(3).to(1)
end
end
end

View file

@ -123,11 +123,12 @@ describe 'The user' do
expect(page).to have_content('Supprimer', count: 2)
expect do
within '.repetition .row:first-child' do
click_on 'Supprimer lélément'
end
expect(page).to have_content('Supprimer', count: 1)
end.to change { Champ.count }
end
let(:simple_procedure) { create(:procedure, :published, :for_individual, types_de_champ_public: [{ mandatory: true, libelle: 'texte obligatoire' }, { mandatory: false, libelle: 'texte optionnel' }]) }