admin: remove UI for managing old pj
This commit is contained in:
parent
b1a6a33261
commit
0c4cb3b498
17 changed files with 42 additions and 554 deletions
|
@ -25,7 +25,6 @@
|
|||
// = require login
|
||||
// = require main_container
|
||||
// = require navbar
|
||||
// = require pieces_justificatives_fields
|
||||
// = require pj_modal
|
||||
// = require print
|
||||
// = require procedure
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
.pieces-justificatives-fields {
|
||||
.form-inline > .form-group {
|
||||
vertical-align: top;
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
class Admin::PiecesJustificativesController < AdminController
|
||||
before_action :retrieve_procedure
|
||||
before_action :procedure_locked?
|
||||
before_action :reset_procedure, only: [:update, :destroy, :move_up, :move_down]
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def update
|
||||
if @procedure.update(update_params)
|
||||
flash.now.notice = 'Modifications sauvegardées'
|
||||
else
|
||||
flash.now.notice = 'Une erreur est survenue'
|
||||
end
|
||||
render 'show', format: :js
|
||||
end
|
||||
|
||||
def destroy
|
||||
@procedure.types_de_piece_justificative.find(params[:id]).destroy
|
||||
|
||||
render 'show', format: :js
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render json: { message: 'Type de piece justificative not found' }, status: 404
|
||||
end
|
||||
|
||||
def move_up
|
||||
index = params[:index].to_i - 1
|
||||
if @procedure.switch_types_de_piece_justificative index
|
||||
render 'show', format: :js
|
||||
else
|
||||
render json: {}, status: 400
|
||||
end
|
||||
end
|
||||
|
||||
def move_down
|
||||
if @procedure.switch_types_de_piece_justificative params[:index].to_i
|
||||
render 'show', format: :js
|
||||
else
|
||||
render json: {}, status: 400
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_params
|
||||
params
|
||||
.require(:procedure)
|
||||
.permit(types_de_piece_justificative_attributes: [:libelle, :description, :id, :order_place, :mandatory, :lien_demarche])
|
||||
end
|
||||
end
|
|
@ -1,55 +0,0 @@
|
|||
module AdminFormulaireHelper
|
||||
BASE_CLASSES = ['btn', 'btn-default', 'form-control', 'fa']
|
||||
|
||||
def button_up(procedure, kind, index, url)
|
||||
if display_up_button?(index, procedure, kind)
|
||||
button(up_classes, "btn_up_#{index}", url)
|
||||
end
|
||||
end
|
||||
|
||||
def button_down(procedure, kind, index, url)
|
||||
if display_down_button?(index, procedure, kind)
|
||||
button(down_classes, "btn_down_#{index}", url)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def button(classes, id, url)
|
||||
link_to(
|
||||
'',
|
||||
url,
|
||||
class: classes,
|
||||
id: id,
|
||||
remote: true,
|
||||
method: :post
|
||||
)
|
||||
end
|
||||
|
||||
def up_classes
|
||||
BASE_CLASSES + ['fa-chevron-up']
|
||||
end
|
||||
|
||||
def down_classes
|
||||
BASE_CLASSES + ['fa-chevron-down']
|
||||
end
|
||||
|
||||
def display_up_button?(index, procedure, kind)
|
||||
index != 0 && count_type_de_champ(procedure, kind) > 1
|
||||
end
|
||||
|
||||
def display_down_button?(index, procedure, kind)
|
||||
(index + 1) < count_type_de_champ(procedure, kind)
|
||||
end
|
||||
|
||||
def count_type_de_champ(procedure, kind)
|
||||
case kind
|
||||
when "public"
|
||||
@count_type_de_champ_public ||= procedure.types_de_champ.count
|
||||
when "private"
|
||||
@count_type_de_champ_private ||= procedure.types_de_champ_private.count
|
||||
when "piece_justificative"
|
||||
@count_type_de_piece_justificative ||= procedure.types_de_piece_justificative.count
|
||||
end
|
||||
end
|
||||
end
|
|
@ -187,10 +187,6 @@ class Procedure < ApplicationRecord
|
|||
switch_list_order(types_de_champ_private, index_of_first_element)
|
||||
end
|
||||
|
||||
def switch_types_de_piece_justificative(index_of_first_element)
|
||||
switch_list_order(types_de_piece_justificative, index_of_first_element)
|
||||
end
|
||||
|
||||
def switch_list_order(list, index_of_first_element)
|
||||
if index_of_first_element < 0 ||
|
||||
index_of_first_element == list.count - 1 ||
|
||||
|
@ -280,10 +276,6 @@ class Procedure < ApplicationRecord
|
|||
whitelisted_at.present?
|
||||
end
|
||||
|
||||
def has_old_pjs?
|
||||
types_de_piece_justificative.any?
|
||||
end
|
||||
|
||||
def total_dossier
|
||||
self.dossiers.state_not_brouillon.size
|
||||
end
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
.pieces-justificatives-fields
|
||||
= f.fields_for :types_de_piece_justificative, types_de_piece_justificative, remote: true do |ff|
|
||||
.form-inline
|
||||
.form-group
|
||||
%h4 Libellé
|
||||
= ff.text_field :libelle, class: 'form-control libelle', placeholder: 'Libellé'
|
||||
.form-group
|
||||
%h4 Description
|
||||
= ff.text_area :description, class: 'form-control description', placeholder: 'Description'
|
||||
.form-group
|
||||
%h4
|
||||
Lien du formulaire vierge
|
||||
%small
|
||||
(optionel)
|
||||
= ff.url_field :lien_demarche, class: 'form-control', placeholder: 'Lien du document vierge'
|
||||
|
||||
.form-group
|
||||
= ff.hidden_field :order_place, value: ff.index
|
||||
= ff.hidden_field :id
|
||||
- if ff.object.id.present?
|
||||
.form-group
|
||||
%br
|
||||
= button_up(@procedure, "piece_justificative", ff.index, move_up_admin_procedure_pieces_justificatives_path(@procedure, ff.index))
|
||||
= button_down(@procedure, "piece_justificative", ff.index, move_down_admin_procedure_pieces_justificatives_path(@procedure, ff.index))
|
||||
|
||||
.form-group
|
||||
%h4 Obligatoire ?
|
||||
.center
|
||||
= ff.check_box :mandatory
|
||||
|
||||
.form-group
|
||||
%br
|
||||
- if ff.object.id.nil?
|
||||
= f.submit('Ajouter la pièce', class: 'btn btn-success', id: 'add_piece_justificative')
|
||||
- else
|
||||
= link_to("", admin_procedure_piece_justificative_path(@procedure, ff.object.id), method: :delete, remote: true, id: "delete_type_de_piece_justificative_#{ff.object.id}", class: %w(form-control btn btn-danger fa fa-trash-o) )
|
|
@ -1,7 +0,0 @@
|
|||
= form_for [:admin, @procedure], url: admin_procedure_pieces_justificatives_path(@procedure), remote: true do |f|
|
||||
#liste_piece_justificative
|
||||
= render partial: 'fields', locals: { types_de_piece_justificative: @procedure.types_de_piece_justificative, f: f }
|
||||
= f.submit "Enregistrer", class: 'btn btn-success', id: :save
|
||||
%hr
|
||||
#new_type_de_piece_justificative
|
||||
= render partial: 'fields', locals: { types_de_piece_justificative: TypeDePieceJustificative.new, f: f }
|
|
@ -1,25 +0,0 @@
|
|||
.row.white-back
|
||||
.alert.alert-info
|
||||
.form-group
|
||||
%p
|
||||
Pour vos nouveaux besoins de pièces jointes, nous vous invitons à
|
||||
= link_to(champs_procedure_path(@procedure)) do
|
||||
rajouter des champs
|
||||
\ <em>pièce justificative</em> à votre formulaire.
|
||||
|
||||
%p
|
||||
Ils offrent les avantages suivants :
|
||||
|
||||
%ul
|
||||
%li Pièces justificatives au fil du formulaire, pour un déroulé plus fluide
|
||||
%li Possibilité de fournir à l’usager un fichier type à remplir et renvoyer
|
||||
%li Possibilité pour l’usager de supprimer les documents joints par erreur
|
||||
%li Support des pièces de grande taille (jusqu’à 200 Mo par pièce)
|
||||
%li Pas de limite de soumission simultanée de plusieurs pièces, pour une expérience usager plus confortable
|
||||
|
||||
= link_to(champs_procedure_path(@procedure), class: 'btn btn-success') do
|
||||
Ajouter un champ PJ
|
||||
|
||||
- if @procedure.has_old_pjs?
|
||||
#piece_justificative_form
|
||||
= render 'form'
|
|
@ -1,2 +0,0 @@
|
|||
<%= render_flash(timeout: 3000, sticky: true) %>
|
||||
<%= render_to_element('#piece_justificative_form', partial: 'admin/pieces_justificatives/form', locals: { procedure: @procedure }) %>
|
|
@ -1 +0,0 @@
|
|||
= render partial: 'layouts/left_panels/left_panel_admin_procedurescontroller_navbar', locals: { active: 'Pieces' }
|
|
@ -42,11 +42,6 @@
|
|||
.procedure-list-element{ class: ('active' if active == 'Champs') }
|
||||
Champs
|
||||
|
||||
- if !@procedure.locked?
|
||||
%a#onglet-pieces{ href: url_for(admin_procedure_pieces_justificatives_path(@procedure)) }
|
||||
.procedure-list-element{ class: ('active' if active == 'Pieces') }
|
||||
Pièces jointes
|
||||
|
||||
- if !@procedure.locked?
|
||||
%a#onglet-private-champs{ href: annotations_procedure_path(@procedure) }
|
||||
.procedure-list-element{ class: ('active' if active == 'Annotations privées') }
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
- case notification.type_notif
|
||||
- when "commentaire"
|
||||
.type-notif.fa.fa-comments-o
|
||||
- when "submitted"
|
||||
.type-notif.fa.fa-thumbs-o-up
|
||||
- when "champs"
|
||||
.type-notif.fa.fa-list-alt
|
||||
- when "piece_justificative"
|
||||
.type-notif.fa.fa-chain
|
|
@ -193,13 +193,6 @@ Rails.application.routes.draw do
|
|||
delete :delete_notice
|
||||
end
|
||||
|
||||
resource :pieces_justificatives, only: [:show, :update]
|
||||
resources :pieces_justificatives, only: :destroy
|
||||
resource :pieces_justificatives, only: [:show, :update] do
|
||||
post '/:index/move_up' => 'pieces_justificatives#move_up', as: :move_up
|
||||
post '/:index/move_down' => 'pieces_justificatives#move_down', as: :move_down
|
||||
end
|
||||
|
||||
resources :mail_templates, only: [:index, :edit, :update]
|
||||
|
||||
put 'archive' => 'procedures#archive', as: :archive
|
||||
|
|
|
@ -1,170 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Admin::PiecesJustificativesController, type: :controller do
|
||||
let(:admin) { create(:administrateur) }
|
||||
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||
before do
|
||||
sign_in admin
|
||||
end
|
||||
|
||||
describe 'GET #show' do
|
||||
let(:procedure_id) { procedure.id }
|
||||
|
||||
subject { get :show, params: { procedure_id: procedure_id } }
|
||||
|
||||
context 'when procedure is not found' do
|
||||
let(:procedure_id) { 9_999_999 }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
|
||||
context 'when procedure is published' do
|
||||
let(:procedure) { create(:procedure, :published, administrateur: admin) }
|
||||
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
|
||||
end
|
||||
|
||||
context 'when procedure does not belong to admin' do
|
||||
let(:admin_2) { create(:administrateur) }
|
||||
let(:procedure) { create(:procedure, administrateur: admin_2) }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:libelle) { 'RIB' }
|
||||
let(:description) { "relevé d'identité bancaire" }
|
||||
let(:update_params) do
|
||||
{
|
||||
types_de_piece_justificative_attributes:
|
||||
{
|
||||
'0' =>
|
||||
{
|
||||
libelle: libelle,
|
||||
description: description
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
let(:request) { put :update, params: { procedure_id: procedure_id, format: :js, procedure: update_params } }
|
||||
subject { request }
|
||||
|
||||
it { is_expected.to render_template('show') }
|
||||
it { expect { subject }.to change(TypeDePieceJustificative, :count).by(1) }
|
||||
it 'adds type de pj to procedure' do
|
||||
request
|
||||
procedure.reload
|
||||
pj = procedure.types_de_piece_justificative.first
|
||||
expect(pj.libelle).to eq(libelle)
|
||||
expect(pj.description).to eq(description)
|
||||
end
|
||||
|
||||
context 'when procedure is not found' do
|
||||
let(:procedure_id) { 9_999_999 }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
|
||||
context 'when libelle is blank' do
|
||||
let(:libelle) { '' }
|
||||
it { expect { subject }.not_to change(TypeDePieceJustificative, :count) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE #destroy' do
|
||||
let!(:pj) { create(:type_de_piece_justificative, procedure: procedure) }
|
||||
let(:procedure_id) { procedure.id }
|
||||
let(:pj_id) { pj.id }
|
||||
let(:request) { delete :destroy, params: { procedure_id: procedure_id, id: pj_id } }
|
||||
subject { request }
|
||||
context 'when procedure is not found' do
|
||||
let(:procedure_id) { 9_999_999 }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
context 'when pj id does not exist' do
|
||||
let(:pj_id) { 9_999_999 }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
context 'when pj id exist but is not linked to procedure' do
|
||||
let(:procedure_1) { create(:procedure, administrateur: admin) }
|
||||
let!(:pj_1) { create(:type_de_piece_justificative, procedure: procedure_1) }
|
||||
let(:pj_id) { pj_1 }
|
||||
it { expect(subject.status).to eq(404) }
|
||||
end
|
||||
context 'when pj is found' do
|
||||
it { expect(subject.status).to eq(200) }
|
||||
it { expect { subject }.to change(TypeDePieceJustificative, :count).by(-1) }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #move_up' do
|
||||
subject { post :move_up, params: { procedure_id: procedure.id, index: index, format: :js } }
|
||||
|
||||
context 'when procedure have no type de champ' do
|
||||
let(:index) { 0 }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have only one type de champ' do
|
||||
let(:index) { 1 }
|
||||
let!(:type_de_piece_justificative) { create(:type_de_piece_justificative, procedure: procedure) }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have tow type de champs' do
|
||||
context 'when index == 0' do
|
||||
let(:index) { 0 }
|
||||
let!(:type_de_piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure) }
|
||||
let!(:type_de_piece_justificative_2) { create(:type_de_piece_justificative, procedure: procedure) }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when index > 0' do
|
||||
let(:index) { 1 }
|
||||
let!(:type_de_piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
|
||||
|
||||
it { expect(subject.status).to eq(200) }
|
||||
it { expect(subject).to render_template('show') }
|
||||
it 'changes order places' do
|
||||
post :move_up, params: { procedure_id: procedure.id, index: index, format: :js }
|
||||
type_de_piece_justificative_0.reload
|
||||
type_de_piece_justificative_1.reload
|
||||
expect(type_de_piece_justificative_0.order_place).to eq(1)
|
||||
expect(type_de_piece_justificative_1.order_place).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST #move_down' do
|
||||
let(:request) { post :move_down, params: { procedure_id: procedure.id, index: index, format: :js } }
|
||||
let(:index) { 0 }
|
||||
|
||||
subject { request }
|
||||
|
||||
context 'when procedure have no type de champ' do
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have only one type de champ' do
|
||||
let!(:type_de_piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure) }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when procedure have 2 type de champ' do
|
||||
let!(:type_de_piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
|
||||
context 'when index represent last type_de_piece_justificative' do
|
||||
let(:index) { 1 }
|
||||
it { expect(subject.status).to eq(400) }
|
||||
end
|
||||
context 'when index does not represent last type_de_piece_justificative' do
|
||||
let(:index) { 0 }
|
||||
it { expect(subject.status).to eq(200) }
|
||||
it { expect(subject).to render_template('show') }
|
||||
it 'changes order place' do
|
||||
request
|
||||
type_de_piece_justificative_0.reload
|
||||
type_de_piece_justificative_1.reload
|
||||
expect(type_de_piece_justificative_0.order_place).to eq(1)
|
||||
expect(type_de_piece_justificative_1.order_place).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -65,71 +65,50 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
|
|||
procedure.update(service: create(:service))
|
||||
end
|
||||
|
||||
context 'With old PJ' do
|
||||
before do
|
||||
# Create a dummy PJ, because adding PJs is no longer allowed on procedures that
|
||||
# do not already have one
|
||||
Procedure.last.types_de_piece_justificative.create(libelle: "dummy PJ")
|
||||
scenario 'Add champ, add file, visualize them in procedure preview' do
|
||||
page.refresh
|
||||
expect(page).to have_current_path(champs_procedure_path(Procedure.last))
|
||||
|
||||
expect(page).to have_selector('#champ-0-libelle')
|
||||
fill_in 'champ-0-libelle', with: 'libelle de champ'
|
||||
blur
|
||||
expect(page).to have_content('Formulaire enregistré')
|
||||
|
||||
within '.buttons' do
|
||||
click_on 'Ajouter un champ'
|
||||
end
|
||||
expect(page).to have_selector('#champ-1-libelle')
|
||||
|
||||
click_on Procedure.last.libelle
|
||||
|
||||
preview_window = window_opened_by { click_on 'onglet-preview' }
|
||||
within_window(preview_window) do
|
||||
expect(page).to have_current_path(apercu_procedure_path(Procedure.last))
|
||||
expect(page).to have_field('libelle de champ')
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'After adding champ and file, make publication' do
|
||||
page.refresh
|
||||
|
||||
fill_in 'champ-0-libelle', with: 'libelle de champ'
|
||||
blur
|
||||
expect(page).to have_content('Formulaire enregistré')
|
||||
|
||||
click_on Procedure.last.libelle
|
||||
expect(page).to have_current_path(admin_procedure_path(Procedure.last))
|
||||
|
||||
expect(page).to have_selector('#publish-procedure', visible: true)
|
||||
find('#publish-procedure').click
|
||||
|
||||
within '#publish-modal' do
|
||||
expect(page).to have_field('procedure_path')
|
||||
fill_in 'lien_site_web', with: 'http://some.website'
|
||||
click_on 'publish'
|
||||
end
|
||||
|
||||
scenario 'Add champ, add file, visualize them in procedure preview' do
|
||||
page.refresh
|
||||
expect(page).to have_current_path(champs_procedure_path(Procedure.last))
|
||||
|
||||
expect(page).to have_selector('#champ-0-libelle')
|
||||
fill_in 'champ-0-libelle', with: 'libelle de champ'
|
||||
blur
|
||||
expect(page).to have_content('Formulaire enregistré')
|
||||
|
||||
within '.buttons' do
|
||||
click_on 'Ajouter un champ'
|
||||
end
|
||||
expect(page).to have_selector('#champ-1-libelle')
|
||||
|
||||
click_on Procedure.last.libelle
|
||||
click_on 'onglet-pieces'
|
||||
expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.last))
|
||||
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.last))
|
||||
expect(page).to have_selector('#procedure_types_de_piece_justificative_attributes_1_libelle')
|
||||
|
||||
preview_window = window_opened_by { click_on 'onglet-preview' }
|
||||
within_window(preview_window) do
|
||||
expect(page).to have_current_path(apercu_procedure_path(Procedure.last))
|
||||
expect(page).to have_field('libelle de champ')
|
||||
expect(page).to have_field('libelle de piece')
|
||||
end
|
||||
end
|
||||
|
||||
scenario 'After adding champ and file, make publication' do
|
||||
page.refresh
|
||||
|
||||
fill_in 'champ-0-libelle', with: 'libelle de champ'
|
||||
blur
|
||||
expect(page).to have_content('Formulaire enregistré')
|
||||
|
||||
click_on Procedure.last.libelle
|
||||
click_on 'onglet-pieces'
|
||||
|
||||
expect(page).to have_current_path(admin_procedure_pieces_justificatives_path(Procedure.last))
|
||||
fill_in 'procedure_types_de_piece_justificative_attributes_0_libelle', with: 'libelle de piece'
|
||||
click_on 'add_piece_justificative'
|
||||
|
||||
click_on 'onglet-infos'
|
||||
expect(page).to have_current_path(admin_procedure_path(Procedure.last))
|
||||
expect(page).to have_selector('#publish-procedure', visible: true)
|
||||
find('#publish-procedure').click
|
||||
|
||||
within '#publish-modal' do
|
||||
expect(page).to have_field('procedure_path')
|
||||
fill_in 'lien_site_web', with: 'http://some.website'
|
||||
click_on 'publish'
|
||||
end
|
||||
|
||||
expect(page).to have_text('Démarche publiée')
|
||||
expect(page).to have_selector('.procedure-lien')
|
||||
end
|
||||
expect(page).to have_text('Démarche publiée')
|
||||
expect(page).to have_selector('.procedure-lien')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe AdminFormulaireHelper, type: :helper do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:kind) { 'piece_justificative' }
|
||||
let(:url) { 'http://localhost' }
|
||||
let!(:type_de_piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
|
||||
let!(:type_de_piece_justificative_2) { create(:type_de_piece_justificative, procedure: procedure, order_place: 2) }
|
||||
|
||||
describe '#button_up' do
|
||||
describe 'with first piece justificative' do
|
||||
let(:index) { 0 }
|
||||
|
||||
it 'returns a button up' do
|
||||
expect(button_up(procedure, kind, index, url)).to be(nil)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with second out of three piece justificative' do
|
||||
let(:index) { 1 }
|
||||
|
||||
it 'returns a button up' do
|
||||
expect(button_up(procedure, kind, index, url)).to match(/fa-chevron-up/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with last piece justificative' do
|
||||
let(:index) { 2 }
|
||||
|
||||
it 'returns a button up' do
|
||||
expect(button_up(procedure, kind, index, url)).to match(/fa-chevron-up/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#button_down' do
|
||||
describe 'with first piece justificative' do
|
||||
let(:index) { 0 }
|
||||
|
||||
it 'returns a button down' do
|
||||
expect(button_down(procedure, kind, index, url)).to match(/fa-chevron-down/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with second out of three piece justificative' do
|
||||
let(:index) { 1 }
|
||||
|
||||
it 'returns a button down' do
|
||||
expect(button_down(procedure, kind, index, url)).to match(/fa-chevron-down/)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with last piece justificative' do
|
||||
let(:index) { 2 }
|
||||
|
||||
it 'returns nil' do
|
||||
expect(button_down(procedure, kind, index, url)).to be(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,48 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'admin/pieces_justificatives/show.html.haml', type: :view do
|
||||
let(:procedure) { create(:procedure) }
|
||||
|
||||
describe 'fields sorted' do
|
||||
let(:first_libelle) { 'salut la compagnie' }
|
||||
let(:last_libelle) { 'je suis bien sur la page' }
|
||||
let!(:type_de_piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1, libelle: last_libelle) }
|
||||
let!(:type_de_piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0, libelle: first_libelle) }
|
||||
before do
|
||||
procedure.reload
|
||||
assign(:procedure, procedure)
|
||||
render
|
||||
end
|
||||
it 'sorts by order place' do
|
||||
expect(rendered).to match(/#{first_libelle}.*#{last_libelle}/m)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'arrow button' do
|
||||
subject do
|
||||
procedure.reload
|
||||
assign(:procedure, procedure)
|
||||
render
|
||||
rendered
|
||||
end
|
||||
context 'when there is no field in database' do
|
||||
it { expect(subject).not_to have_css('.fa-chevron-down') }
|
||||
it { expect(subject).not_to have_css('.fa-chevron-up') }
|
||||
end
|
||||
context 'when there is only one field in database' do
|
||||
let!(:type_de_piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
|
||||
it { expect(subject).not_to have_css('#btn_down_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_1') }
|
||||
it { expect(subject).not_to have_css('#btn_down_1') }
|
||||
end
|
||||
context 'when there are 2 fields in database' do
|
||||
let!(:type_de_piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
|
||||
let!(:type_de_piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
|
||||
it { expect(subject).to have_css('#btn_down_0') }
|
||||
it { expect(subject).not_to have_css('#btn_up_0') }
|
||||
it { expect(subject).to have_css('#btn_up_1') }
|
||||
it { expect(subject).not_to have_css('#btn_down_1') }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue