Merge pull request #506 from sgmap/Enhanced_week_overview
Enhanced week overview
This commit is contained in:
commit
8f767b3f76
9 changed files with 331 additions and 139 deletions
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
|
@ -1,11 +1,13 @@
|
|||
class GestionnaireMailer < ApplicationMailer
|
||||
layout 'mailers/layout'
|
||||
|
||||
def new_gestionnaire email, password
|
||||
send_mail email, password, "Vous avez été nommé accompagnateur sur la plateforme TPS"
|
||||
end
|
||||
|
||||
def last_week_overview(gestionnaire, overview)
|
||||
headers['X-mailjet-campaign'] = 'last_week_overview'
|
||||
send_mail gestionnaire.email, overview, 'Résumé de la semaine'
|
||||
send_mail gestionnaire.email, overview, 'Vos activités sur TPS'
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -106,16 +106,15 @@ class Gestionnaire < ActiveRecord::Base
|
|||
active_procedure_overviews = procedures
|
||||
.where(published: true)
|
||||
.all
|
||||
.map { |procedure| procedure.procedure_overview(start_date, dossiers_with_notifications_count_for_procedure(procedure)) }
|
||||
.map { |procedure| procedure.procedure_overview(start_date) }
|
||||
.select(&:had_some_activities?)
|
||||
|
||||
if active_procedure_overviews.count == 0 && notifications.count == 0
|
||||
if active_procedure_overviews.count == 0
|
||||
nil
|
||||
else
|
||||
{
|
||||
start_date: start_date,
|
||||
procedure_overviews: active_procedure_overviews,
|
||||
notifications: notifications
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -135,8 +135,8 @@ class Procedure < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
def procedure_overview(start_date, notifications_count)
|
||||
ProcedureOverview.new(self, start_date, notifications_count)
|
||||
def procedure_overview(start_date)
|
||||
ProcedureOverview.new(self, start_date)
|
||||
end
|
||||
|
||||
def initiated_mail_template
|
||||
|
|
|
@ -1,82 +1,72 @@
|
|||
class ProcedureOverview
|
||||
include Rails.application.routes.url_helpers
|
||||
attr_accessor :libelle, :notifications_count, :received_dossiers_count, :created_dossiers_count, :processed_dossiers_count, :date
|
||||
attr_accessor :procedure,
|
||||
:created_dossiers_count,
|
||||
:dossiers_en_instruction_count,
|
||||
:old_dossiers_en_instruction,
|
||||
:dossiers_en_construction_count,
|
||||
:old_dossiers_en_construction
|
||||
|
||||
def initialize(procedure, start_date, notifications_count)
|
||||
@libelle = procedure.libelle
|
||||
@procedure_url = backoffice_dossiers_procedure_url(procedure)
|
||||
@notifications_count = notifications_count
|
||||
def initialize(procedure, start_date)
|
||||
@start_date = start_date
|
||||
@procedure = procedure
|
||||
|
||||
@received_dossiers_count = procedure.dossiers.where(state: :received).count
|
||||
@created_dossiers_count = procedure.dossiers
|
||||
@dossiers_en_instruction_count = procedure.dossiers.state_en_instruction.count
|
||||
@old_dossiers_en_instruction = procedure
|
||||
.dossiers
|
||||
.state_en_instruction
|
||||
.where('received_at < ?', 1.week.ago)
|
||||
|
||||
@dossiers_en_construction_count = procedure.dossiers.state_en_construction.count
|
||||
@old_dossiers_en_construction = procedure
|
||||
.dossiers
|
||||
.state_en_construction
|
||||
.where('initiated_at < ?', 1.week.ago)
|
||||
|
||||
@created_dossiers_count = procedure
|
||||
.dossiers
|
||||
.where(created_at: start_date..DateTime.now)
|
||||
.where.not(state: :draft)
|
||||
.state_not_brouillon
|
||||
.count
|
||||
@processed_dossiers_count = procedure.dossiers.where(processed_at: start_date..DateTime.now).count
|
||||
end
|
||||
|
||||
def had_some_activities?
|
||||
[received_dossiers_count,
|
||||
created_dossiers_count,
|
||||
processed_dossiers_count,
|
||||
notifications_count].reduce(:+) > 0
|
||||
[@dossiers_en_instruction_count,
|
||||
@dossiers_en_construction_count,
|
||||
@created_dossiers_count].reduce(:+) > 0
|
||||
end
|
||||
|
||||
def to_html
|
||||
[libelle_description,
|
||||
dossiers_en_instruction_description,
|
||||
created_dossier_description,
|
||||
processed_dossier_description,
|
||||
notifications_description].compact.join('<br>')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def libelle_description
|
||||
"<a href='#{@procedure_url}'><strong>#{libelle}</strong></a>"
|
||||
end
|
||||
|
||||
def dossiers_en_instruction_description
|
||||
case received_dossiers_count
|
||||
def dossiers_en_construction_description
|
||||
case @dossiers_en_construction_count
|
||||
when 0
|
||||
nil
|
||||
when 1
|
||||
"1 dossier est en cours d'instruction"
|
||||
'dossier suivi en construction'
|
||||
else
|
||||
"#{received_dossiers_count} dossiers sont en cours d'instruction"
|
||||
'dossiers suivis en construction'
|
||||
end
|
||||
end
|
||||
|
||||
def dossiers_en_instruction_description
|
||||
case @dossiers_en_instruction_count
|
||||
when 0
|
||||
nil
|
||||
when 1
|
||||
"dossier est en cours d'instruction"
|
||||
else
|
||||
"dossiers sont en cours d'instruction"
|
||||
end
|
||||
end
|
||||
|
||||
def created_dossier_description
|
||||
case created_dossiers_count
|
||||
when 0
|
||||
nil
|
||||
when 1
|
||||
'1 nouveau dossier a été déposé'
|
||||
else
|
||||
"#{created_dossiers_count} nouveaux dossiers ont été déposés"
|
||||
end
|
||||
end
|
||||
formated_date = I18n.l(@start_date, format: '%d %B %Y')
|
||||
|
||||
def processed_dossier_description
|
||||
case processed_dossiers_count
|
||||
case @created_dossiers_count
|
||||
when 0
|
||||
nil
|
||||
when 1
|
||||
'1 dossier a été instruit'
|
||||
"nouveau dossier a été déposé depuis le #{formated_date}"
|
||||
else
|
||||
"#{processed_dossiers_count} dossiers ont été instruits"
|
||||
end
|
||||
end
|
||||
|
||||
def notifications_description
|
||||
case notifications_count
|
||||
when 0
|
||||
nil
|
||||
when 1
|
||||
'1 notification en attente sur les dossiers que vous suivez'
|
||||
else
|
||||
"#{notifications_count} notifications en attente sur les dossiers que vous suivez"
|
||||
"nouveaux dossiers ont été déposés depuis le #{formated_date}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,26 +1,44 @@
|
|||
%table{ align: 'center', border: '0', cellpadding: '0', cellspacing: '0', height: '100%', style: 'background-color: #fafafa', width: '100%' }
|
||||
%tbody
|
||||
%tr
|
||||
%td{ align: 'center', style: 'height: 100%; margin: 0; padding: 30px; width: 100%; border-top: 0', valign: 'top' }
|
||||
%table{ border: '0', cellpadding: '0', cellspacing: '0', style: 'border-collapse: collapse; border: 0; max-width: 600px!important;', width: '100%' }
|
||||
%tbody
|
||||
%tr
|
||||
%td{ style: 'background: #ffffff none no-repeat center/cover; background-color: #ffffff; background-image: none; background-repeat: no-repeat; background-position: center; background-size: cover; border-top: 0; padding-top: 0;', valign: 'top' }
|
||||
%table{ border: '0', cellpadding: '0', cellspacing: '0', style: 'min-width: 100%; border-collapse: collapse', width: '100%' }
|
||||
%tr
|
||||
%td{ style: 'padding: 0 30px; mso-line-height-rule: exactly; -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; ', valign: 'top' }
|
||||
%img{ align: 'middle', alt: 'Logo TPS', src: image_url('mailer/gestionnaire_mailer/logo.png'), style: 'max-width: 125px; padding: 30px 0; display: inline !important; vertical-align: bottom; border: 0; height: auto; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic;' }
|
||||
%tr
|
||||
%td{ style: 'padding: 0 30px 30px; word-break: break-word; color: #333333; font-family: Helvetica; font-size: 16px; line-height: 150%; text-align: left; border-bottom: 2px solid #4393F3;', valign: 'top' }
|
||||
Bonjour, voici votre résumé de l'activité de la semaine du #{l(@args[:start_date], format: '%d %B')} au #{l(DateTime.now, format: '%d %B')}.
|
||||
%br
|
||||
%br
|
||||
- content_for(:title, 'Vos activités sur TPS')
|
||||
|
||||
- @args[:procedure_overviews].each do |procedure_overview|
|
||||
= procedure_overview.to_html.html_safe
|
||||
%br
|
||||
%br
|
||||
Bonne journée,
|
||||
%br
|
||||
%br
|
||||
L'équipe Téléprocédures Simplifiées
|
||||
- @args[:procedure_overviews].each_with_index do |procedure_overview, index|
|
||||
|
||||
%h2{ style: 'font-size: 20px; font-weight: 300; margin: 25px 0 5px;' }
|
||||
#{procedure_overview.procedure.libelle}
|
||||
= link_to 'voir', backoffice_dossiers_procedure_url(procedure_overview.procedure), style: 'color: #4393F3; font-size: 14px;'
|
||||
%table{ cellpadding: '0', cellspacing: '0', style: 'width: 100%; padding-bottom: 20px;' }
|
||||
%tbody
|
||||
|
||||
- if procedure_overview.created_dossiers_count > 0
|
||||
%tr
|
||||
%td{ style: 'padding: 2px 0;' }
|
||||
%span{ style: 'font-weight: bold;' }= procedure_overview.created_dossiers_count
|
||||
= procedure_overview.created_dossier_description
|
||||
|
||||
- if procedure_overview.dossiers_en_construction_count > 0
|
||||
%tr
|
||||
%td{ style: 'padding: 2px 0;' }
|
||||
%span{ style: 'font-weight: bold;' }= procedure_overview.dossiers_en_construction_count
|
||||
= procedure_overview.dossiers_en_construction_description
|
||||
- if procedure_overview.old_dossiers_en_construction.count > 0
|
||||
dont <span style='font-weight: bold; color: #FF5D60; padding: 2px 0;' >#{procedure_overview.old_dossiers_en_construction.count}</span> depuis plus de 7 jours
|
||||
- if procedure_overview.old_dossiers_en_construction.count < 6
|
||||
\:
|
||||
= procedure_overview.old_dossiers_en_construction.map do |old_dossier|
|
||||
- link_to "nº #{old_dossier.id}", backoffice_dossier_url(old_dossier), style: 'color: #4393F3;'
|
||||
- end.join(', ').html_safe
|
||||
|
||||
- if procedure_overview.dossiers_en_instruction_count > 0
|
||||
%tr
|
||||
%td{ style: 'padding: 2px 0;' }
|
||||
%span{ style: 'font-weight: bold;' }= procedure_overview.dossiers_en_instruction_count
|
||||
= procedure_overview.dossiers_en_instruction_description
|
||||
- if procedure_overview.old_dossiers_en_instruction.count > 0
|
||||
dont <span style='font-weight: bold; color: #FF5D60; padding: 2px 0;' >#{procedure_overview.old_dossiers_en_instruction.count}</span> depuis plus de 7 jours
|
||||
- if procedure_overview.old_dossiers_en_instruction.count < 6
|
||||
\:
|
||||
= procedure_overview.old_dossiers_en_instruction.each do |old_dossier|
|
||||
- link_to "nº #{old_dossier.id}", backoffice_dossier_url(old_dossier), style: 'color: #4393F3;'
|
||||
- end.join(', ').html_safe
|
||||
|
||||
- if index != (@args[:procedure_overviews].count - 1)
|
||||
.spacer{ style: 'border-bottom: 1px solid #CCC; margin: 25px 0 30px;' }
|
||||
|
|
190
app/views/layouts/mailers/layout.html.erb
Normal file
190
app/views/layouts/mailers/layout.html.erb
Normal file
|
@ -0,0 +1,190 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!doctype html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
|
||||
<head>
|
||||
<title><%= yield(:title) %></title>
|
||||
<!--[if !mso]>
|
||||
<!-- -->
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<!--<![endif]-->
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style type="text/css"> #outlook a { padding: 0; } .ReadMsgBody { width: 100%; } .ExternalClass { width: 100%; } .ExternalClass * { line-height:100%; } body { margin: 0; padding: 0; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; } table, td { border-collapse:collapse; mso-table-lspace: 0pt; mso-table-rspace: 0pt; } img { border: 0; height: auto; line-height: 100%; outline: none; text-decoration: none; -ms-interpolation-mode: bicubic; } p { display: block; margin: 13px 0; }</style>
|
||||
<!--[if !mso]>
|
||||
<!-->
|
||||
<style type="text/css"> @media only screen and (max-width:480px) { @-ms-viewport { width:320px; } @viewport { width:320px; } }</style>
|
||||
<!--<![endif]-->
|
||||
<!--[if mso]>
|
||||
<xml>
|
||||
<o:OfficeDocumentSettings>
|
||||
<o:AllowPNG/>
|
||||
<o:PixelsPerInch>96</o:PixelsPerInch>
|
||||
</o:OfficeDocumentSettings>
|
||||
</xml>
|
||||
<![endif]-->
|
||||
<!--[if lte mso 11]>
|
||||
<style type="text/css"> .outlook-group-fix { width:100% !important; }</style>
|
||||
<![endif]-->
|
||||
<style type="text/css"> @media only screen and (min-width:480px) { .mj-column-per-66 { width:66.66666666666666%!important; }.mj-column-per-33 { width:33.33333333333333%!important; }.mj-column-per-100 { width:100%!important; } }</style>
|
||||
</head>
|
||||
<body style="background: #F4F4F4;">
|
||||
<div style="background-color:#F4F4F4;">
|
||||
<!--[if mso | IE]>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="600" align="center" style="width:600px;">
|
||||
<tr>
|
||||
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
|
||||
<![endif]-->
|
||||
<div style="margin:0px auto;max-width:600px;">
|
||||
<table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;" align="center" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:20px 0px 20px 0px;">
|
||||
<!--[if mso | IE]>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td style="vertical-align:top;width:396px;">
|
||||
<![endif]-->
|
||||
<div class="mj-column-per-66 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;">
|
||||
<table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="word-wrap:break-word;font-size:0px;padding:0;padding-top:0px;padding-bottom:0px;" align="left">
|
||||
<div class="" style="cursor:auto;color:#55575d;font-family:Helvetica, Arial, sans-serif;font-size:11px;line-height:22px;text-align:left;">
|
||||
<img align="middle" alt="Logo TPS" src="<%= image_url('mailer/gestionnaire_mailer/logo.png') %>" style="max-width=125px; padding=30px 0; display=inline !important; vertical-align=bottom; border=0; height=auto; outline=none; text-decoration=none; -ms-interpolation-mode=bicubic;" />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]>
|
||||
</td>
|
||||
<td style="vertical-align:top;width:198px;">
|
||||
<![endif]-->
|
||||
<div class="mj-column-per-33 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;">
|
||||
<table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="word-wrap:break-word;font-size:0px;padding:0px 25px 0px 0px;padding-top:0px;padding-bottom:0px;" align="right">
|
||||
<div class="" style="cursor:auto;color:#55575d;font-family:Helvetica, Arial, sans-serif;font-size:11px;line-height:22px;text-align:right;">
|
||||
<p style="margin: 10px 0;">
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
<!--[if mso | IE]>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="600" align="center" style="width:600px;">
|
||||
<tr>
|
||||
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
|
||||
<![endif]-->
|
||||
<div style="margin:0px auto;max-width:600px;background:#ffffff;">
|
||||
<table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;background:#ffffff;" align="center" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:20px 0px 20px 0px;">
|
||||
<!--[if mso | IE]>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td style="vertical-align:top;width:600px;">
|
||||
<![endif]-->
|
||||
<div class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;">
|
||||
<table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="word-wrap:break-word;font-size:0px;padding:0px 25px 0px 25px;padding-top:0px;padding-bottom:0px;" align="left">
|
||||
<div class="" style="cursor:auto;color:#55575d;font-family:Helvetica, Arial, sans-serif;font-size:13px;line-height:22px;text-align:left;">
|
||||
<h1 style="font-size: 30px; text-align: center; font-weight: 300; max-width: 300px; margin: 30px auto 40px; line-height: 1.2;"><%= yield(:title) %></h1>
|
||||
<%= yield %>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
<!--[if mso | IE]>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="600" align="center" style="width:600px;">
|
||||
<tr>
|
||||
<td style="line-height:0px;font-size:0px;mso-line-height-rule:exactly;">
|
||||
<![endif]-->
|
||||
<div style="margin:0px auto;max-width:600px;">
|
||||
<table role="presentation" cellpadding="0" cellspacing="0" style="font-size:0px;width:100%;" align="center" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="text-align:center;vertical-align:top;direction:ltr;font-size:0px;padding:20px 0px 20px 0px;">
|
||||
<!--[if mso | IE]>
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td style="vertical-align:top;width:600px;">
|
||||
<![endif]-->
|
||||
<div class="mj-column-per-100 outlook-group-fix" style="vertical-align:top;display:inline-block;direction:ltr;font-size:13px;text-align:left;width:100%;">
|
||||
<table role="presentation" cellpadding="0" cellspacing="0" width="100%" border="0">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="word-wrap:break-word;font-size:0px;padding:0px 20px 0px 20px;padding-top:0px;padding-bottom:0px;" align="center">
|
||||
<div class="" style="cursor:auto;color:#55575d;font-family:Helvetica, Arial, sans-serif;font-size:11px;line-height:22px;text-align:center;">
|
||||
<img align="middle" alt="Logo Beta Gouv Fr" src="<%= image_url('mailer/gestionnaire_mailer/logo-beta-gouv-fr.png') %>" style="max-width=125px; padding=30px 0; display=inline !important; vertical-align=bottom; border=0; height=auto; outline=none; text-decoration=none; -ms-interpolation-mode=bicubic;" />
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="word-wrap:break-word;font-size:0px;padding:0px 20px 0px 20px;padding-top:0px;padding-bottom:0px;" align="center">
|
||||
<div class="" style="cursor:auto;color:#55575d;font-family:Helvetica, Arial, sans-serif;font-size:11px;line-height:22px;text-align:center;">
|
||||
<p style="margin: 10px 0;">
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<![endif]-->
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<!--[if mso | IE]>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<in![endif]-->
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -365,14 +365,6 @@ describe Gestionnaire, type: :model do
|
|||
context 'when the gestionnaire has no notifications' do
|
||||
it { is_expected.to eq(nil) }
|
||||
end
|
||||
|
||||
context 'when the gestionnaire has one notification' do
|
||||
before :each do
|
||||
expect(gestionnaire2).to receive(:notifications).twice.and_return([1])
|
||||
end
|
||||
|
||||
it { is_expected.to eq({ start_date: monday, procedure_overviews: [], notifications: [1] }) }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a procedure published was active' do
|
||||
|
|
|
@ -9,14 +9,36 @@ describe ProcedureOverview, type: :model do
|
|||
Timecop.freeze(friday)
|
||||
end
|
||||
|
||||
let(:procedure_overview) { ProcedureOverview.new(procedure, monday, 0) }
|
||||
let(:procedure_overview) { ProcedureOverview.new(procedure, monday) }
|
||||
|
||||
describe 'received_dossiers_count' do
|
||||
let!(:received_dossier) do
|
||||
dossier = create(:dossier, procedure: procedure, state: :received, created_at: monday)
|
||||
describe 'dossiers_en_instruction_count' do
|
||||
let!(:en_instruction_dossier) do
|
||||
create(:dossier, procedure: procedure, state: :received, created_at: monday)
|
||||
end
|
||||
|
||||
it { expect(procedure_overview.received_dossiers_count).to eq(1) }
|
||||
it { expect(procedure_overview.dossiers_en_instruction_count).to eq(1) }
|
||||
end
|
||||
|
||||
describe 'old_dossiers_en_instruction' do
|
||||
let!(:old_dossier_en_instruction) do
|
||||
create(:dossier, procedure: procedure, state: :received, received_at: monday - 1.month)
|
||||
end
|
||||
|
||||
let!(:dossier_en_instruction) do
|
||||
create(:dossier, procedure: procedure, state: :received, received_at: monday)
|
||||
end
|
||||
|
||||
it do
|
||||
expect(procedure_overview.old_dossiers_en_instruction).to match([old_dossier_en_instruction])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'dossiers_en_construction_count' do
|
||||
let!(:dossier_en_construction) do
|
||||
create(:dossier, procedure: procedure, state: :initiated, created_at: monday)
|
||||
end
|
||||
|
||||
it { expect(procedure_overview.dossiers_en_construction_count).to eq(1) }
|
||||
end
|
||||
|
||||
describe 'created_dossiers_count' do
|
||||
|
@ -35,53 +57,32 @@ describe ProcedureOverview, type: :model do
|
|||
it { expect(procedure_overview.created_dossiers_count).to eq(1) }
|
||||
end
|
||||
|
||||
describe 'processed_dossiers_count' do
|
||||
let!(:processed_dossier_during_the_week) do
|
||||
create(:dossier, procedure: procedure, created_at: monday, processed_at: monday)
|
||||
describe 'had_some_activities?' do
|
||||
subject { procedure_overview.had_some_activities? }
|
||||
|
||||
before :each do
|
||||
procedure_overview.dossiers_en_instruction_count = 0
|
||||
procedure_overview.dossiers_en_construction_count = 0
|
||||
procedure_overview.created_dossiers_count = 0
|
||||
end
|
||||
|
||||
let!(:processed_dossier_before_the_week) do
|
||||
create(:dossier, procedure: procedure, created_at: (monday - 1.week), processed_at: (monday - 1.week))
|
||||
context 'when there are no activities' do
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
it { expect(procedure_overview.processed_dossiers_count).to eq(1) }
|
||||
end
|
||||
|
||||
describe 'to_html' do
|
||||
subject { procedure_overview.to_html }
|
||||
|
||||
context 'when the different count are equal to 0' do
|
||||
it { is_expected.to match(/^<a href='http:\/\/.+'><strong>libelle<\/strong><\/a>$/) }
|
||||
context 'when there are some dossiers en instruction' do
|
||||
before { procedure_overview.dossiers_en_instruction_count = 2 }
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when the different counts are equal to 1' do
|
||||
before :each do
|
||||
procedure_overview.notifications_count = 1
|
||||
procedure_overview.received_dossiers_count = 1
|
||||
procedure_overview.created_dossiers_count = 1
|
||||
procedure_overview.processed_dossiers_count = 1
|
||||
end
|
||||
|
||||
it { is_expected.to match(/^<a href='.+'><strong>libelle<\/strong><\/a>/) }
|
||||
it { is_expected.to include("1 dossier est en cours d'instruction") }
|
||||
it { is_expected.to include('1 nouveau dossier a été déposé') }
|
||||
it { is_expected.to include('1 dossier a été instruit') }
|
||||
it { is_expected.to include('1 notification en attente sur les dossiers que vous suivez') }
|
||||
context 'when there are some dossiers en construction' do
|
||||
before { procedure_overview.dossiers_en_construction_count = 2 }
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when the different counts are equal to 2' do
|
||||
before :each do
|
||||
procedure_overview.notifications_count = 2
|
||||
procedure_overview.received_dossiers_count = 3
|
||||
procedure_overview.created_dossiers_count = 4
|
||||
procedure_overview.processed_dossiers_count = 5
|
||||
end
|
||||
|
||||
it { is_expected.to match(/^<a href='.+'><strong>libelle<\/strong><\/a>/) }
|
||||
it { is_expected.to include("3 dossiers sont en cours d'instruction") }
|
||||
it { is_expected.to include('4 nouveaux dossiers ont été déposés') }
|
||||
it { is_expected.to include('5 dossiers ont été instruits') }
|
||||
it { is_expected.to include('2 notifications en attente sur les dossiers que vous suivez') }
|
||||
context 'when there are some created dossiers' do
|
||||
before { procedure_overview.created_dossiers_count = 2 }
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue