diff --git a/app/assets/javascripts/description.js b/app/assets/javascripts/description.js new file mode 100644 index 000000000..7ca93b611 --- /dev/null +++ b/app/assets/javascripts/description.js @@ -0,0 +1,37 @@ +$(document).on('page:load', action_type_de_champs); +$(document).ready(action_type_de_champs); + + +function action_type_de_champs() { + $("input[type='email']").on('change', function () { + toggleErrorClass(this, validateEmail($(this).val())); + }); + + $("input[type='phone']").on('change', function () { + val = $(this).val(); + val = val.replace(/[ ]/g, ''); + + toggleErrorClass(this, validatePhone(val)); + }); +} + +function toggleErrorClass(node, boolean) { + if (boolean) + $(node).removeClass('input-error'); + else + $(node).addClass('input-error'); +} + +function validatePhone(phone) { + var re = /^(0|(\+[1-9]{2})|(00[1-9]{2}))[1-9][0-9]{8}$/; + return validateInput(phone, re) +} + +function validateEmail(email) { + var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + return validateInput(email, re) +} + +function validateInput(input, regex) { + return regex.test(input); +} \ No newline at end of file diff --git a/app/assets/stylesheets/description.scss b/app/assets/stylesheets/description.scss index 8f303ce15..38947921c 100644 --- a/app/assets/stylesheets/description.scss +++ b/app/assets/stylesheets/description.scss @@ -1,12 +1,17 @@ @import "bootstrap"; @import "bootstrap-datepicker3"; -#description_page #liste_champs{ - h4{ +#description_page #liste_champs { + h4 { margin-top: 35px; } } +.input-error { + color: darkred !important; + border-color: darkred !important +} + .type_champ-text { @extend .col-md-6; @extend .col-lg-6; @@ -16,12 +21,40 @@ } } +.type_champ-email { + @extend .col-md-4; + @extend .col-lg-4; + + input[type='email'] { + width: 100%; + } +} + +.type_champ-civilite { + @extend .col-md-3; + @extend .col-lg-3; +} + +.type_champ-phone { + @extend .col-md-2; + @extend .col-lg-2; + + input[type='phone'] { + width: 100%; + } +} + +.datepicker-switch { + color: #0086b3; + text-decoration: underline; +} + .type_champ-textarea { @extend .col-md-8; @extend .col-lg-8; textarea.form-control { - width:100%; + width: 100%; height: 133px; } } @@ -30,7 +63,7 @@ @extend .col-md-3; @extend .col-lg-3; - input[type='number']{ + input[type='number'] { width: 100%; } } @@ -39,7 +72,7 @@ @extend .col-md-2; @extend .col-lg-2; - input[type='number']{ + input[type='number'] { width: 100%; } } 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/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 0ace5c1b5..8ee4befa2 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -60,7 +60,7 @@ class Admin::ProceduresController < AdminController end flash.notice = 'Préocédure modifiée' - redirect_to admin_procedures_path + redirect_to edit_admin_procedure_path(id: @procedure.id) end def archive diff --git a/app/models/piece_justificative.rb b/app/models/piece_justificative.rb index 7bb2cdb34..4d80291b1 100644 --- a/app/models/piece_justificative.rb +++ b/app/models/piece_justificative.rb @@ -23,7 +23,7 @@ class PieceJustificative < ActiveRecord::Base (RemoteDownloader.new content.filename).url else (LocalDownloader.new content.path, - (type_de_piece_justificative.nil? ? content.original_filename : type_de_piece_justificative.libelle)).url + (type_de_piece_justificative.nil? ? content.original_filename : type_de_piece_justificative.libelle)).url end end end @@ -38,7 +38,9 @@ class PieceJustificative < ActiveRecord::Base application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.oasis.opendocument.text, application/vnd.oasis.opendocument.presentation, - application/vnd.oasis.opendocument.spreadsheet + application/vnd.oasis.opendocument.spreadsheet, + image/png, + image/jpeg " end end diff --git a/app/models/type_de_champ.rb b/app/models/type_de_champ.rb index 8bd7c8a95..aa5d4b87e 100644 --- a/app/models/type_de_champ.rb +++ b/app/models/type_de_champ.rb @@ -1,5 +1,8 @@ class TypeDeChamp < ActiveRecord::Base enum type_champs: {text: 'text', + email: 'email', + phone: 'phone', + civilite: 'civilite', textarea: 'textarea', datetime: 'datetime', number: 'number', diff --git a/app/uploaders/cerfa_uploader.rb b/app/uploaders/cerfa_uploader.rb index c69dcbac8..1f8371a38 100644 --- a/app/uploaders/cerfa_uploader.rb +++ b/app/uploaders/cerfa_uploader.rb @@ -25,7 +25,7 @@ class CerfaUploader < CarrierWave::Uploader::Base # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: def extension_white_list - %w(pdf doc docx xls xlsx ppt pptx odt ods odp) + %w(pdf doc docx xls xlsx ppt pptx odt ods odp jpg jpeg png) end def filename diff --git a/app/uploaders/piece_justificative_uploader.rb b/app/uploaders/piece_justificative_uploader.rb index ce446eb0a..c3cd6a556 100644 --- a/app/uploaders/piece_justificative_uploader.rb +++ b/app/uploaders/piece_justificative_uploader.rb @@ -25,7 +25,7 @@ class PieceJustificativeUploader < CarrierWave::Uploader::Base # Add a white list of extensions which are allowed to be uploaded. # For images you might use something like this: def extension_white_list - %w(pdf doc docx xls xlsx ppt pptx odt ods odp) + %w(pdf doc docx xls xlsx ppt pptx odt ods odp jpg jpeg png) end def filename diff --git a/app/uploaders/procedure_logo_uploader.rb b/app/uploaders/procedure_logo_uploader.rb index 1199b32fa..dab2a2f79 100644 --- a/app/uploaders/procedure_logo_uploader.rb +++ b/app/uploaders/procedure_logo_uploader.rb @@ -36,7 +36,7 @@ class ProcedureLogoUploader < CarrierWave::Uploader::Base if Features.remote_storage filename = "#{model.class.to_s.underscore}-#{secure_token}.#{file.extension.downcase}" else - filename = "logo.#{file.extension.downcase}" + filename = "logo-#{secure_token}.#{file.extension.downcase}" end end filename diff --git a/app/views/admin/accompagnateurs/show.html.haml b/app/views/admin/accompagnateurs/show.html.haml index d4bee085c..edcac3188 100644 --- a/app/views/admin/accompagnateurs/show.html.haml +++ b/app/views/admin/accompagnateurs/show.html.haml @@ -1,9 +1,4 @@ -%h2.text-info - =@procedure.libelle -%br - -%ul.nav.nav-tabs - = render partial: 'admin/procedures/navbar', locals: {active: 'Accompagnateurs'} +=render partial: 'admin/procedures/head', locals: {active: 'Accompagnateurs'} #accompagnateur_form .row diff --git a/app/views/admin/pieces_justificatives/show.html.haml b/app/views/admin/pieces_justificatives/show.html.haml index 6fdc68a99..5ca55f972 100644 --- a/app/views/admin/pieces_justificatives/show.html.haml +++ b/app/views/admin/pieces_justificatives/show.html.haml @@ -1,9 +1,4 @@ -%h2.text-info - =@procedure.libelle -%br - -%ul.nav.nav-tabs - = render partial: 'admin/procedures/navbar', locals: {active: 'Pieces'} +=render partial: 'admin/procedures/head', locals: {active: 'Pieces'} #piece_justificative_form = render 'form' \ 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..01c815d6b --- /dev/null +++ b/app/views/admin/previsualisations/show.html.haml @@ -0,0 +1,4 @@ +=render partial: 'admin/procedures/head', locals: {active: 'Prévisualisation'} + +#previsualisation + =render 'users/description/show' \ No newline at end of file diff --git a/app/views/admin/procedures/_head.html.haml b/app/views/admin/procedures/_head.html.haml new file mode 100644 index 000000000..185fd711e --- /dev/null +++ b/app/views/admin/procedures/_head.html.haml @@ -0,0 +1,8 @@ +%h2.text-info + -unless @procedure.logo.blank? + = image_tag @procedure.logo, style: 'width: 30px' + =@procedure.libelle +%br + +%ul.nav.nav-tabs + = render partial: 'admin/procedures/navbar', locals: {active: active} \ No newline at end of file diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index 199762600..c71686181 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -14,7 +14,9 @@ .row .col-md-6.col-lg-6 %h4 Logo de la procédure - = f.file_field(:logo, accept: 'image/png, image/jpg,image/jpeg') + - unless @procedure.logo.blank? + = image_tag @procedure.logo, {style: 'height: 40px; display: inline; margin-right: 6px', id: 'preview_procedure_logo'} + = f.file_field(:logo, accept: 'image/png, image/jpg, image/jpeg', style: 'display:inline') %div{style:'margin-top:5px'} %i 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/edit.html.haml b/app/views/admin/procedures/edit.html.haml index cc799d336..afbfaf50f 100644 --- a/app/views/admin/procedures/edit.html.haml +++ b/app/views/admin/procedures/edit.html.haml @@ -1,9 +1,4 @@ -%h2.text-info - =@procedure.libelle -%br - -%ul.nav.nav-tabs - = render partial: 'navbar', locals: {active: 'Description'} += render partial: 'head', locals: {active: 'Description'} #procedure_new.section.section-label = form_for @procedure, url: url_for({controller: 'admin/procedures', action: :update, id: @procedure.id}), multipart: true do |f| 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..6bb99288b 100644 --- a/app/views/admin/procedures/show.html.haml +++ b/app/views/admin/procedures/show.html.haml @@ -1,26 +1,20 @@ #procedure_show - %h2.text-info - =@facade.procedure.libelle - %br + =render partial: 'head', locals: {active: 'Informations'} - %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/admin/types_de_champ/show.html.haml b/app/views/admin/types_de_champ/show.html.haml index a89627788..2dbac0970 100644 --- a/app/views/admin/types_de_champ/show.html.haml +++ b/app/views/admin/types_de_champ/show.html.haml @@ -1,9 +1,4 @@ -%h2.text-info - =@procedure.libelle -%br - -%ul.nav.nav-tabs - = render partial: 'admin/procedures/navbar', locals: {active: 'Champs'} +=render partial: 'admin/procedures/head', locals: {active: 'Champs'} #liste_champ = render partial: 'form' \ No newline at end of file diff --git a/app/views/users/description/_champs.html.haml b/app/views/users/description/_champs.html.haml new file mode 100644 index 000000000..d1a724967 --- /dev/null +++ b/app/views/users/description/_champs.html.haml @@ -0,0 +1,38 @@ +-@champs.each do |champ| + .row + %div{class: "type_champ-#{champ.type_champ}"} + -if champ.type_champ == 'checkbox' + %h4{style:'margin-left:15px;'} + = champ.libelle + - if champ.mandatory? + = '*' + %input{type: 'hidden', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", value: ''} + %input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.value == 'on')} + -else + %h4 + = champ.libelle + - if champ.mandatory? + = '*' + + -if champ.type_champ == 'textarea' + %textarea.form-control{name:"champs['#{champ.id}']", + placeholder: champ.libelle, + id: "champs_#{champ.id}"} + =champ.value + -elsif champ.type_champ == 'civilite' + %label.radio-inline + = radio_button_tag "champs['#{champ.id}']", "M.", champ.value == 'Mme' ? false : true + Monsieur + + %label.radio-inline + = radio_button_tag "champs['#{champ.id}']", "Mme", champ.value == 'Mme' + Madame + + -else + %input.form-control{name:"champs['#{champ.id}']", + placeholder: champ.libelle, + id: "champs_#{champ.id}", + value: champ.value, + type: champ.type_champ, + 'data-provide' => ('datepicker' if champ.type_champ == 'datetime'), + 'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')} \ No newline at end of file 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 a1d9b0300..74930f900 100644 --- a/app/views/users/description/show.html.haml +++ b/app/views/users/description/show.html.haml @@ -1,76 +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? - -@champs.each do |champ| - .row - %div{class: "type_champ-#{champ.type_champ}"} - -if champ.type_champ == 'checkbox' - %h4{style:'margin-left:15px;'} - = champ.libelle - - if champ.mandatory? - = '*' - %input{type: 'hidden', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", value: ''} - %input{type: 'checkbox', style:'margin-left: 15px;', name:"champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.value == 'on')} - -else - %h4 - = champ.libelle - - if champ.mandatory? - = '*' - - -if champ.type_champ == 'textarea' - %textarea.form-control{name:"champs['#{champ.id}']", - placeholder: champ.libelle, - id: "champs_#{champ.id}"} - =champ.value - -else - %input.form-control{name:"champs['#{champ.id}']", - placeholder: champ.libelle, - id: "champs_#{champ.id}", - value: champ.value, - type:"#{champ.type_champ}", - 'data-provide' => ('datepicker' if champ.type_champ == 'datetime'), - 'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')} - - -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/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index bcfc2ded8..c4d414b0a 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -192,7 +192,7 @@ describe Admin::ProceduresController, type: :controller do it { expect(subject.cadastre).to be_truthy } end - it { expect(subject).to redirect_to(admin_procedures_path) } + it { expect(subject).to redirect_to(edit_admin_procedure_path id: procedure.id) } it { expect(flash[:notice]).to be_present } end 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/admin/procedures/edit.html.haml_spec.rb b/spec/views/admin/procedures/edit.html.haml_spec.rb new file mode 100644 index 000000000..44db3875c --- /dev/null +++ b/spec/views/admin/procedures/edit.html.haml_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe 'admin/procedures/edit.html.haml', type: :view do + let(:logo) { Rack::Test::UploadedFile.new("./spec/support/files/logo_test_procedure.png", 'image/png') } + let(:procedure) { create(:procedure, logo: logo) } + + before do + assign(:procedure, procedure) + render + end + + context 'when procedure logo is present' do + it 'display on the page' do + expect(rendered).to have_selector('#preview_procedure_logo') + end + end +end \ No newline at end of file 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)