dossier: add a page with the form

This commit is contained in:
Pierre de La Morinerie 2018-08-14 13:06:44 +00:00
parent 86539413ee
commit af95e56b50
8 changed files with 92 additions and 5 deletions

View file

@ -30,4 +30,8 @@
font-weight: bold;
}
}
.button.edit-form {
float: right;
}
}

View file

@ -4,8 +4,8 @@ module NewUser
helper_method :new_demarche_url
before_action :ensure_ownership!, except: [:index, :show, :modifier, :update, :recherche]
before_action :ensure_ownership_or_invitation!, only: [:show, :modifier, :update]
before_action :ensure_ownership!, except: [:index, :show, :formulaire, :modifier, :update, :recherche]
before_action :ensure_ownership_or_invitation!, only: [:show, :formulaire, :modifier, :update]
before_action :ensure_dossier_can_be_updated, only: [:update_identite, :update]
before_action :forbid_invite_submission!, only: [:update]
@ -34,6 +34,10 @@ module NewUser
@dossier = dossier
end
def formulaire
@dossier = dossier
end
def attestation
send_data(dossier.attestation.pdf.read, filename: 'attestation.pdf', type: 'application/pdf')
end
@ -104,7 +108,11 @@ module NewUser
NotificationMailer.send_initiated_notification(@dossier).deliver_later
redirect_to merci_dossier_path(@dossier)
elsif current_user.owns?(dossier)
redirect_to users_dossier_recapitulatif_path(@dossier)
if Flipflop.new_dossier_details?
redirect_to formulaire_dossier_path(@dossier)
else
redirect_to users_dossier_recapitulatif_path(@dossier)
end
else
redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user))
end

View file

@ -0,0 +1,8 @@
#dossier-show
= render partial: 'new_user/dossiers/show/header', locals: { dossier: @dossier }
= render partial: 'shared/dossiers/show', locals: { dossier: @dossier, demande_seen_at: nil }
.container
- if !@dossier.read_only?
= link_to "Modifier le dossier", modifier_dossier_path(@dossier), class: 'button primary edit-form'

View file

@ -8,5 +8,7 @@
%h2 Dossier nº #{dossier.id}
%ul.tabs
%li.active
%li{ class: current_page?(dossier_path(dossier)) ? 'active' : nil }
= link_to "Résumé", dossier_path(dossier)
%li{ class: current_page?(formulaire_dossier_path(dossier)) ? 'active' : nil }
= link_to "Formulaire", formulaire_dossier_path(dossier)

View file

@ -274,6 +274,7 @@ Rails.application.routes.draw do
get 'modifier'
patch 'modifier', to: 'dossiers#update'
get 'merci'
get 'formulaire'
post 'ask_deletion'
get 'attestation'
end

View file

@ -509,6 +509,20 @@ describe NewUser::DossiersController, type: :controller do
end
end
describe '#formulaire' do
let(:dossier) { create(:dossier, :en_construction, user: user) }
before do
Flipflop::FeatureSet.current.test!.switch!(:new_dossier_details, true)
sign_in(user)
end
subject! { get(:formulaire, params: { id: dossier.id }) }
it { expect(assigns(:dossier)).to eq(dossier) }
it { is_expected.to render_template(:formulaire) }
end
describe '#ask_deletion' do
before { sign_in(user) }

View file

@ -1,6 +1,10 @@
describe 'Dossier details:' do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, :en_construction, user: user) }
let(:simple_procedure) do
tdcs = [create(:type_de_champ, libelle: 'texte obligatoire')]
create(:procedure, :published, :for_individual, types_de_champ: tdcs)
end
let(:dossier) { create(:dossier, :en_construction, :for_individual, user: user, procedure: simple_procedure) }
before do
Flipflop::FeatureSet.current.test!.switch!(:new_dossier_details, true)
@ -14,6 +18,21 @@ describe 'Dossier details:' do
expect(page).to have_selector('.status-explanation')
end
scenario 'the user can see and edit dossier before instruction' do
visit_dossier dossier
click_on 'Formulaire'
expect(page).to have_current_path(formulaire_dossier_path(dossier))
click_on 'Modifier le dossier'
expect(page).to have_current_path(modifier_dossier_path(dossier))
fill_in('texte obligatoire', with: 'Nouveau texte')
click_on 'Enregistrer les modifications du dossier'
expect(page).to have_current_path(formulaire_dossier_path(dossier))
expect(page).to have_content('Nouveau texte')
end
private
def visit_dossier(dossier)

View file

@ -0,0 +1,31 @@
require 'spec_helper'
describe 'new_user/dossiers/formulaire.html.haml', type: :view do
let(:procedure) { create(:procedure, :published, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private) }
let(:dossier) { create(:dossier, :en_construction, :with_entreprise, procedure: procedure) }
before do
assign(:dossier, dossier)
end
subject! { render }
it 'renders the header' do
expect(rendered).to have_text("Dossier nº #{dossier.id}")
end
it 'renders the dossier infos' do
expect(rendered).to have_text('Identité')
expect(rendered).to have_text('Formulaire')
expect(rendered).to have_text('Pièces jointes')
end
context 'when the dossier is editable' do
it { is_expected.to have_link('Modifier le dossier', href: modifier_dossier_path(dossier)) }
end
context 'when the dossier is read-only' do
let(:dossier) { create(:dossier, :en_instruction, :with_entreprise, procedure: procedure) }
it { is_expected.not_to have_link('Modifier le dossier') }
end
end