commencer: add an independant page

This commit is contained in:
Pierre de La Morinerie 2019-01-16 10:57:58 +00:00
parent bd77f82df0
commit 016e5f2e6f
14 changed files with 252 additions and 42 deletions

View file

@ -0,0 +1,11 @@
@import "constants";
.commencer {
.button:first-of-type {
margin-top: 4 * $default-spacer;
}
.button {
margin-bottom: 2 * $default-spacer;
}
}

View file

@ -5,6 +5,10 @@
h1 {
text-align: center;
margin-bottom: 20px;
@media (max-width: $two-columns-breakpoint) {
font-size: 28px;
}
}
hr {

View file

@ -1,25 +1,44 @@
module NewUser
class CommencerController < ApplicationController
def commencer_test
procedure = Procedure.brouillons.find_by(path: params[:path])
if procedure.present?
redirect_to new_dossier_path(procedure_id: procedure.id, brouillon: true)
else
flash.alert = "La démarche est inconnue."
redirect_to root_path
end
end
layout 'procedure_context'
def commencer
procedure = Procedure.publiees.find_by(path: params[:path])
@procedure = Procedure.publiees.find_by(path: params[:path])
if procedure.present?
redirect_to new_dossier_path(procedure_id: procedure.id)
else
if @procedure.blank?
flash.alert = "La démarche est inconnue, ou la création de nouveaux dossiers pour cette démarche est terminée."
redirect_to root_path
return redirect_to root_path
end
render 'commencer/show'
end
def commencer_test
@procedure = Procedure.brouillons.find_by(path: params[:path])
if @procedure.blank?
flash.alert = "La démarche est inconnue, ou cette démarche nest maintenant plus en test."
return redirect_to root_path
end
render 'commencer/show'
end
def sign_in
store_user_location!
redirect_to new_user_session_path
end
def sign_up
store_user_location!
redirect_to new_user_registration_path
end
private
def store_user_location!
procedure = Procedure.find_by(path: params[:path])
store_location_for(:user, new_dossier_path(procedure_id: procedure.id))
end
end
end

View file

@ -23,6 +23,14 @@ module DossierHelper
end
end
def url_for_new_dossier(procedure)
if procedure.brouillon?
new_dossier_url(procedure_id: procedure.id, brouillon: true)
else
new_dossier_url(procedure_id: procedure.id)
end
end
def dossier_submission_is_closed?(dossier)
dossier.brouillon? && dossier.procedure.archivee?
end

View file

@ -0,0 +1,30 @@
- content_for(:title, @procedure.libelle)
.commencer.form
- if !user_signed_in?
%h1 Commencer la démarche
= link_to 'Créer un compte demarches-simplifiees.fr', commencer_sign_up_path(path: @procedure.path), class: ['button large expand primary']
= link_to 'Jai déjà un compte', commencer_sign_in_path(path: @procedure.path), class: ['button large expand']
- else
- dossiers = current_user.dossiers.where(procedure: @procedure)
- drafts = dossiers.merge(Dossier.state_brouillon)
- not_drafts = dossiers.merge(Dossier.state_not_brouillon)
- if dossiers.count == 0
= link_to 'Commencer la démarche', url_for_new_dossier(@procedure), class: ['button large expand primary']
- elsif drafts.count == 1 && not_drafts.count == 0
%h1 Vous avez déjà commencé à remplir un dossier
= link_to 'Continuer à remplir mon dossier', brouillon_dossier_path(drafts.first), class: ['button large expand primary']
= link_to 'Commencer un nouveau dossier', url_for_new_dossier(@procedure), class: ['button large expand']
- elsif not_drafts.count == 1
%h1 Vous avez déjà déposé un dossier
= link_to 'Voir mon dossier', dossier_path(not_drafts.first), class: ['button large expand primary']
= link_to 'Commencer un nouveau dossier', url_for_new_dossier(@procedure), class: ['button large expand']
- else
%h1 Vous avez déjà des dossiers pour cette démarche
= link_to 'Voir mes dossiers en cours', dossiers_path, class: ['button large expand primary']
= link_to 'Commencer un nouveau dossier', url_for_new_dossier(@procedure), class: ['button large expand']

View file

@ -265,6 +265,8 @@ Rails.application.routes.draw do
namespace :commencer do
get '/test/:path', action: 'commencer_test', as: :test
get '/:path', action: 'commencer'
get '/:path/sign_in', action: 'sign_in', as: :sign_in
get '/:path/sign_up', action: 'sign_up', as: :sign_up
end
resources :dossiers, only: [:index, :show, :new] do

View file

@ -2,39 +2,88 @@ require 'spec_helper'
describe NewUser::CommencerController, type: :controller do
let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published) }
let(:procedure_id) { procedure.id }
let(:published_procedure) { create(:procedure, :published) }
let(:draft_procedure) { create(:procedure, :with_path) }
describe 'GET #commencer' do
describe '#commencer' do
subject { get :commencer, params: { path: path } }
let(:path) { procedure.path }
it { expect(subject.status).to eq 302 }
it { expect(subject).to redirect_to new_dossier_path(procedure_id: procedure.id) }
context 'when the path is for a published procedure' do
let(:path) { published_procedure.path }
context 'when procedure path does not exist' do
it 'renders the view' do
expect(subject.status).to eq(200)
expect(subject).to render_template('show')
expect(assigns(:procedure)).to eq published_procedure
end
end
context 'when the path is for a non-published procedure' do
let(:path) { draft_procedure.path }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
context 'when the path does not exist' do
let(:path) { 'hello' }
it { expect(subject).to redirect_to(root_path) }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
end
describe 'GET #commencer_test' do
before do
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
describe '#commencer_test' do
subject { get :commencer_test, params: { path: path } }
context 'when the path is for a draft procedure' do
let(:path) { draft_procedure.path }
it 'renders the view' do
expect(subject.status).to eq(200)
expect(subject).to render_template('show')
expect(assigns(:procedure)).to eq draft_procedure
end
end
subject { get :commencer_test, params: { path: path } }
let(:procedure) { create(:procedure, :with_path) }
let(:path) { procedure.path }
context 'when the path is for a published procedure' do
let(:path) { published_procedure.path }
it { expect(subject.status).to eq 302 }
it { expect(subject).to redirect_to new_dossier_path(procedure_id: procedure.id, brouillon: true) }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
context 'when procedure path does not exist' do
context 'when the path does not exist' do
let(:path) { 'hello' }
it { expect(subject).to redirect_to(root_path) }
it 'redirects with an error message' do
expect(subject).to redirect_to(root_path)
end
end
end
describe '#sign_in' do
subject { get :sign_in, params: { path: published_procedure.path } }
it 'set the path to return after sign-in to the dossier creation path' do
subject
expect(controller.stored_location_for(:user)).to eq(new_dossier_path(procedure_id: published_procedure.id))
end
it { expect(subject).to redirect_to(new_user_session_path) }
end
describe '#sign_up' do
subject { get :sign_up, params: { path: published_procedure.path } }
it 'set the path to return after sign-up to the dossier creation path' do
subject
expect(controller.stored_location_for(:user)).to eq(new_dossier_path(procedure_id: published_procedure.id))
end
it { expect(subject).to redirect_to(new_user_registration_path) }
end
end

