extract checkboxes zones to dedicated page

This commit is contained in:
Christophe Robillard 2022-09-26 19:02:39 +02:00 committed by krichtof
parent 94ca93e130
commit 4d2c37ffdf
7 changed files with 91 additions and 52 deletions

View file

@ -1,6 +1,6 @@
module Administrateurs module Administrateurs
class ProceduresController < AdministrateurController class ProceduresController < AdministrateurController
before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :allow_expert_review, :experts_require_administrateur_invitation, :reset_draft] before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :zones, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :allow_expert_review, :experts_require_administrateur_invitation, :reset_draft]
before_action :procedure_revisable?, only: [:champs, :annotations, :modifications, :reset_draft] before_action :procedure_revisable?, only: [:champs, :annotations, :modifications, :reset_draft]
before_action :draft_valid?, only: [:apercu] before_action :draft_valid?, only: [:apercu]
@ -108,6 +108,9 @@ module Administrateurs
def edit def edit
end end
def zones
end
def create def create
@procedure = Procedure.new(procedure_params.merge(administrateurs: [current_administrateur])) @procedure = Procedure.new(procedure_params.merge(administrateurs: [current_administrateur]))
@procedure.draft_revision = @procedure.revisions.build @procedure.draft_revision = @procedure.revisions.build

View file

@ -13,12 +13,6 @@
%span.mandatory * %span.mandatory *
= f.text_area :description, rows: '6', placeholder: 'Description de la démarche, destinataires, etc. ', class: 'form-control' = f.text_area :description, rows: '6', placeholder: 'Description de la démarche, destinataires, etc. ', class: 'form-control'
- if Flipper.enabled? :zonage
= f.collection_check_boxes :zone_ids, Zone.available_at(@procedure.published_or_created_at), :id, :label do |b|
.editable-champ.editable-champ-checkbox
= b.check_box
= b.label
%h3.header-subsection Logo de la démarche %h3.header-subsection Logo de la démarche
= render Attachment::EditComponent.new(form: f, attached_file: @procedure.logo, direct_upload: true, user_can_destroy: true) = render Attachment::EditComponent.new(form: f, attached_file: @procedure.logo, direct_upload: true, user_can_destroy: true)

View file

@ -0,0 +1,27 @@
- content_for(:root_class, 'scroll-margins-for-sticky-footer')
= render partial: 'administrateurs/breadcrumbs',
locals: { steps: [['Démarches', admin_procedures_path],
[@procedure.libelle.truncate_words(10), admin_procedure_path(@procedure)],
['Description']] }
.container
= form_for @procedure,
url: url_for({ controller: 'administrateurs/procedures', action: :update, id: @procedure.id }),
multipart: true,
html: { class: 'form' } do |f|
%h1.page-title Zones
= f.label :zone do
= t('zone', scope: 'activerecord.attributes.procedure')
- if Flipper.enabled? :zonage
= f.collection_check_boxes :zone_ids, Zone.available_at(@procedure.published_or_created_at), :id, :label do |b|
.editable-champ.editable-champ-checkbox
= b.check_box
= b.label
.procedure-form__actions.sticky--bottom
.actions-right
= link_to 'Annuler', admin_procedure_path(id: @procedure), class: 'button', data: { confirm: 'Êtes-vous sûr de vouloir annuler les modifications effectuées ?'}
= f.button 'Enregistrer', class: 'button primary send'

View file

@ -431,6 +431,7 @@ Rails.application.routes.draw do
member do member do
get 'apercu' get 'apercu'
get 'champs' get 'champs'
get 'zones'
get 'annotations' get 'annotations'
get 'modifications' get 'modifications'
get 'monavis' get 'monavis'

View file

