diff --git a/app/javascript/new_design/administrateur/DraggableItem.js b/app/javascript/new_design/administrateur/DraggableItem.js index e1ff2a357..95d284120 100644 --- a/app/javascript/new_design/administrateur/DraggableItem.js +++ b/app/javascript/new_design/administrateur/DraggableItem.js @@ -130,9 +130,7 @@ export default { addChamp() { this.typesDeChamp.push({ type_champ: 'text', - drop_down_list: {}, - types_de_champ: [], - options: {} + types_de_champ: [] }); } } diff --git a/app/javascript/new_design/administrateur/champs-editor.js b/app/javascript/new_design/administrateur/champs-editor.js index 8445b458d..3b47de908 100644 --- a/app/javascript/new_design/administrateur/champs-editor.js +++ b/app/javascript/new_design/administrateur/champs-editor.js @@ -53,6 +53,14 @@ function initEditor(el) { this.update = update; this.updateAll = updateAll; + + // We add an initial type de champ here if form is empty + if (this.state.typesDeChamp.length === 0) { + this.state.typesDeChamp.push({ + type_champ: 'text', + types_de_champ: [] + }); + } } }); } diff --git a/spec/features/admin/procedure_creation_spec.rb b/spec/features/admin/procedure_creation_spec.rb index f8fd9a74a..eefc0853f 100644 --- a/spec/features/admin/procedure_creation_spec.rb +++ b/spec/features/admin/procedure_creation_spec.rb @@ -100,9 +100,6 @@ feature 'As an administrateur I wanna create a new procedure', js: true do page.refresh expect(page).to have_current_path(champs_procedure_path(Procedure.last)) - within '.footer' do - click_on 'Ajouter un champ' - end expect(page).to have_selector('#procedure_types_de_champ_attributes_0_libelle') fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ' expect(page).to have_content('Formulaire mis à jour') @@ -131,9 +128,6 @@ feature 'As an administrateur I wanna create a new procedure', js: true do scenario 'After adding champ and file, make publication' do page.refresh - within '.footer' do - click_on 'Ajouter un champ' - end fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ' expect(page).to have_content('Formulaire mis à jour') diff --git a/spec/features/new_administrateur/procedures_spec.rb b/spec/features/new_administrateur/procedures_spec.rb index 47ba7e66f..c1b3b1b8b 100644 --- a/spec/features/new_administrateur/procedures_spec.rb +++ b/spec/features/new_administrateur/procedures_spec.rb @@ -11,6 +11,8 @@ feature 'As an administrateur I edit procedure', js: true do end it "Add a new champ" do + click_on 'Supprimer' + within '.footer' do click_on 'Ajouter un champ' end @@ -31,7 +33,6 @@ feature 'As an administrateur I edit procedure', js: true do click_on 'Ajouter un champ' click_on 'Ajouter un champ' click_on 'Ajouter un champ' - click_on 'Ajouter un champ' end expect(page).not_to have_content('Le libellé doit être rempli.') expect(page).not_to have_content('Modifications non sauvegardées.') @@ -66,9 +67,6 @@ feature 'As an administrateur I edit procedure', js: true do end it "Remove champs" do - within '.footer' do - click_on 'Ajouter un champ' - end fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libellé de champ' expect(page).to have_content('Formulaire mis à jour') page.refresh @@ -78,13 +76,10 @@ feature 'As an administrateur I edit procedure', js: true do expect(page).not_to have_content('Supprimer') page.refresh - expect(page).not_to have_content('Supprimer') + expect(page).to have_content('Supprimer', count: 1) end it "Only add valid champs" do - within '.footer' do - click_on 'Ajouter un champ' - end expect(page).to have_selector('#procedure_types_de_champ_attributes_0_description') fill_in 'procedure_types_de_champ_attributes_0_description', with: 'déscription du champ' expect(page).to have_content('Le libellé doit être rempli.') @@ -95,9 +90,6 @@ feature 'As an administrateur I edit procedure', js: true do end it "Add repetition champ" do - within '.footer' do - click_on 'Ajouter un champ' - end expect(page).to have_selector('#procedure_types_de_champ_attributes_0_libelle') select('Bloc répétable', from: 'procedure_types_de_champ_attributes_0_type_champ') fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libellé de champ'