feat(procedure): includes read duration of explication/non fillable champs

Long explications can significantly increase global fill duration,
so we can't ignore them.

Closes #7963
This commit is contained in:
Colin Darie 2022-10-29 12:43:37 +02:00
parent 7731c6ad64
commit 010c9a0dcb
4 changed files with 32 additions and 9 deletions

View file

@ -203,11 +203,14 @@ class ProcedureRevision < ApplicationRecord
private
def compute_estimated_fill_duration
tdc_durations = types_de_champ_public.fillable.map do |tdc|
duration = tdc.estimated_fill_duration(self) + tdc.estimated_read_duration
tdc.mandatory ? duration : duration / 2
types_de_champ_public.sum do |tdc|
next tdc.estimated_read_duration unless tdc.fillable?
duration = tdc.estimated_read_duration + tdc.estimated_fill_duration(self)
duration /= 2 unless tdc.mandatory?
duration
end
tdc_durations.sum
end
def children_types_de_champ_as_json(tdcs_as_json, parent_tdcs)

View file

@ -1,8 +1,9 @@
class TypesDeChamp::TypeDeChampBase
include ActiveModel::Validations
delegate :description, :libelle, :mandatory, :stable_id, to: :@type_de_champ
delegate :description, :libelle, :mandatory, :stable_id, :fillable?, to: :@type_de_champ
FILL_DURATION_SHORT = 10.seconds
FILL_DURATION_MEDIUM = 1.minute.in_seconds
FILL_DURATION_LONG = 3.minutes.in_seconds
READ_WORDS_PER_SECOND = 140.0 / 60 # 140 words per minute
@ -32,7 +33,12 @@ class TypesDeChamp::TypeDeChampBase
# Default estimated duration to fill the champ in a form, in seconds.
# May be overridden by subclasses.
def estimated_fill_duration(revision)
FILL_DURATION_SHORT
if fillable?
FILL_DURATION_SHORT
else
0.seconds
end
end
def estimated_read_duration
return 0.seconds if description.blank?

View file

@ -11,10 +11,10 @@ RSpec.describe ProcedureHelper, type: :helper do
end
describe '#estimated_fill_duration_minutes' do
subject { estimated_fill_duration_minutes(procedure) }
subject { estimated_fill_duration_minutes(procedure.reload) }
context 'with champs' do
let(:procedure) { build(:procedure, :with_yes_no, :with_piece_justificative) }
let(:procedure) { create(:procedure, :with_yes_no, :with_piece_justificative) }
it 'rounds up the duration to the minute' do
expect(subject).to eq(2)
@ -22,7 +22,7 @@ RSpec.describe ProcedureHelper, type: :helper do
end
context 'without champs' do
let(:procedure) { build(:procedure) }
let(:procedure) { create(:procedure) }
it 'never displays zero minutes' do
expect(subject).to eq(1)

View file

@ -731,6 +731,20 @@ describe ProcedureRevision do
expect(subject).to eq repetable_block_read_duration + row_duration * 2.5 + children_read_duration
end
end
context 'when there are non fillable champs' do
let(:types_de_champ_public) do
[
{
type: :explication,
description: "5 words description <strong>containing html</strong> " * 20
},
{ mandatory: true, description: nil }
]
end
it 'estimates duration based on content reading' do
expect(subject).to eq((100 / TypesDeChamp::TypeDeChampBase::READ_WORDS_PER_SECOND).round + TypesDeChamp::TypeDeChampBase::FILL_DURATION_SHORT)
end
end