diff --git a/app/assets/javascripts/old_design/user/description.js b/app/assets/javascripts/old_design/user/description.js deleted file mode 100644 index c1ac0aabf..000000000 --- a/app/assets/javascripts/old_design/user/description.js +++ /dev/null @@ -1,5 +0,0 @@ -$(document).on('turbolinks:load', activeSelect2); - -function activeSelect2() { - $('select.select2').select2({ theme: "bootstrap", width: '100%' }); -} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index e163c9274..aa4da2aa3 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -51,8 +51,6 @@ // = require font-awesome // = require franceconnect // = require bootstrap-wysihtml5 -// = require select2 -// = require select2-bootstrap @import "constants"; @import "bootstrap-sprockets"; diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index 4116b24c5..e70091633 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -1,62 +1,4 @@ class Users::DescriptionController < UsersController - before_action only: [:show] do - authorized_routes? self.class - end - - before_action :check_autorisation_donnees, only: [:show] - before_action :check_starter_dossier_informations, only: [:show] - - def show - @dossier ||= current_user_dossier.decorate - - @procedure = @dossier.procedure - @champs = @dossier.ordered_champs - - @headers = @champs.select { |c| c.type_champ == 'header_section' } - - if !@dossier.can_be_en_construction? - flash[:alert] = t('errors.messages.procedure_archived') - end - - rescue ActiveRecord::RecordNotFound - flash.alert = t('errors.messages.dossier_not_found') - redirect_to url_for(root_path) - end - - def update - dossier = current_user_dossier - procedure = dossier.procedure - - return head :forbidden if !dossier.can_be_en_construction? - - ChampsService.save_champs(dossier.champs, params) if params[:champs] - - errors_upload = PiecesJustificativesService.upload!(dossier, current_user, params) + ChampsService.check_piece_justificative_files(dossier.champs) - return redirect_to_description_with_errors(dossier, errors_upload) if errors_upload.any? - - if params[:champs] && !(brouillon_submission? || brouillon_then_dashboard_submission?) - errors = - ChampsService.build_error_messages(dossier.champs) + - PiecesJustificativesService.missing_pj_error_messages(dossier) - return redirect_to_description_with_errors(dossier, errors) if errors.any? - end - - if brouillon_submission? - flash.notice = 'Votre brouillon a bien été sauvegardé.' - redirect_to users_dossier_description_path(dossier.id) - elsif brouillon_then_dashboard_submission? - redirect_to url_for(controller: :dossiers, action: :index, liste: :brouillon) - else - if dossier.brouillon? - dossier.en_construction! - # TODO move to model - NotificationMailer.send_initiated_notification(dossier).deliver_later - end - flash.notice = 'Félicitations, votre demande a bien été enregistrée.' - redirect_to url_for(controller: :recapitulatif, action: :show, dossier_id: dossier.id) - end - end - def pieces_justificatives invite = current_user.invite? params[:dossier_id] @@ -78,46 +20,4 @@ class Users::DescriptionController < UsersController redirect_to users_dossier_recapitulatif_path end - - def self.route_authorization - { - states: [:brouillon, :en_construction] - } - end - - private - - def redirect_to_description_with_errors(dossier, errors) - errors_to_display = if errors.count > 3 - errors.take(3) + ['...'] - else - errors - end - - flash.alert = errors_to_display - redirect_to users_dossier_description_path(dossier_id: dossier.id) - end - - def brouillon_submission? - params[:submit_action] == 'brouillon' - end - - def brouillon_then_dashboard_submission? - params[:submit_action] == 'brouillon_then_dashboard' - end - - def check_autorisation_donnees - @dossier = current_user_dossier - - redirect_to url_for(users_dossier_path(@dossier.id)) if @dossier.autorisation_donnees.nil? || !@dossier.autorisation_donnees - end - - def check_starter_dossier_informations - @dossier ||= current_user_dossier - - if (@dossier.procedure.for_individual? && @dossier.individual.nil?) || - (!@dossier.procedure.for_individual? && @dossier.etablissement.nil?) - redirect_to url_for(users_dossier_path(@dossier.id)) - end - end end diff --git a/app/javascript/packs/application-old.js b/app/javascript/packs/application-old.js index 6926ac025..38a2ae10f 100644 --- a/app/javascript/packs/application-old.js +++ b/app/javascript/packs/application-old.js @@ -11,7 +11,6 @@ import jQuery from 'jquery'; // required by the browsers we support will be included. import 'babel-polyfill'; -import 'select2'; import 'typeahead.js'; import '../shared/rails-ujs-fix'; diff --git a/app/views/admin/procedures/_modal_publish.html.haml b/app/views/admin/procedures/_modal_publish.html.haml index 14ad13e43..dc51848ce 100644 --- a/app/views/admin/procedures/_modal_publish.html.haml +++ b/app/views/admin/procedures/_modal_publish.html.haml @@ -1,4 +1,4 @@ -#publish-modal.modal.fade{ "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1" } +#publish-modal.modal{ "aria-labelledby" => "myModalLabel", :role => "dialog", :tabindex => "-1" } .modal-dialog.modal-lg{ :role => "document" } = form_tag admin_procedure_publish_path(procedure_id: @procedure.id), method: :put, remote: true do .modal-content diff --git a/app/views/shared/dossiers/_edit.html.haml b/app/views/shared/dossiers/_edit.html.haml index c43012547..2c83362b3 100644 --- a/app/views/shared/dossiers/_edit.html.haml +++ b/app/views/shared/dossiers/_edit.html.haml @@ -4,7 +4,7 @@ - if apercu - form_options = { url: '', method: :get, html: { class: 'form', multipart: true } } - else - - form_options = { html: { class: 'form', multipart: true, novalidate: dossier.brouillon? } } + - form_options = { url: modifier_dossier_url(dossier), method: :patch, html: { class: 'form', multipart: true, novalidate: dossier.brouillon? } } = form_for dossier, form_options do |f| diff --git a/app/views/users/description/_champs.html.haml b/app/views/users/description/_champs.html.haml deleted file mode 100644 index 9ba42c910..000000000 --- a/app/views/users/description/_champs.html.haml +++ /dev/null @@ -1,14 +0,0 @@ -- render_partial_url = private ? 'users/description/champs/header_private_section' : 'users/description/champs/header_section' -- @champs = @champs_private if private -- @headers = @headers_private if private - -- if @headers.present? - - if @champs.first.type_champ != 'header_section' - = render partial: render_partial_url, locals: { libelle: 'Dossier', order_place: -1, champs: @champs } - - @headers.each do |header| - .row - %div{ class: "type-champ-#{header.type_champ.gsub('_', '-')}" } - = render partial: render_partial_url, locals: { libelle: header.libelle, order_place: header.order_place, champs: @champs } -- else - .row - = render partial: render_partial_url, locals: { libelle: 'Dossier', order_place: -1, champs: @champs } diff --git a/app/views/users/description/champs/_checkbox.html.haml b/app/views/users/description/champs/_checkbox.html.haml deleted file mode 100644 index 1471a1873..000000000 --- a/app/views/users/description/champs/_checkbox.html.haml +++ /dev/null @@ -1 +0,0 @@ -%input{ type: 'checkbox', style: 'margin-left: 15px;', name: "champs['#{champ.id}']", id: "champs_#{champ.id}", checked: ('checked' if champ.object.value == 'on') } diff --git a/app/views/users/description/champs/_civilite.html.haml b/app/views/users/description/champs/_civilite.html.haml deleted file mode 100644 index 70071d5a8..000000000 --- a/app/views/users/description/champs/_civilite.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -%div - %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 diff --git a/app/views/users/description/champs/_date.html.haml b/app/views/users/description/champs/_date.html.haml deleted file mode 100644 index 7e0d94563..000000000 --- a/app/views/users/description/champs/_date.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%input.form-control{ name: "champs['#{champ.id}']", - placeholder: "JJ/MM/AAAA", - id: "champs_#{champ.id}", - value: champ.date_for_input, - type: "date" } diff --git a/app/views/users/description/champs/_datetime.html.haml b/app/views/users/description/champs/_datetime.html.haml deleted file mode 100644 index 1ed6a5584..000000000 --- a/app/views/users/description/champs/_datetime.html.haml +++ /dev/null @@ -1,16 +0,0 @@ -= render partial: 'users/description/champs/date', locals: { champ: champ } - -%br -%select.form-control{ name: "time_hour['#{champ.id}']", style: 'width:70px;display:inline;', id: "time_hour_#{champ.id}" } - - (0..23).each do |num| - - num = "%.2i" %num - %option{ value: num, selected: (:selected if champ.same_hour?(num)) } - = num -h -%select.form-control{ name: "time_minute['#{champ.id}']", style: 'width:70px;display:inline;', id: "time_minute_#{champ.id}" } - - (0..59).each do |num| - - num = "%.2i" %num - - if num.to_i%5 == 0 - %option{ value: num, selected: (:selected if champ.same_minute?(num)) } - = num -min diff --git a/app/views/users/description/champs/_departements.html.haml b/app/views/users/description/champs/_departements.html.haml deleted file mode 100644 index 6fb027390..000000000 --- a/app/views/users/description/champs/_departements.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -= select_tag("champs['#{champ.id}']", - options_for_select(Champs::DepartementChamp.departements, selected: champ.object.value)) diff --git a/app/views/users/description/champs/_dossier_link.html.haml b/app/views/users/description/champs/_dossier_link.html.haml deleted file mode 100644 index 7af6d5016..000000000 --- a/app/views/users/description/champs/_dossier_link.html.haml +++ /dev/null @@ -1,20 +0,0 @@ -- dossier = Dossier.find_by(id: champ.value) -- show_text_summary = dossier.present? -- show_warning = !show_text_summary && champ.value.present? -- text_summary = dossier&.text_summary - -.dossier-link - %input.form-control{ name: "champs['#{ champ.id }']", - placeholder: "Numéro de dossier", - id: "champs_#{ champ.id }", - value: champ.value, - type: 'number', - 'autocomplete' => 'off', - 'data-type' => 'dossier-link' } - - .help-block - %p.text-info{ style: show_text_summary ? nil : 'display: none;' } - %span.dossier-text-summary= text_summary - - %p.text-warning{ style: show_warning ? nil : 'display: none;' } - Ce dossier est inconnu diff --git a/app/views/users/description/champs/_drop_down_list.html.haml b/app/views/users/description/champs/_drop_down_list.html.haml deleted file mode 100644 index 2821104db..000000000 --- a/app/views/users/description/champs/_drop_down_list.html.haml +++ /dev/null @@ -1,7 +0,0 @@ -- if champ.drop_down_list && champ.drop_down_list.options.any? - = select_tag("champs['#{champ.id}']", - options_for_select(champ.drop_down_list.options, - selected: champ.drop_down_list.selected_options(champ), - disabled: champ.drop_down_list.disabled_options), - multiple: champ.drop_down_list.multiple, - class: 'select2') diff --git a/app/views/users/description/champs/_engagement.html.haml b/app/views/users/description/champs/_engagement.html.haml deleted file mode 100644 index caeb1140c..000000000 --- a/app/views/users/description/champs/_engagement.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -%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.object.value == 'on') } diff --git a/app/views/users/description/champs/_header_private_section.html.haml b/app/views/users/description/champs/_header_private_section.html.haml deleted file mode 100644 index b9d8bdacd..000000000 --- a/app/views/users/description/champs/_header_private_section.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -.row - .col-lg-12.col-md-12.col-sm-12.col-xs-12 - %br - %h3.text-info - = libelle - = render partial: 'users/description/champs/render_list_champs', locals: { champs: champs, order_place: order_place } diff --git a/app/views/users/description/champs/_header_section.html.haml b/app/views/users/description/champs/_header_section.html.haml deleted file mode 100644 index cafbe73ae..000000000 --- a/app/views/users/description/champs/_header_section.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -.default-data-block.default_visible - .row.show-block.infos - .header - .col-xs-12.title - .carret-right - .carret-down - .title-content - = libelle - .clearfix - .body - = render partial: 'users/description/champs/render_list_champs', locals: { champs: champs, order_place: order_place } diff --git a/app/views/users/description/champs/_pays.html.haml b/app/views/users/description/champs/_pays.html.haml deleted file mode 100644 index 67981205c..000000000 --- a/app/views/users/description/champs/_pays.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -= select_tag("champs['#{champ.id}']", - options_for_select(Champs::PaysChamp.pays, selected: champ.object.value)) diff --git a/app/views/users/description/champs/_piece_justificative.html.haml b/app/views/users/description/champs/_piece_justificative.html.haml deleted file mode 100644 index e32428721..000000000 --- a/app/views/users/description/champs/_piece_justificative.html.haml +++ /dev/null @@ -1,15 +0,0 @@ -- pj = champ.piece_justificative_file - -- if !pj.attached? - = file_field_tag "champs['#{champ.id}']", - id: "champs_#{champ.id}", - direct_upload: true, - mandatory: champ.mandatory? -- else - %a{ href: url_for(pj), target: '_blank' } - = pj.filename.to_s - %br - Modifier : - = file_field_tag "champs['#{champ.id}']", - id: "champs_#{champ.id}", - direct_upload: true diff --git a/app/views/users/description/champs/_regions.html.haml b/app/views/users/description/champs/_regions.html.haml deleted file mode 100644 index 24c6f4bc5..000000000 --- a/app/views/users/description/champs/_regions.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -= select_tag("champs['#{champ.id}']", - options_for_select(Champs::RegionChamp.regions, selected: champ.object.value)) diff --git a/app/views/users/description/champs/_render_list_champs.html.haml b/app/views/users/description/champs/_render_list_champs.html.haml deleted file mode 100644 index e7f5dab2a..000000000 --- a/app/views/users/description/champs/_render_list_champs.html.haml +++ /dev/null @@ -1,66 +0,0 @@ -- champs.decorate.each do |champ| - - if champ.order_place > order_place - - if champ.type_champ == 'header_section' - - break - - .row - %div{ class: if champ.type_champ == 'textarea' || champ.type_champ == 'engagement' then 'col-md-12' else 'col-md-6' end } - .form-group - %label{ for: "champs_#{champ.id}" } - = champ.libelle - - if champ.mandatory? - * - - - case champ.type_champ - - when 'textarea' - = render partial: 'users/description/champs/textarea', locals: { champ: champ } - - - when 'checkbox' - = render partial: 'users/description/champs/checkbox', locals: { champ: champ } - - - when 'civilite' - = render partial: 'users/description/champs/civilite', locals: { champ: champ } - - - when 'datetime' - = render partial: 'users/description/champs/datetime', locals: { champ: champ } - - - when 'yes_no' - = render partial: 'users/description/champs/yes_no', locals: { champ: champ } - - - when 'drop_down_list', 'multiple_drop_down_list' - = render partial: 'users/description/champs/drop_down_list', locals: { champ: champ } - - - when 'pays' - = render partial: 'users/description/champs/pays', locals: { champ: champ } - - - when 'regions' - = render partial: 'users/description/champs/regions', locals: { champ: champ } - - - when 'engagement' - = render partial: 'users/description/champs/engagement', locals: { champ: champ } - - - when 'departements' - = render partial: 'users/description/champs/departements', locals: { champ: champ } - - - when 'dossier_link' - = render partial: 'users/description/champs/dossier_link', locals: { champ: champ } - - - when 'explication' - - - when 'date' - = render partial: 'users/description/champs/date', locals: { champ: champ } - - - when 'piece_justificative' - = render partial: 'users/description/champs/piece_justificative', locals: { champ: champ } - - - else - %input.form-control{ name: "champs['#{champ.id}']", - placeholder: champ.libelle, - id: "champs_#{champ.id}", - value: champ.value, - type: champ.type_champ } - - - - if champ.description.present? - %div{ id: "description_champs_#{champ.id}", class: ('help-block' if champ.type_champ != 'engagement') } - = simple_format(sanitize(champ.description_with_links, attributes: %w(href target))) diff --git a/app/views/users/description/champs/_textarea.html.haml b/app/views/users/description/champs/_textarea.html.haml deleted file mode 100644 index 1ca81e00f..000000000 --- a/app/views/users/description/champs/_textarea.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%textarea.form-control.wysihtml5{ name: "champs['#{champ.id}']", - placeholder: champ.description, - id: "champs_#{champ.id}", - row: '6' } - = champ.value diff --git a/app/views/users/description/champs/_yes_no.html.haml b/app/views/users/description/champs/_yes_no.html.haml deleted file mode 100644 index 83d4622dc..000000000 --- a/app/views/users/description/champs/_yes_no.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -%div - %label.radio-inline - = radio_button_tag "champs['#{champ.id}']", "true", champ.object.value == 'true' - Oui - - %label.radio-inline - = radio_button_tag "champs['#{champ.id}']", "false", champ.object.value == 'false' - Non diff --git a/app/views/users/description/show.html.haml b/app/views/users/description/show.html.haml deleted file mode 100644 index 79ecf32ae..000000000 --- a/app/views/users/description/show.html.haml +++ /dev/null @@ -1,64 +0,0 @@ -.container#description-page - - if notice_url(@dossier.procedure).present? - #lien_notice_panel.row{ style: 'width: 280px; position: fixed; background-color: white; right: 5%; top: 80px; z-index: 200;' } - .panel.panel-info{ style: 'margin-bottom: 0;' } - .panel-body.center - .row - .col-xs-1 - .fa.fa-info-circle.text-info{ style: 'font-size: 2em; margin-top: 20%;' } - .col-xs-10{ style: 'padding-right: 0px;' } - %b - = link_to 'Accéder au guide', notice_url(@dossier.procedure), { target: '_blank' } - pour remplir pour votre dossier - - %h2.text-info - = @dossier.procedure.libelle - - -# TODO use form_for - = form_tag(url_for({ controller: 'users/description', action: :update, dossier_id: @dossier.id }), class: 'form', method: 'POST', multipart: true) do - - if @champs.present? - #liste-champs - = render partial: 'users/description/champs', locals: { private: false } - - - if @procedure.lien_demarche.present? || @dossier.types_de_piece_justificative.size > 0 - %br - %h3 Pièces jointes - - - -# TODO a refactorer - .row - .col-lg-8 - = render partial: 'users/description/pieces_justificatives', locals: { dossier: @dossier } - - %div{ style: 'text-align: right;' } - %h6 Tous les champs portant un * sont obligatoires. - - - if !@dossier.can_be_en_construction? - .alert.alert-danger - = t('errors.messages.procedure_archived') - - elsif !@dossier.brouillon? - = render partial: '/layouts/modifications_terminees' - - else - = hidden_field_tag 'submit_action', 'brouillon' - = submit_tag 'Bonjour Active Storage !', style: 'display: none;' - = button_tag 'Soumettre mon dossier', - id: 'suivant', - type: 'submit', - class: 'btn btn btn-success', - style: 'float: right;', - disabled: @procedure.archivee?, - data: { disable: true, action: 'nouveaux' } - = button_tag 'Enregistrer un brouillon', - id: 'brouillon', - type: 'submit', - class: 'btn btn-xs btn-default', - style: 'float: right; margin-right: 10px; margin-top: 6px;', - disabled: @procedure.archivee?, - data: { disable: true, action: 'brouillon' } - = button_tag "Enregistrer et voir mes dossiers", - id: 'brouillon_then_dashboard', - type: 'submit', - class: 'btn btn-xs btn-default', - style: 'float: right; margin-right: 10px; margin-top: 6px;', - disabled: @procedure.archivee?, - data: { disable: true, action: 'brouillon_then_dashboard' } diff --git a/config/routes.rb b/config/routes.rb index 663a9562f..ce2bf183c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,8 @@ Rails.application.routes.draw do + # + # Manager + # + get 'manager/sign_in' => 'administrations/sessions#new' delete 'manager/sign_out' => 'administrations/sessions#destroy' namespace :manager do @@ -38,8 +42,16 @@ Rails.application.routes.draw do root to: "administrateurs#index" end + # + # Monitoring + # + get "/ping" => "ping#index", :constraints => { :ip => /127.0.0.1/ } + # + # Authentication + # + devise_for :administrations, skip: [:password, :registrations, :sessions], controllers: { @@ -77,6 +89,10 @@ Rails.application.routes.draw do get '/administrateurs/sign_in/demo' => redirect("/users/sign_in") end + # + # Main routes + # + root 'root#index' get 'users' => 'users#index' @@ -95,6 +111,17 @@ Rails.application.routes.draw do get ':champ_id/siret' => 'siret#index', as: 'siret' end + namespace :commencer do + get '/test/:procedure_path' => '/users/dossiers#commencer_test', as: :test + get '/:procedure_path' => '/users/dossiers#commencer' + end + + get "patron" => "root#patron" + + # + # Deprecated UI + # + namespace :users do namespace :dossiers do resources :invites, only: [:index, :show] @@ -105,9 +132,6 @@ Rails.application.routes.draw do resources :dossiers do get '/add_siret' => 'dossiers/add_siret#show' - get 'description' => 'description#show' - post 'description' => 'description#update' - patch 'pieces_justificatives' => 'description#pieces_justificatives' get '/recapitulatif' => 'recapitulatif#show' @@ -209,6 +233,10 @@ Rails.application.routes.draw do resources :gestionnaires, only: [:index, :create, :destroy] end + # + # Addresses + # + namespace :ban do get 'search' => 'search#get' get 'address_point' => 'search#get_address_point' @@ -218,6 +246,10 @@ Rails.application.routes.draw do post 'dossier/:dossier_id' => '/invites#create', as: 'dossier' end + # + # API + # + namespace :api do namespace :v1 do resources :procedures, only: [:index, :show] do @@ -230,12 +262,9 @@ Rails.application.routes.draw do end end - namespace :commencer do - get '/test/:procedure_path' => '/users/dossiers#commencer_test', as: :test - get '/:procedure_path' => '/users/dossiers#commencer' - end - - get "patron" => "root#patron" + # + # User + # scope module: 'new_user' do resources :dossiers, only: [:index, :update] do @@ -243,6 +272,7 @@ Rails.application.routes.draw do get 'identite' patch 'update_identite' get 'modifier' + patch 'modifier', to: 'dossiers#update' get 'merci' post 'ask_deletion' get 'attestation' @@ -250,13 +280,14 @@ Rails.application.routes.draw do collection do post 'recherche' - # FIXME: to remove when show is implemeted - # needed to fix refresh after dossier draft save - get ':id', to: redirect('/dossiers/%{id}/modifier') end end end + # + # Gestionnaire + # + scope module: 'new_gestionnaire', as: 'gestionnaire' do resources :procedures, only: [:index, :show], param: :procedure_id do member do @@ -306,6 +337,10 @@ Rails.application.routes.draw do get "recherche" => "recherche#index" end + # + # Administrateur + # + scope module: 'new_administrateur' do resources :procedures, only: [] do member do @@ -322,7 +357,10 @@ Rails.application.routes.draw do apipie + # # Legacy routes + # + get 'backoffice' => redirect('/procedures') get 'backoffice/sign_in' => redirect('/users/sign_in') get 'backoffice/dossiers/procedure/:procedure_id' => redirect('/procedures/%{procedure_id}') diff --git a/spec/controllers/users/description_controller_shared_example.rb b/spec/controllers/users/description_controller_shared_example.rb deleted file mode 100644 index 04145cde8..000000000 --- a/spec/controllers/users/description_controller_shared_example.rb +++ /dev/null @@ -1,439 +0,0 @@ -shared_examples 'description_controller_spec' do - describe 'GET #show' do - before do - dossier.update_column :autorisation_donnees, true - end - context 'user is not connected' do - before do - sign_out dossier.user - end - - it 'redirects to users/sign_in' do - get :show, params: { dossier_id: dossier_id } - expect(response).to redirect_to('/users/sign_in') - end - end - - context 'when all is ok' do - before do - dossier.etablissement = create(:etablissement) - get :show, params: { dossier_id: dossier_id } - end - - it 'returns http success' do - expect(response).to have_http_status(:success) - end - - context 'procedure is archived' do - render_views - let(:archived) { true } - - it { expect(response).to have_http_status(:success) } - it { expect(response.body).to_not have_content(I18n.t('errors.messages.procedure_archived')) } - - context 'dossier is a brouillon' do - let(:state) { 'brouillon' } - - it { expect(response).to have_http_status(:success) } - it { expect(response.body).to have_content(I18n.t('errors.messages.procedure_archived')) } - end - end - end - - it 'redirection vers start si mauvais dossier ID' do - get :show, params: { dossier_id: bad_dossier_id } - - expect(flash[:alert]).to be_present - expect(response).to redirect_to(root_path) - end - - it_behaves_like "not owner of dossier", :show - - describe 'before_action authorized_routes?' do - context 'when dossier does not have a valid state' do - before do - dossier.state = 'en_instruction' - dossier.save - - get :show, params: { dossier_id: dossier.id } - end - - it { is_expected.to redirect_to root_path } - end - end - - describe 'before action check_autorisation_donnees' do - subject { get :show, params: { dossier_id: dossier_id } } - - context 'when dossier does not have a valid autorisations_donness (nil)' do - before do - dossier.update_column :autorisation_donnees, nil - end - - it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" } - end - - context 'when dossier does not have a valid autorisations_donness (false)' do - before do - dossier.update_column :autorisation_donnees, false - end - - it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" } - end - end - - describe 'before action check_starter_dossier_informations' do - subject { get :show, params: { dossier_id: dossier_id } } - - context 'when dossier does not have an etablissement datas' do - it { expect(dossier.etablissement).to be_nil } - it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" } - end - - context 'when dossier does not have an individual datas' do - before do - procedure.update_column :for_individual, true - end - - it { expect(dossier.individual).to be_nil } - it { expect(subject).to redirect_to "/users/dossiers/#{dossier.id}" } - end - end - end - - describe 'POST #update' do - context 'Tous les attributs sont bons' do - describe 'Premier enregistrement des données' do - let(:state) { 'brouillon' } - - def submit_dossier - post :update, params: { dossier_id: dossier_id, submit_action: submit } - dossier.reload - end - - context "when the user submits the dossier" do - let(:submit) { 'nouveaux' } - - it "redirection vers la page recapitulative" do - submit_dossier - - expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif") - end - - it 'etat du dossier est en construction' do - submit_dossier - - expect(dossier.state).to eq('en_construction') - end - - context 'sending the accusé de réception mail' do - before { Timecop.freeze(DateTime.now) } - - after { Timecop.return } - - it 'sets the state of the dossier before sending the mail' do - sender = double("notification sender") - allow(sender).to receive(:deliver_later) - expect(NotificationMailer) - .to receive(:send_initiated_notification) - .with(have_attributes(en_construction_at: DateTime.now)) - .and_return(sender) - - submit_dossier - end - end - end - - context 'when user saves a brouillon' do - let(:submit) { 'brouillon' } - - it "reste sur la page du dossier" do - submit_dossier - expect(response).to redirect_to("/users/dossiers/#{dossier_id}/description") - end - - it 'etat du dossier est brouillon' do - submit_dossier - expect(dossier.state).to eq('brouillon') - end - end - - context 'when user saves a brouillon and goes to dashboard' do - let(:submit) { 'brouillon_then_dashboard' } - - it "goes to dashboard" do - submit_dossier - expect(response).to redirect_to("/users/dossiers?liste=brouillon") - end - - it 'etat du dossier est brouillon' do - submit_dossier - expect(dossier.state).to eq('brouillon') - end - end - end - - context 'En train de manipuler un dossier non brouillon' do - before do - dossier.en_construction! - post :update, params: { dossier_id: dossier_id } - dossier.reload - end - - it 'Redirection vers la page récapitulatif' do - expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif") - end - - it 'etat du dossier n\'est pas soumis' do - expect(dossier.state).not_to eq('brouillon') - end - end - end - - describe 'Sauvegarde des champs' do - let(:champs_dossier) { dossier.champs } - let(:dossier_text_value) { 'test value' } - let(:dossier_date_value) { '2018-01-31' } - let(:dossier_hour_value) { '17' } - let(:dossier_minute_value) { '00' } - let(:dossier_datetime_champ_id) { dossier.champs.find { |c| c.type_champ == "datetime" }.id } - let(:dossier_text_champ_id) { dossier.champs.find { |c| c.type_champ == "text" }.id } - let(:params) { - { - dossier_id: dossier_id, - champs: { - "'#{dossier_text_champ_id}'" => dossier_text_value, - "'#{dossier_datetime_champ_id}'" => dossier_date_value - }, - time_hour: { - "'#{dossier_datetime_champ_id}'" => dossier_hour_value, - }, - time_minute: { - "'#{dossier_datetime_champ_id}'" => dossier_minute_value, - } - } - } - - before do - post :update, params: params - dossier.reload - end - - it { expect(dossier.champs.find(dossier_text_champ_id).value).to eq(dossier_text_value) } - it { expect(response).to redirect_to users_dossier_recapitulatif_path } - - context 'when champs is type_de_champ datetime' do - it { expect(dossier.champs.find(dossier_datetime_champ_id).value).to eq("#{dossier_date_value} #{dossier_hour_value}:#{dossier_minute_value}") } - end - - context 'when champs value is empty' do - let(:dossier_text_value) { '' } - - it { expect(dossier.champs.find(dossier_text_champ_id).value).to eq(dossier_text_value) } - it { expect(response).to redirect_to users_dossier_recapitulatif_path } - - context 'when champs is mandatory' do - let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ_mandatory, :with_datetime) } - - it { expect(response).not_to redirect_to users_dossier_recapitulatif_path } - it { expect(flash[:alert]).to be_present } - end - end - end - - context 'Sauvegarde des pièces justificatives', vcr: { cassette_name: 'controllers_users_description_controller_sauvegarde_pj' } do - let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids } - before do - post :update, params: { - dossier_id: dossier_id, - "piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0, - "piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1 - } - dossier.reload - end - - describe 'clamav anti-virus presence', vcr: { cassette_name: 'controllers_users_description_controller_clamav_presence' } do - it 'ClamavService safe_file? is call' do - expect(ClamavService).to receive(:safe_file?).twice - - post :update, params: { - dossier_id: dossier_id, - "piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0, - "piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1 - } - end - end - - context 'for piece 0' do - subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[0].to_s } - it { expect(subject.content).not_to be_nil } - it { expect(subject.user).to eq user } - end - context 'for piece 1' do - subject { dossier.retrieve_last_piece_justificative_by_type all_pj_type[1].to_s } - it { expect(subject.content).not_to be_nil } - it { expect(subject.user).to eq user } - end - end - - context 'La procédure est archivée' do - let(:archived) { true } - - before do - post :update, params: { dossier_id: dossier.id } - end - - it { expect(response.status).to eq(302) } - - context 'Le dossier est en brouillon' do - let(:state) { 'brouillon' } - - it { expect(response.status).to eq(403) } - end - end - end - - describe 'POST #pieces_justificatives', vcr: { cassette_name: 'controllers_users_description_controller_pieces_justificatives' } do - let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids } - - subject { - patch :pieces_justificatives, params: { - dossier_id: dossier.id, - "piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0, - "piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1 - } - } - - context 'when user is a guest' do - let(:guest) { create :user } - - before do - create :invite, dossier: dossier, email: guest.email, user: guest - - sign_in guest - end - - context 'when PJ have no documents' do - it { expect(dossier.pieces_justificatives.size).to eq 0 } - - context 'when upload two PJ' do - before do - subject - dossier.reload - end - - it { expect(dossier.pieces_justificatives.size).to eq 2 } - it { expect(flash[:notice]).to be_present } - it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by(dossier_id: dossier.id).id) } - end - end - - context 'when PJ have already a document' do - before do - create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative_id: all_pj_type[0] - create :piece_justificative, :contrat, dossier: dossier, type_de_piece_justificative_id: all_pj_type[1] - end - - it { expect(dossier.pieces_justificatives.size).to eq 2 } - - context 'when upload two PJ', vcr: { cassette_name: 'controllers_users_description_controller_upload_2pj' } do - before do - subject - dossier.reload - end - - it { expect(dossier.pieces_justificatives.size).to eq 4 } - it { expect(flash[:notice]).to be_present } - it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by(dossier_id: dossier.id).id) } - end - end - - context 'when one of PJs is not valid' do - let(:piece_justificative_0) { Rack::Test::UploadedFile.new("./spec/support/files/entreprise.json", 'application/json') } - - it { expect(dossier.pieces_justificatives.size).to eq 0 } - - context 'when upload two PJ' do - before do - subject - dossier.reload - end - - it { expect(dossier.pieces_justificatives.size).to eq 1 } - it { expect(flash[:alert]).to be_present } - it { is_expected.to redirect_to users_dossiers_invite_path(id: guest.invites.find_by(dossier_id: dossier.id).id) } - end - end - end - end -end - -shared_examples 'description_controller_spec_POST_piece_justificatives_for_owner' do - let(:all_pj_type) { dossier.procedure.type_de_piece_justificative_ids } - - subject { - patch :pieces_justificatives, params: { - dossier_id: dossier.id, - "piece_justificative_#{all_pj_type[0].to_s}" => piece_justificative_0, - "piece_justificative_#{all_pj_type[1].to_s}" => piece_justificative_1 - } - } - - context 'when user is the owner', vcr: { cassette_name: 'controllers_users_description_controller_pieces_justificatives' } do - before do - sign_in user - end - - context 'when PJ have no documents' do - it { expect(dossier.pieces_justificatives.size).to eq 0 } - - context 'when upload two PJ' do - before do - subject - dossier.reload - end - - it { expect(dossier.pieces_justificatives.size).to eq 2 } - it { expect(flash[:notice]).to be_present } - it { is_expected.to redirect_to recapitulatif_path } - end - end - - context 'when PJ have already a document', vcr: { cassette_name: 'controllers_users_description_controller_pj_already_exist' } do - before do - create :piece_justificative, :rib, dossier: dossier, type_de_piece_justificative_id: all_pj_type[0] - create :piece_justificative, :contrat, dossier: dossier, type_de_piece_justificative_id: all_pj_type[1] - end - - it { expect(dossier.pieces_justificatives.size).to eq 2 } - - context 'when upload two PJ', vcr: { cassette_name: 'controllers_users_description_controller_pj_already_exist_upload_2pj' } do - before do - subject - dossier.reload - end - - it { expect(dossier.pieces_justificatives.size).to eq 4 } - it { expect(flash[:notice]).to be_present } - it { is_expected.to redirect_to recapitulatif_path } - end - end - - context 'when one of PJs is not valid' do - let(:piece_justificative_0) { Rack::Test::UploadedFile.new("./spec/support/files/entreprise.json", 'application/json') } - - it { expect(dossier.pieces_justificatives.size).to eq 0 } - - context 'when upload two PJ' do - before do - subject - dossier.reload - end - - it { expect(dossier.pieces_justificatives.size).to eq 1 } - it { expect(flash[:alert]).to be_present } - it { is_expected.to redirect_to recapitulatif_path } - end - end - end -end diff --git a/spec/controllers/users/description_controller_spec.rb b/spec/controllers/users/description_controller_spec.rb deleted file mode 100644 index 011560304..000000000 --- a/spec/controllers/users/description_controller_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'spec_helper' - -require 'controllers/users/description_controller_shared_example' - -describe Users::DescriptionController, type: :controller, vcr: { cassette_name: 'controllers_users_description_controller' } do - let(:owner_user) { create(:user) } - let(:invite_by_user) { create :user, email: 'invite@plop.com' } - let(:archived) { false } - let(:state) { 'en_construction' } - let(:procedure) do - if archived - create(:procedure, :archived, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime) - else - create(:procedure, :published, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime) - end - end - let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: state) } - - let(:dossier_id) { dossier.id } - let(:bad_dossier_id) { Dossier.count + 10000 } - - let(:name_piece_justificative) { 'dossierPDF.pdf' } - let(:name_piece_justificative_0) { 'piece_justificative_0.pdf' } - let(:name_piece_justificative_1) { 'piece_justificative_1.pdf' } - - let(:piece_justificative_0) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative_0}", 'application/pdf') } - let(:piece_justificative_1) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative_1}", 'application/pdf') } - - before do - allow(ClamavService).to receive(:safe_file?).and_return(true) - - create :invite, dossier: dossier, user: invite_by_user, email: invite_by_user.email, type: 'InviteUser' - - sign_in user - end - - context 'when sign in user is the owner' do - let(:user) { owner_user } - let(:recapitulatif_path) { users_dossier_recapitulatif_path } - - it_should_behave_like "description_controller_spec" - it_should_behave_like "description_controller_spec_POST_piece_justificatives_for_owner" - end - - context 'when sign in user is an invite by owner' do - let(:user) { invite_by_user } - let(:recapitulatif_path) { users_dossiers_invite_path(id: dossier_id) } - - it_should_behave_like "description_controller_spec" - end -end diff --git a/spec/features/admin/procedure_creation_spec.rb b/spec/features/admin/procedure_creation_spec.rb index 8fa654aa2..3c410d020 100644 --- a/spec/features/admin/procedure_creation_spec.rb +++ b/spec/features/admin/procedure_creation_spec.rb @@ -13,95 +13,107 @@ feature 'As an administrateur I wanna create a new procedure', js: true do context 'Right after sign_in I shall see all procedure states links' do scenario 'Finding draft procedures' do - page.find_by_id('draft-procedures').click + click_on 'draft-procedures' expect(page).to have_current_path(admin_procedures_draft_path) end scenario 'Finding active procedures' do - page.find_by_id('active-procedures').click + click_on 'active-procedures' expect(page).to have_current_path(admin_procedures_path) end scenario 'Finding archived procedures' do - page.find_by_id('archived-procedures').click + click_on 'archived-procedures' expect(page).to have_current_path(admin_procedures_archived_path) end end context 'Creating a new procedure' do - scenario 'Finding new procedure link' do - page.find_by_id('new-procedure').click - page.find_by_id('from-scratch').click - expect(page).to have_current_path(new_admin_procedure_path) - end - scenario 'Finding save button for new procedure, libelle, description and cadre_juridique required' do - page.find_by_id('new-procedure').click - page.find_by_id('from-scratch').click + expect(page).to have_selector('#new-procedure') + find('#new-procedure').click + click_on 'from-scratch' + + expect(page).to have_current_path(new_admin_procedure_path) fill_in 'procedure_duree_conservation_dossiers_dans_ds', with: '3' fill_in 'procedure_duree_conservation_dossiers_hors_ds', with: '6' - page.find_by_id('save-procedure').click - page.find_by_id('flash_message').visible? + click_on 'save-procedure' + + expect(page).to have_text('Libelle doit être rempli') fill_in_dummy_procedure_details - page.find_by_id('save-procedure').click - expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first.id.to_s)) + click_on 'save-procedure' + + expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first)) end end context 'Editing a new procedure' do before 'Create procedure' do - page.find_by_id('new-procedure').click - page.find_by_id('from-scratch').click + expect(page).to have_selector('#new-procedure') + find('#new-procedure').click + click_on 'from-scratch' + + expect(page).to have_current_path(new_admin_procedure_path) fill_in_dummy_procedure_details - page.find_by_id('save-procedure').click + click_on 'save-procedure' procedure = Procedure.last procedure.update(service: create(:service)) end scenario 'Add champ, add file, visualize them in procedure preview' do - page.find_by_id('procedure_types_de_champ_attributes_0_libelle').set 'libelle de champ' - page.find_by_id('add_type_de_champ').click - page.find_by_id('procedure_types_de_champ_attributes_1_libelle') + fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ' + click_on 'add_type_de_champ' + expect(page).to have_current_path(admin_procedure_types_de_champ_path(Procedure.first)) + expect(page).to have_selector('#procedure_types_de_champ_attributes_1_libelle') expect(Procedure.first.types_de_champ.first.libelle).to eq('libelle de champ') - page.find_by_id('onglet-pieces').click - expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first.id.to_s)) - page.find_by_id('procedure_types_de_piece_justificative_attributes_0_libelle').set 'libelle de piece' - page.find_by_id('add_piece_justificative').click - page.find_by_id('procedure_types_de_piece_justificative_attributes_1_libelle') + click_on 'onglet-pieces' + expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first)) + fill_in 'procedure_types_de_piece_justificative_attributes_0_libelle', with: 'libelle de piece' + click_on 'add_piece_justificative' + expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first)) + expect(page).to have_selector('#procedure_types_de_piece_justificative_attributes_1_libelle') - preview_window = window_opened_by { page.find_by_id('onglet-preview').click } + preview_window = window_opened_by { click_on 'onglet-preview' } within_window(preview_window) do expect(page).to have_current_path(apercu_procedure_path(Procedure.first)) - expect(page.find("input[type='text']")['placeholder']).to eq('libelle de champ') - expect(page.first('.pj-input label').text).to eq('libelle de piece') + expect(page).to have_field('libelle de champ') + expect(page).to have_field('libelle de piece') end end scenario 'After adding champ and file, check impossibility to publish procedure, add accompagnateur and make publication' do - page.find_by_id('procedure_types_de_champ_attributes_0_libelle').set 'libelle de champ' - page.find_by_id('add_type_de_champ').click - page.find_by_id('onglet-pieces').click - page.find_by_id('procedure_types_de_piece_justificative_attributes_0_libelle').set 'libelle de piece' - page.find_by_id('add_piece_justificative').click + fill_in 'procedure_types_de_champ_attributes_0_libelle', with: 'libelle de champ' + click_on 'add_type_de_champ' + click_on 'onglet-pieces' - page.find_by_id('onglet-infos').click - expect(page).to have_current_path(admin_procedure_path(Procedure.first.id.to_s)) - expect(page.find_by_id('publish-procedure')['disabled']).to eq('true') + expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.first)) + fill_in 'procedure_types_de_piece_justificative_attributes_0_libelle', with: 'libelle de piece' + click_on 'add_piece_justificative' - page.find_by_id('onglet-accompagnateurs').click - expect(page).to have_current_path(admin_procedure_accompagnateurs_path(Procedure.first.id.to_s)) - page.find_by_id('gestionnaire_email').set 'gestionnaire@apientreprise.fr' - page.find_by_id('add-gestionnaire-email').click + click_on 'onglet-infos' + expect(page).to have_current_path(admin_procedure_path(Procedure.first)) + expect(page).to have_selector('#publish-procedure') + expect(page.find_by_id('publish-procedure')[:disabled]).to eq('true') + + click_on 'onglet-accompagnateurs' + expect(page).to have_current_path(admin_procedure_accompagnateurs_path(Procedure.first)) + fill_in 'gestionnaire_email', with: 'gestionnaire@apientreprise.fr' + click_on 'add-gestionnaire-email' page.first('.gestionnaire-affectation').click - page.find_by_id('onglet-infos').click + click_on 'onglet-infos' + expect(page).to have_current_path(admin_procedure_path(Procedure.first)) expect(page).to have_selector('#publish-procedure', visible: true) - page.find_by_id('publish-procedure').click + find('#publish-procedure').click - expect(page.find_by_id('procedure_path')['value']).to eq('libelle-de-la-procedure') - page.find_by_id('publish').click + within '#publish-modal' do + expect(page).to have_field('procedure_path', with: 'libelle-de-la-procedure') + click_on 'publish' + end + + expect(page).to have_text('Procédure publiée') expect(page).to have_selector('.procedure-lien') end end diff --git a/spec/features/description_page/upload_piece_justificative_spec.rb b/spec/features/description_page/upload_piece_justificative_spec.rb deleted file mode 100644 index 6aba555f9..000000000 --- a/spec/features/description_page/upload_piece_justificative_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ -require 'spec_helper' - -feature 'user is on description page' do - let!(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ) } - let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, autorisation_donnees: true) } - - before do - allow(ClamavService).to receive(:safe_file?).and_return(true) - - visit users_dossier_description_path dossier - - within('#new_user') do - page.find_by_id('user_email').set dossier.user.email - page.find_by_id('user_password').set dossier.user.password - page.click_on 'Se connecter' - end - end - - it { expect(page).to have_css('#description-page') } - - context 'he fill description fields' do - before do - find_by_id("champs_#{dossier.champs.first.id}").set 'mon nom' - end - context 'before submit' do - it 'pieces_justificatives are empty' do - dossier.pieces_justificatives.each do |piece_justificative| - expect(piece_justificative).to be_empty - end - end - end - context 'when he adds a piece_justificative and submit form', vcr: { cassette_name: 'description_page_upload_piece_justificative_adds_cerfa_and_submit' } do - before do - file_input_id = "piece_justificative_#{dossier.types_de_piece_justificative.first.id.to_s}" - attach_file(file_input_id, File.path('spec/support/files/dossierPDF.pdf')) - click_on('Soumettre mon dossier') - dossier.reload - end - scenario 'fills the given piece_justificative' do - expect(dossier.pieces_justificatives.first).not_to be_empty - end - end - end -end diff --git a/spec/features/new_user/dossier_spec.rb b/spec/features/new_user/dossier_spec.rb index 4b8100e65..4859ed215 100644 --- a/spec/features/new_user/dossier_spec.rb +++ b/spec/features/new_user/dossier_spec.rb @@ -96,12 +96,12 @@ feature 'The user' do click_on 'Enregistrer le brouillon' expect(user_dossier.reload.brouillon?).to be(true) expect(page).to have_content('Votre brouillon a bien été sauvegardé') - expect(page).to have_current_path(dossier_path(user_dossier)) + expect(page).to have_current_path(modifier_dossier_path(user_dossier)) # Check an incomplete dossier cannot be submitted when mandatory fields are missing click_on 'Soumettre le dossier' expect(user_dossier.reload.brouillon?).to be(true) - expect(page).to have_current_path(dossier_path(user_dossier)) + expect(page).to have_current_path(modifier_dossier_path(user_dossier)) # Check a dossier can be submitted when all mandatory fields are filled fill_in('texte obligatoire', with: 'super texte') diff --git a/spec/features/users/dossier_creation_spec.rb b/spec/features/users/dossier_creation_spec.rb index 890d82427..504e0d007 100644 --- a/spec/features/users/dossier_creation_spec.rb +++ b/spec/features/users/dossier_creation_spec.rb @@ -81,7 +81,7 @@ feature 'As a User I wanna create a dossier' do wait_for_ajax expect(page).to have_css('#recap-info-entreprise') - find(:css, "#dossier_autorisation_donnees[value='1']").set(true) + check 'dossier_autorisation_donnees' page.find_by_id('etape_suivante').click expect(page).to have_current_path(users_dossier_carte_path(procedure_with_siret.dossiers.last.id.to_s)) page.find_by_id('etape_suivante').click diff --git a/spec/services/user_routes_authorization_service_spec.rb b/spec/services/user_routes_authorization_service_spec.rb index ea0c4eebe..f1f27e61c 100644 --- a/spec/services/user_routes_authorization_service_spec.rb +++ b/spec/services/user_routes_authorization_service_spec.rb @@ -69,25 +69,6 @@ describe UserRoutesAuthorizationService do end end - describe 'Users::DescriptionController' do - let(:controller) { Users::DescriptionController } - - describe 'brouillon' do - let(:state) { 'brouillon' } - it { is_expected.to be_truthy } - end - - describe 'en_construction' do - let(:state) { 'en_construction' } - it { is_expected.to be_truthy } - end - - describe 'accepte' do - let(:state) { 'accepte' } - it { is_expected.to be_falsey } - end - end - describe 'recapitulatif' do let(:controller) { Users::RecapitulatifController } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c33b295f9..1de2c6b03 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -47,7 +47,7 @@ Capybara.register_driver :headless_chrome do |app| desired_capabilities: capabilities end -Capybara.default_max_wait_time = 1 +Capybara.default_max_wait_time = 2 # Save a snapshot of the HTML page when an integration test fails Capybara::Screenshot.autosave_on_failure = true diff --git a/spec/views/users/description/_pieces_justificatives.html.haml_spec.rb b/spec/views/users/description/_pieces_justificatives.html.haml_spec.rb deleted file mode 100644 index df2b7e6bf..000000000 --- a/spec/views/users/description/_pieces_justificatives.html.haml_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -require 'spec_helper' - -describe 'users/description/_pieces_justificatives.html.haml', type: :view do - let!(:procedure) { create(:procedure) } - let!(:tpj1) do - create( - :type_de_piece_justificative, - procedure: procedure, - libelle: "Première pièce jointe", - description: "Première description", - order_place: 1, - mandatory: true - ) - end - let!(:tpj2) do - create( - :type_de_piece_justificative, - procedure: procedure, - libelle: "Seconde pièce jointe", - description: "Seconde description", - order_place: 2, - lien_demarche: "https://www.google.fr" - ) - end - let!(:dossier) { create(:dossier, :procedure => procedure) } - - before do - render 'users/description/pieces_justificatives.html.haml', dossier: dossier - end - - it 'should render two PJ with their title, mandatory status and description' do - expect(rendered).to include("Première pièce jointe *") - expect(rendered).to include("Seconde pièce jointe") - expect(rendered.index("Première pièce jointe")).to be < rendered.index("Seconde pièce jointe") - - expect(rendered).to include("Première description") - expect(rendered).to include("Seconde description") - - expect(rendered).to have_selector("input[type=file]", count: 2) - end -end diff --git a/spec/views/users/description/champs/_date.html.haml_spec.rb b/spec/views/users/description/champs/_date.html.haml_spec.rb deleted file mode 100644 index cbed678bf..000000000 --- a/spec/views/users/description/champs/_date.html.haml_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -require 'spec_helper' - -describe 'users/description/champs/date.html.haml', type: :view do - let(:type_champ) { create(:type_de_champ_date) } - - before do - render 'users/description/champs/date.html.haml', champ: champ - end - - let!(:champ) { create(:champ, type_de_champ: type_champ, value: "2017-09-19").decorate } - - it 'should render an input for the dossier link' do - expect(rendered).to have_css("input[value='2017-09-19']") - end -end diff --git a/spec/views/users/description/champs/_departements.html.haml_spec.rb b/spec/views/users/description/champs/_departements.html.haml_spec.rb deleted file mode 100644 index 8ca65c223..000000000 --- a/spec/views/users/description/champs/_departements.html.haml_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper' - -describe 'users/description/champs/departements.html.haml', vcr: { cassette_name: 'geoapi_departements' }, type: :view do - let(:champ) { create(:champ) } - - before do - render 'users/description/champs/departements.html.haml', champ: champ.decorate - end - - it 'should render departments drop down list' do - expect(rendered).to include("Ain") - end -end diff --git a/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb b/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb deleted file mode 100644 index 6d6849ff8..000000000 --- a/spec/views/users/description/champs/_dossier_link.html.haml_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'spec_helper' - -describe 'users/description/champs/dossier_link.html.haml', type: :view do - let(:type_champ) { create(:type_de_champ_dossier_link) } - - before do - render 'users/description/champs/dossier_link.html.haml', champ: champ - end - - context 'in all cases' do - let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) } - - it 'should render an input for the dossier link' do - expect(rendered).to have_css("input[type=number][placeholder='Numéro de dossier']") - end - end - - context 'When no dossier is provided' do - let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) } - - it 'should not display the procedure libelle' do - expect(rendered).to have_css('.text-info[style*="display: none"]') - end - - it 'should not display a warning' do - expect(rendered).to have_css('.text-warning[style*="display: none"]') - end - end - - context 'When a dossier whith a procedure is provided' do - let!(:procedure) { create(:procedure) } - let!(:dossier) { create(:dossier, procedure: procedure) } - let!(:champ) { create(:champ, type_de_champ: type_champ, value: dossier.id) } - - it 'should display the procedure libelle' do - expect(rendered).not_to have_css('.text-info[style*="display: none"]') - end - - it 'should not display a warning' do - expect(rendered).to have_css('.text-warning[style*="display: none"]') - end - end - - context 'When a unknown dossier id is provided' do - let!(:champ) { create(:champ, type_de_champ: type_champ, value: 666) } - - it 'should not display the procedure libelle' do - expect(rendered).to have_css('.text-info[style*="display: none"]') - end - - it 'should display a warning' do - expect(rendered).not_to have_css('.text-warning[style*="display: none"]') - end - end -end diff --git a/spec/views/users/description/champs/_engagement.html.haml_spec.rb b/spec/views/users/description/champs/_engagement.html.haml_spec.rb deleted file mode 100644 index 31a44cc12..000000000 --- a/spec/views/users/description/champs/_engagement.html.haml_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'spec_helper' - -describe 'users/description/champs/engagement.html.haml', type: :view do - let(:type_champ) { create(:type_de_champ_engagement) } - - subject { render 'users/description/champs/engagement.html.haml', champ: champ } - - context "when the value is on" do - let!(:champ) { create(:champ, type_de_champ: type_champ, value: "on").decorate } - - it { is_expected.to have_selector("input[type='checkbox'][checked]") } - end - - context "when the value is nil" do - let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil).decorate } - - it { is_expected.to have_selector("input[type='checkbox']") } - it { is_expected.not_to have_selector("input[type='checkbox'][checked]") } - end -end diff --git a/spec/views/users/description/champs/_pays.html.haml_spec.rb b/spec/views/users/description/champs/_pays.html.haml_spec.rb deleted file mode 100644 index 78374b392..000000000 --- a/spec/views/users/description/champs/_pays.html.haml_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper' - -describe 'users/description/champs/pays.html.haml', type: :view do - let(:champ) { create(:champ) } - - before do - render 'users/description/champs/pays.html.haml', champ: champ.decorate - end - - it 'should render pays drop down list' do - expect(rendered).to include("FRANCE") - end -end diff --git a/spec/views/users/description/champs/_regions.html.haml_spec.rb b/spec/views/users/description/champs/_regions.html.haml_spec.rb deleted file mode 100644 index bc627ddff..000000000 --- a/spec/views/users/description/champs/_regions.html.haml_spec.rb +++ /dev/null @@ -1,13 +0,0 @@ -require 'spec_helper' - -describe 'users/description/champs/regions.html.haml', vcr: { cassette_name: 'geoapi_regions' }, type: :view do - let(:champ) { create(:champ) } - - before do - render 'users/description/champs/regions.html.haml', champ: champ.decorate - end - - it 'should render regions drop down list' do - expect(rendered).to include("Normandie") - end -end diff --git a/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb b/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb deleted file mode 100644 index 04443e355..000000000 --- a/spec/views/users/description/champs/_render_list_champs.html.haml_spec.rb +++ /dev/null @@ -1,55 +0,0 @@ -describe 'users/description/champs/render_list_champs.html.haml', type: :view do - let(:type_champ) { create(:type_de_champ_checkbox) } - - context "with any champ" do - let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) } - - before do - render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0 - end - - it "should render the champ's libelle" do - expect(rendered).to have_content(champ.libelle) - end - end - - context "with a checkbox champ" do - context "whose value equals nil" do - let!(:champ_checkbox_checked) { create(:champ, type_de_champ: type_champ, value: nil) } - - before do - render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0 - end - - it 'should not render a checked checkbox' do - expect(rendered).not_to have_css('input[type=checkbox][checked]') - end - end - - context "whose value equals 'on'" do - let!(:champ_checkbox_checked) { create(:champ, type_de_champ: type_champ, value: 'on') } - - before do - render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0 - end - - it 'should render a checked checkbox' do - expect(rendered).to have_css('input[type=checkbox][checked]') - end - end - end - - context 'with a dossier_link' do - let(:type_champ) { create(:type_de_champ_dossier_link) } - let!(:champ) { create(:champ, type_de_champ: type_champ, value: nil) } - - before do - render 'users/description/champs/render_list_champs.html.haml', champs: Champ.all, order_place: 0 - end - - it 'should render the _dossier_link partial' do - expect(view).to render_template(partial: 'users/description/champs/_dossier_link', - locals: { champ: champ }) - end - end -end diff --git a/spec/views/users/description/champs/_yes_no.html.haml_spec.rb b/spec/views/users/description/champs/_yes_no.html.haml_spec.rb deleted file mode 100644 index 2b8f25a0e..000000000 --- a/spec/views/users/description/champs/_yes_no.html.haml_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'spec_helper' - -describe 'users/description/champs/yes_no.html.haml', type: :view do - let(:type_champ) { create(:type_de_champ_yes_no) } - - before do - render 'users/description/champs/yes_no.html.haml', champ: champ - end - - context "when the value is Oui" do - let!(:champ) { create(:champ, type_de_champ: type_champ, value: "true").decorate } - - it 'should select the Oui radio button' do - expect(rendered).to have_selector("input[value='true'][checked]") - end - end - - context "when the value is Non" do - let!(:champ) { create(:champ, type_de_champ: type_champ, value: "false").decorate } - - it 'should select the Non radio button' do - expect(rendered).to have_selector("input[value='false'][checked]") - 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 deleted file mode 100644 index ca1a0f3fd..000000000 --- a/spec/views/users/description/show.html.haml_spec.rb +++ /dev/null @@ -1,108 +0,0 @@ -require 'spec_helper' - -describe 'users/description/show.html.haml', type: :view do - let(:user) { create(:user) } - let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime) } - let(:dossier) { create(:dossier, procedure: procedure, user: user) } - let(:dossier_id) { dossier.id } - - before do - sign_in user - 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 - end - - context 'si la page précédente n\'est pas recapitulatif' do - before do - render - end - it 'le bouton "Terminer" est présent' do - expect(rendered).to have_selector('#suivant') - end - end - - context 'si la page précédente est recapitularif' do - before do - dossier.en_construction! - 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é" est présent' do - expect(rendered).to have_selector('#modification_terminee') - end - - it 'le lien de retour au récapitulatif est présent' do - expect(rendered).to have_selector("a[href='/users/dossiers/#{dossier_id}/recapitulatif']") - end - end - - context 'Champs' do - let(:champs) { dossier.champs } - let(:types_de_champ) { procedure.types_de_champ.where(type_champ: 'datetime').first } - let(:champ_datetime) { champs.where(type_de_champ_id: types_de_champ.id).first } - - before do - champ_datetime.value = "2016-06-22 12:05" - champ_datetime.save - render - end - - describe 'first champs' do - subject { dossier.champs.first } - it { expect(rendered).to have_css("#champs_#{subject.id}") } - end - - describe 'last champs' do - subject { dossier.champs.last } - it { expect(rendered).to have_css("#champs_#{subject.id}") } - end - - describe 'datetime value is correctly setup when is not nil' do - it { expect(rendered).to have_css("input[type='date'][id='champs_#{champ_datetime.id}'][value='2016-06-22']") } - it { expect(rendered).to have_css("option[value='12'][selected='selected']") } - it { expect(rendered).to have_css("option[value='05'][selected='selected']") } - 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 - 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 piece justificative and demarche link' do - it { expect(rendered).not_to have_content 'Documents administratifs' } - end - end -end