From e6b5698008b4f4d27eb64c4986279defe2e3d22d Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 6 Jun 2016 17:40:32 +0200 Subject: [PATCH] Add previsualization formulaire page for administrateur --- .../admin/previsualisations_controller.rb | 13 ++ .../admin/previsualisations/show.html.haml | 9 + app/views/admin/procedures/_navbar.html.haml | 5 +- app/views/admin/procedures/new.html.haml | 3 + app/views/admin/procedures/show.html.haml | 29 ++- app/views/users/description/_show.html.haml | 50 +++++ app/views/users/description/show.html.haml | 49 +---- config/routes.rb | 1 + .../previsualisations_controller_spec.rb | 16 ++ .../previsualisations/show.html.haml_spec.rb | 172 ++++++++++++++++++ .../users/description/show.html.haml_spec.rb | 1 + 11 files changed, 284 insertions(+), 64 deletions(-) create mode 100644 app/controllers/admin/previsualisations_controller.rb create mode 100644 app/views/admin/previsualisations/show.html.haml create mode 100644 app/views/users/description/_show.html.haml create mode 100644 spec/controllers/admin/previsualisations_controller_spec.rb create mode 100644 spec/views/admin/previsualisations/show.html.haml_spec.rb diff --git a/app/controllers/admin/previsualisations_controller.rb b/app/controllers/admin/previsualisations_controller.rb new file mode 100644 index 000000000..22f39d343 --- /dev/null +++ b/app/controllers/admin/previsualisations_controller.rb @@ -0,0 +1,13 @@ +class Admin::PrevisualisationsController < AdminController + before_action :retrieve_procedure + + def show + @procedure + @dossier = Dossier.new(id: 0, procedure: @procedure) + + Champ.where(dossier_id: @dossier.id).destroy_all + @dossier.build_default_champs + + @champs = @dossier.ordered_champs + end +end \ No newline at end of file diff --git a/app/views/admin/previsualisations/show.html.haml b/app/views/admin/previsualisations/show.html.haml new file mode 100644 index 000000000..6e5ac9db8 --- /dev/null +++ b/app/views/admin/previsualisations/show.html.haml @@ -0,0 +1,9 @@ +%h2.text-info + =@procedure.libelle +%br + +%ul.nav.nav-tabs + = render partial: 'admin/procedures/navbar', locals: {active: 'Prévisualisation'} + +#previsualisation + =render 'users/description/show' \ No newline at end of file diff --git a/app/views/admin/procedures/_navbar.html.haml b/app/views/admin/procedures/_navbar.html.haml index 10bbe3d66..25198c9b0 100644 --- a/app/views/admin/procedures/_navbar.html.haml +++ b/app/views/admin/procedures/_navbar.html.haml @@ -14,4 +14,7 @@ %li{ class: ('disabled' if @procedure.locked?) || ('active' if active == 'Pieces') } = link_to_unless(@procedure.locked?, 'Pièces justificatives', admin_procedure_pieces_justificatives_path(@procedure)) do - = link_to('Pièces justificatives', '#') \ No newline at end of file + = link_to('Pièces justificatives', '#') + +%li{ class: ('active' if active == 'Prévisualisation'), style: 'float:right' } + = link_to('Prévisualisation', admin_procedure_previsualisation_path(@procedure), {style: 'font-style: italic;'}) \ No newline at end of file diff --git a/app/views/admin/procedures/new.html.haml b/app/views/admin/procedures/new.html.haml index 123a1b16c..d72bed14b 100644 --- a/app/views/admin/procedures/new.html.haml +++ b/app/views/admin/procedures/new.html.haml @@ -4,3 +4,6 @@ = form_for @procedure, url: {controller: 'admin/procedures', action: :create}, multipart: true do |f| =render partial: 'informations', locals: {f: f} =f.submit 'Valider', class: 'btn btn-info', style: 'float:right' + %br + %br + %br \ No newline at end of file diff --git a/app/views/admin/procedures/show.html.haml b/app/views/admin/procedures/show.html.haml index efb1d9e10..73ea9a435 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -6,21 +6,20 @@ %ul.nav.nav-tabs = render partial: 'navbar', locals: {active: 'Informations'} - %li{style:'float:right'} - = form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put do - %button#archive.btn.btn-nav.text-info{type: :button} - %i.fa.fa-eraser - - if @facade.procedure.archived - = 'Réactiver' - - else - = 'Archiver' - #confirm - %button#valid.btn.btn-nav.text-success{type: :submit} - %i.fa.fa-check - Valider - %button#cancel.btn.btn-nav.text-danger{type: :button} - %i.fa.fa-remove - Annuler + = form_tag admin_procedure_archive_path(procedure_id: @facade.procedure.id, archive: !@facade.procedure.archived?), method: :put, style:'float: right; margin-top: 10px' do + %button#archive.btn.btn-small.btn-default.text-info{type: :button} + %i.fa.fa-eraser + - if @facade.procedure.archived + = 'Réactiver' + - else + = 'Archiver' + #confirm + %button#valid.btn.btn-small.btn-success{type: :submit} + %i.fa.fa-check + Valider + %button#cancel.btn.btn-small.btn-danger{type: :button} + %i.fa.fa-remove + Annuler - if @facade.procedure.locked? #procedure_locked.center diff --git a/app/views/users/description/_show.html.haml b/app/views/users/description/_show.html.haml new file mode 100644 index 000000000..a42e114b0 --- /dev/null +++ b/app/views/users/description/_show.html.haml @@ -0,0 +1,50 @@ +.container#description_page + %h2 + = @dossier.procedure.libelle + %h3 Votre dossier + + %br + + -#TODO use form_for + = form_tag(url_for({controller: 'users/description', action: :create, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST', multipart: true) do + %div + .row + .col-md-12 + %h4 Libellé pour votre dossier * + = text_field_tag :nom_projet, @dossier.nom_projet, placeholder: 'Nom du projet', class: 'form-control' + %br + .row + .col-md-12 + %h4 Description * + = text_area_tag :description, @dossier.description, rows: '6', placeholder: 'Description du projet', class: 'form-control wysihtml5' + + #liste_champs + -unless @champs.nil? + =render partial: 'users/description/champs' + + -if !@procedure.lien_demarche.blank? || @procedure.cerfa_flag || @dossier.types_de_piece_justificative.size > 0 + %br + %h3 Documents administratifs + + -unless @procedure.lien_demarche.blank? + %p + Formulaire / documentation de la démarche : + %a{style:'font-size:0.9em; padding-left:3px', id: 'lien_cerfa' ,href: "#{@procedure.lien_demarche}", :target => '_blank'} Accéder + + + %br + //TODO a refactorer + = render partial: 'users/description/pieces_justificatives' + + - if user_signed_in? + + %div{style: 'text-align:right'} + %h6 Tous les champs portant un * sont obligatoires. + + -if !@dossier.draft? + =render partial: '/layouts/modifications_terminees' + -else + = submit_tag 'Soumettre mon dossier', id: 'suivant', class: %w(btn btn btn-success), style: 'float:right', data: { disable_with: 'Soumettre votre dossier', submit: true} + + %br + %br \ No newline at end of file diff --git a/app/views/users/description/show.html.haml b/app/views/users/description/show.html.haml index 17b06cbba..74930f900 100644 --- a/app/views/users/description/show.html.haml +++ b/app/views/users/description/show.html.haml @@ -1,48 +1 @@ -.container#description_page - %h2 - = @dossier.procedure.libelle - %h3 Votre dossier - - %br - - -#TODO use form_for - = form_tag(url_for({controller: :description, action: :create, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST', multipart: true) do - %div - .row - .col-md-12 - %h4 Libellé pour votre dossier * - = text_field_tag :nom_projet, @dossier.nom_projet, placeholder: 'Nom du projet', class: 'form-control' - %br - .row - .col-md-12 - %h4 Description * - = text_area_tag :description, @dossier.description, rows: '6', placeholder: 'Description du projet', class: 'form-control wysihtml5' - - #liste_champs - -unless @champs.nil? - =render partial: 'champs' - - -if !@procedure.lien_demarche.blank? || @procedure.cerfa_flag || @dossier.pieces_justificatives.size > 1 - %br - %h3 Documents administratifs - - -unless @procedure.lien_demarche.blank? - %p - Formulaire / documentation de la démarche : - %a{style:'font-size:0.9em; padding-left:3px', id: 'lien_cerfa' ,href: "#{@procedure.lien_demarche}", :target => '_blank'} Accéder - - - %br - //TODO a refactorer - = render partial: 'pieces_justificatives' - - %div{style: 'text-align:right'} - %h6 Tous les champs portant un * sont obligatoires. - - -if !@dossier.draft? - =render partial: '/layouts/modifications_terminees' - -else - = submit_tag 'Soumettre mon dossier', id: 'suivant', class: %w(btn btn btn-success), style: 'float:right', data: { disable_with: 'Soumettre votre dossier', submit: true} - - %br - %br \ No newline at end of file += render partial: 'show' \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 81964b8d6..03c1c4a11 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -94,6 +94,7 @@ Rails.application.routes.draw do resource :accompagnateurs, only: [:show, :update] + resource :previsualisation, only: [:show] resources :types_de_champ, only: [:destroy] resource :pieces_justificatives, only: [:show, :update] diff --git a/spec/controllers/admin/previsualisations_controller_spec.rb b/spec/controllers/admin/previsualisations_controller_spec.rb new file mode 100644 index 000000000..8c9836bfb --- /dev/null +++ b/spec/controllers/admin/previsualisations_controller_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe Admin::PrevisualisationsController, type: :controller do + let(:admin) { create(:administrateur) } + let(:procedure) { create :procedure, administrateur: admin } + + before do + sign_in admin + end + + describe 'GET #show' do + subject { get :show, procedure_id: procedure.id } + it { expect(subject.status).to eq(200) } + end + +end \ No newline at end of file diff --git a/spec/views/admin/previsualisations/show.html.haml_spec.rb b/spec/views/admin/previsualisations/show.html.haml_spec.rb new file mode 100644 index 000000000..06fc2a884 --- /dev/null +++ b/spec/views/admin/previsualisations/show.html.haml_spec.rb @@ -0,0 +1,172 @@ +require 'spec_helper' + +describe 'admin/previsualisations/show.html.haml', type: :view do + let(:user) { create(:user) } + let(:cerfa_flag) { true } + let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, cerfa_flag: cerfa_flag) } + let(:dossier) { create(:dossier, procedure: procedure, user: user) } + let(:dossier_id) { dossier.id } + + before do + assign(:dossier, dossier) + assign(:procedure, dossier.procedure) + assign(:champs, dossier.ordered_champs) + end + + context 'tous les attributs sont présents sur la page' do + before do + render + end + it 'Le formulaire envoie vers /users/dossiers/:dossier_id/description en #POST' do + expect(rendered).to have_selector("form[action='/users/dossiers/#{dossier_id}/description'][method=post]") + end + + it 'Nom du projet' do + expect(rendered).to have_selector('input[id=nom_projet][name=nom_projet]') + end + + it 'Description du projet' do + expect(rendered).to have_selector('textarea[id=description][name=description]') + end + + it 'Charger votre CERFA (PDF)' do + expect(rendered).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]') + end + + it 'Lien CERFA' do + expect(rendered).to have_selector('#lien_cerfa') + end + end + + context 'si la page précédente n\'est pas recapitulatif' do + before do + render + end + it 'le bouton "Terminer" n\'est pas présent' do + expect(rendered).not_to have_selector('#suivant') + end + end + + context 'si la page précédente est recapitularif' do + before do + dossier.initiated! + dossier.reload + render + end + + it 'le bouton "Terminer" n\'est pas présent' do + expect(rendered).to_not have_selector('#suivant') + end + + it 'le bouton "Modification terminé" n\'est pas présent' do + expect(rendered).not_to have_selector('#modification_terminee') + end + + it 'le lien de retour au récapitulatif n\'est pas présent' do + expect(rendered).not_to have_selector("a[href='/users/dossiers/#{dossier_id}/recapitulatif']") + end + end + + context 'les valeurs sont réaffichées si elles sont présentes dans la BDD' do + let!(:dossier) do + create(:dossier, + nom_projet: 'Projet de test', + description: 'Description de test', + user: user) + end + + before do + render + end + + it 'Nom du projet' do + expect(rendered).to have_selector("input[id=nom_projet][value='#{dossier.nom_projet}']") + end + + it 'Description du projet' do + expect(rendered).to have_content("#{dossier.description}") + end + end + + context 'Champs' do + let(:champs) { dossier.champs } + + before do + render + end + + describe 'first champs' do + subject { dossier.champs.first } + it { expect(rendered).to have_css(".type_champ-#{subject.type_champ}") } + it { expect(rendered).to have_css("#champs_#{subject.id}") } + end + + describe 'last champs' do + subject { dossier.champs.last } + it { expect(rendered).to have_css(".type_champ-#{subject.type_champ}") } + it { expect(rendered).to have_css("#champs_#{subject.id}") } + end + end + + context 'Pièces justificatives' do + let(:all_type_pj_procedure_id) { dossier.procedure.type_de_piece_justificative_ids } + + before do + render + end + + context 'la liste des pièces justificatives a envoyé est affichée' do + it 'RIB' do + expect(rendered).to have_css("#piece_justificative_#{all_type_pj_procedure_id[0]}") + end + end + + context 'la liste des pièces récupérées automatiquement est signaliée' do + it 'Attestation MSA' do + expect(rendered).to have_selector("#piece_justificative_#{all_type_pj_procedure_id[1]}", "Nous l'avons récupéré pour vous.") + end + end + end + + context 'Envoi des CERFA désactivé' do + let!(:cerfa_flag) { false } + + before do + render + end + + it { expect(rendered).to_not have_css("#cerfa_flag") } + it { expect(rendered).to_not have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]') } + end + + describe 'display title Documents administratifs' do + before do + render + end + + let(:procedure) { create :procedure, lien_demarche: '' } + let(:dossier) { create(:dossier, procedure: procedure) } + + context 'when dossier not have cerfa, piece justificative and demarche link' do + it { expect(rendered).not_to have_content 'Documents administratifs' } + end + + context 'when dossier have pj' do + let(:dossier) { create(:dossier) } + + it { expect(rendered).to have_content 'Documents administratifs' } + end + + context 'when procedure have demarche link' do + let(:procedure) { create :procedure } + + it { expect(rendered).to have_content 'Documents administratifs' } + end + + context 'when procedure have cerfa flag true' do + let(:procedure) {create(:procedure, cerfa_flag: true)} + + it { expect(rendered).to have_content 'Documents administratifs' } + end + end +end diff --git a/spec/views/users/description/show.html.haml_spec.rb b/spec/views/users/description/show.html.haml_spec.rb index 22b0060a9..e6c123b9c 100644 --- a/spec/views/users/description/show.html.haml_spec.rb +++ b/spec/views/users/description/show.html.haml_spec.rb @@ -8,6 +8,7 @@ describe 'users/description/show.html.haml', type: :view do let(:dossier_id) { dossier.id } before do + sign_in user assign(:dossier, dossier) assign(:procedure, dossier.procedure) assign(:champs, dossier.ordered_champs)