@ -12,6 +12,8 @@ describe Administrateurs::ProceduresController, type: :controller do
let(:duree_conservation_dossiers_dans_ds) { 3 } let(:duree_conservation_dossiers_dans_ds) { 3 }
let(:monavis_embed) { nil } let(:monavis_embed) { nil }
let(:lien_site_web) { 'http://mon-site.gouv.fr' } let(:lien_site_web) { 'http://mon-site.gouv.fr' }
let(:zone) { create(:zone) }
let(:zone_ids) { [zone.id] }
describe '#apercu' do describe '#apercu' do
render_views render_views
@ -55,6 +57,7 @@ describe Administrateurs::ProceduresController, type: :controller do
cadre_juridique: cadre_juridique, cadre_juridique: cadre_juridique,
duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds, duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds,
monavis_embed: monavis_embed, monavis_embed: monavis_embed,
zone_ids: zone_ids,
lien_site_web: lien_site_web lien_site_web: lien_site_web
} }
} }
@ -176,6 +179,14 @@ describe Administrateurs::ProceduresController, type: :controller do
end end
end end
describe 'GET #zones' do
let(:procedure) { create(:procedure, administrateur: admin) }
let(:procedure_id) { procedure.id }
subject { get :zones, params: { id: procedure_id } }
it { is_expected.to have_http_status(:success) }
end
describe 'POST #create' do describe 'POST #create' do
context 'when all attributs are filled' do context 'when all attributs are filled' do
describe 'new procedure in database' do describe 'new procedure in database' do

View file

@ -1,16 +1,6 @@
describe 'administrateurs/procedures/edit.html.haml' do describe 'administrateurs/procedures/edit.html.haml' do
let(:logo) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') } let(:logo) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
let(:procedure) { create(:procedure, logo: logo, lien_site_web: 'http://some.website') } let(:procedure) { create(:procedure, logo: logo, lien_site_web: 'http://some.website') }
let(:populate_zones_task) { Rake::Task['after_party:populate_zones'] }
before do
Flipper.enable(:zonage)
populate_zones_task.invoke
end
after do
populate_zones_task.reenable
end
context 'when procedure logo is present' do context 'when procedure logo is present' do
it 'display on the page' do it 'display on the page' do
@ -20,39 +10,4 @@ describe 'administrateurs/procedures/edit.html.haml' do
expect(rendered).to have_selector('.procedure-logos') expect(rendered).to have_selector('.procedure-logos')
end end
end end
context 'when procedure has never been published' do
before { Timecop.freeze(now) }
after { Timecop.return }
let(:procedure) { create(:procedure, zone: Zone.find_by(acronym: 'MTEI')) }
let(:now) { Time.zone.parse('18/05/2022') }
it 'displays zones with label available at the creation date' do
assign(:procedure, procedure)
render
expect(rendered).to have_content("Ministère du Travail")
expect(rendered).not_to have_content("Ministère du Travail, du Plein emploi et de l'Insertion")
end
end
context 'when procedure has been published' do
before { Timecop.freeze(now) }
after { Timecop.return }
let(:procedure) { create(:procedure, zone: Zone.find_by(acronym: 'MTEI')) }
let(:now) { Time.zone.parse('18/05/2022') }
it 'displays zones with label available at the creation date' do
Timecop.freeze(Time.zone.parse('22/05/2022')) do
procedure.publish!
end
assign(:procedure, procedure)
render
expect(rendered).to have_content("Ministère du Travail, du Plein emploi et de l'Insertion")
end
end
end end

View file

@ -0,0 +1,48 @@
describe 'administrateurs/procedures/zones.html.haml' do
let(:procedure) { create(:procedure) }
let(:populate_zones_task) { Rake::Task['after_party:populate_zones'] }
before do
Flipper.enable(:zonage)
populate_zones_task.invoke
end
after do
populate_zones_task.reenable
end
context 'when procedure has never been published' do
before { Timecop.freeze(now) }
after { Timecop.return }
let(:procedure) { create(:procedure, zones: [Zone.find_by(acronym: 'MTEI')]) }
let(:now) { Time.zone.parse('18/05/2022') }
it 'displays zones with label available at the creation date' do
assign(:procedure, procedure)
render
expect(rendered).to have_content("Ministère du Travail")
expect(rendered).not_to have_content("Ministère du Travail, du Plein emploi et de l'Insertion")
end
end
context 'when procedure has been published' do
before { Timecop.freeze(now) }
after { Timecop.return }
let(:procedure) { create(:procedure, zones: [Zone.find_by(acronym: 'MTEI')]) }
let(:now) { Time.zone.parse('18/05/2022') }
it 'displays zones with label available at the creation date' do
Timecop.freeze(Time.zone.parse('22/05/2022')) do
procedure.publish!
end
assign(:procedure, procedure)
render
expect(rendered).to have_content("Ministère du Travail, du Plein emploi et de l'Insertion")
end
end
end