View file

@ -14,10 +14,12 @@ feature 'The gestionnaire part' do
scenario 'a gestionnaire can fill a dossier' do
visit commencer_path(path: procedure.path)
click_on 'Jai déjà un compte'
expect(page).to have_current_path new_user_session_path
sign_in_with(gestionnaire.email, password, true)
expect(page).to have_current_path(siret_dossier_path(procedure.reload.dossiers.last))
expect(page).to have_content(procedure.libelle)
end
end

View file

@ -130,6 +130,8 @@ feature 'The user' do
def log_in(email, password, procedure)
visit "/commencer/#{procedure.path}"
click_on 'Jai déjà un compte'
expect(page).to have_current_path(new_user_session_path)
fill_in 'user_email', with: email

View file

@ -17,10 +17,10 @@ feature 'Creating a new dossier:' do
before do
visit commencer_path(path: procedure.path)
click_on 'Commencer la démarche'
expect(page).to have_content(procedure.libelle)
expect(page).to have_content(procedure.description)
expect(page).to have_content(procedure.service.email)
expect(page).to have_current_path identite_dossier_path(user.reload.dossiers.last)
expect_page_to_have_procedure_description(procedure)
fill_in 'individual_nom', with: 'Nom'
fill_in 'individual_prenom', with: 'Prenom'
@ -77,13 +77,12 @@ feature 'Creating a new dossier:' do
.to_return(status: 404, body: '')
end
scenario 'the user can enter the SIRET of its etablissement and create a new draft', vcr: { cassette_name: 'api_adresse_search_paris_3' }, js: true do
scenario 'the user can enter the SIRET of its etablissement and create a new draft', vcr: { cassette_name: 'api_adresse_search_paris_3' } do
visit commencer_path(path: procedure.path)
click_on 'Commencer la démarche'
expect(page).to have_current_path(siret_dossier_path(dossier))
expect(page).to have_content(procedure.libelle)
expect(page).to have_content(procedure.description)
expect(page).to have_content(procedure.service.email)
expect(page).to have_current_path siret_dossier_path(dossier)
expect_page_to_have_procedure_description(procedure)
fill_in 'Numéro SIRET', with: siret
click_on 'Valider'
@ -97,7 +96,10 @@ feature 'Creating a new dossier:' do
scenario 'the user is notified when its SIRET is invalid' do
visit commencer_path(path: procedure.path)
click_on 'Commencer la démarche'
expect(page).to have_current_path(siret_dossier_path(dossier))
expect_page_to_have_procedure_description(procedure)
fill_in 'Numéro SIRET', with: '0000'
click_on 'Valider'

View file

@ -48,11 +48,14 @@ feature 'linked dropdown lists' do
def log_in(email, password, procedure)
visit "/commencer/#{procedure.path}"
click_on 'Jai déjà un compte'
expect(page).to have_current_path(new_user_session_path)
fill_in 'user_email', with: email
fill_in 'user_password', with: password
click_on 'Se connecter'
expect(page).to have_current_path(identite_dossier_path(user_dossier))
end

View file

@ -41,8 +41,8 @@ feature 'Signing up:' do
end
scenario 'a new user can sign-up and fill the procedure' do
expect(page).to have_current_path new_user_session_path
click_on 'Créer un compte'
expect(page).to have_current_path new_user_registration_path
expect_page_to_have_procedure_description(procedure)
sign_up_with user_email, user_password
@ -50,6 +50,7 @@ feature 'Signing up:' do
click_confirmation_link_for user_email
expect(page).to have_content 'Votre compte a été activé'
expect(page).to have_current_path identite_dossier_path(procedure.reload.dossiers.last)
expect_page_to_have_procedure_description(procedure)
end
end

View file

@ -21,6 +21,7 @@ feature 'Signin in:' do
end
scenario 'an existing user can sign-in and fill the procedure' do
click_on 'Jai déjà un compte'
expect(page).to have_current_path new_user_session_path
expect_page_to_have_procedure_description(procedure)

View file

@ -0,0 +1,76 @@
require 'rails_helper'
RSpec.describe 'commencer/show.html.haml', type: :view do
include Rails.application.routes.url_helpers
let(:procedure) { create(:procedure, :with_service, :published) }
before do
assign(:procedure, procedure)
if user
sign_in user
end
end
subject { render }
context 'when no user is signed in' do
let(:user) { nil }
it 'renders sign-in and sign-up links' do
subject
expect(rendered).to have_link('Créer un compte')
expect(rendered).to have_link('Jai déjà un compte')
end
end
context 'when the user is already signed in' do
let(:user) { create :user }
shared_examples_for 'it renders a link to create a new dossier' do |button_label|
it 'renders a link to create a new dossier' do
subject
expect(rendered).to have_link(button_label, href: new_dossier_url(procedure_id: procedure.id))
end
end
context 'and they dont have any dossier on this procedure' do
it_behaves_like 'it renders a link to create a new dossier', 'Commencer la démarche'
end
context 'and they have a pending draft' do
let!(:brouillon) { create(:dossier, user: user, procedure: procedure) }
it_behaves_like 'it renders a link to create a new dossier', 'Commencer un nouveau dossier'
it 'renders a link to resume the pending draft' do
subject
expect(rendered).to have_link('Continuer à remplir mon dossier', href: brouillon_dossier_path(brouillon))
end
end
context 'and they have a submitted dossier' do
let!(:brouillon) { create(:dossier, user: user, procedure: procedure) }
let!(:dossier) { create(:dossier, :en_construction, :for_individual, user: user, procedure: procedure) }
it_behaves_like 'it renders a link to create a new dossier', 'Commencer un nouveau dossier'
it 'renders a link to the submitted dossier' do
subject
expect(rendered).to have_link('Voir mon dossier', href: dossier_path(dossier))
end
end
context 'and they have several submitted dossiers' do
let!(:brouillon) { create(:dossier, user: user, procedure: procedure) }
let!(:dossiers) { create_list(:dossier, 2, :en_construction, :for_individual, user: user, procedure: procedure) }
it_behaves_like 'it renders a link to create a new dossier', 'Commencer un nouveau dossier'
it 'renders a link to the dossiers list' do
subject
expect(rendered).to have_link('Voir mes dossiers en cours', href: dossiers_path)
end
end
end
end