fix(champs): finish EditableChampComponent refactor

This commit is contained in:
Paul Chavard 2022-09-08 11:25:39 +02:00
parent 0a1a9e07c4
commit d35ceb7214
58 changed files with 135 additions and 282 deletions
app
components/editable_champ
helpers
models
views
spec/components/editable_champ

View file

@ -1,7 +1,3 @@
class EditableChamp::AddressComponent < ApplicationComponent
class EditableChamp::AddressComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
def initialize(form:, champ:)
@form, @champ = form, champ
end
end

View file

@ -1,7 +1,3 @@
class EditableChamp::AnnuaireEducationComponent < ApplicationComponent
class EditableChamp::AnnuaireEducationComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
def initialize(form:, champ:)
@form, @champ = form, champ
end
end

View file

@ -1,7 +1,3 @@
class EditableChamp::CarteComponent < ApplicationComponent
class EditableChamp::CarteComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
def initialize(form:, champ:)
@form, @champ = form, champ
end
end

View file

@ -1,5 +1,7 @@
class EditableChamp::ChampLabelComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
include StringToHtmlHelper
def initialize(form:, champ:, seen_at: nil)
@form, @champ, @seen_at = form, champ, seen_at
end
end

View file

@ -1,10 +1,10 @@
= # we do this trick because some html elements should use 'label' and some should be plain paragraphs
- if @champ.html_label?
= @form.label @champ.main_value_name, id: champ.labelledby_id, for: champ.input_id do
= render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at }
= @form.label @champ.main_value_name, id: @champ.labelledby_id, for: @champ.input_id do
= render EditableChamp::ChampLabelContentComponent.new champ: @champ, seen_at: @seen_at
- else
.@form-label.mb-4
= render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at }
.form-label.mb-4
= render EditableChamp::ChampLabelContentComponent.new champ: @champ, seen_at: @seen_at
- if @champ.description.present?
.notice{ id: @champ.describedby_id }= string_to_html(champ.description)
.notice{ id: @champ.describedby_id }= string_to_html(@champ.description)

View file

@ -1,5 +1,5 @@
class EditableChamp::ChampLabelContentComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
def initialize(champ:, seen_at: nil)
@champ, @seen_at = champ, seen_at
end
end

View file

@ -2,10 +2,10 @@
- if @champ.type_de_champ.mandatory?
%span.mandatory *
- if @champ.updated_at.present? && seen_at.present?
%span.updated-at{ class: highlight_if_unseen_class(seen_at, @champ.updated_at) }
- if @champ.updated_at.present? && @seen_at.present?
%span.updated-at{ class: highlight_if_unseen_class(@seen_at, @champ.updated_at) }
= "modifié le #{try_format_datetime(@champ.updated_at)}"
- if @champ.rebased_at.present? && champ.rebased_at > (seen_at || champ.updated_at) && current_user.owns_or_invite?(champ.dossier)
- if @champ.rebased_at.present? && @champ.rebased_at > (@seen_at || @champ.updated_at) && controller.current_user.owns_or_invite?(@champ.dossier)
%span.updated-at.highlighted
Le type de ce @champ où sa description a été modifiée par l'administration. Vérifier son contenu.

View file

@ -1,5 +1,2 @@
class EditableChamp::CheckboxComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::CheckboxComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::CiviliteComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::CiviliteComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::CnafComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::CnafComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,7 +1,3 @@
class EditableChamp::CommunesComponent < ApplicationComponent
class EditableChamp::CommunesComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
def initialize(form:, champ:)
@form, @champ = form, champ
end
end

View file

@ -1,5 +1,2 @@
class EditableChamp::DateComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::DateComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,8 +1,4 @@
class EditableChamp::DatetimeComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::DatetimeComponent < EditableChamp::EditableChampBaseComponent
def datetime_start_year(date)
if date == nil || date.year == 0 || date.year >= Date.today.year - 1
Date.today.year - 1

View file

@ -1,5 +1,2 @@
class EditableChamp::DecimalNumberComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::DecimalNumberComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,7 +1,3 @@
class EditableChamp::DepartementsComponent < ApplicationComponent
class EditableChamp::DepartementsComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
def initialize(form:, champ:)
@form, @champ = form, champ
end
end

View file

@ -1,5 +1,2 @@
class EditableChamp::DgfipComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::DgfipComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::DossierLinkComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::DossierLinkComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::DropDownListComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::DropDownListComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::DropDownOtherInputComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::DropDownOtherInputComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -0,0 +1,5 @@
class EditableChamp::EditableChampBaseComponent < ApplicationComponent
def initialize(form:, champ:, seen_at: nil)
@form, @champ, @seen_at = form, champ, seen_at
end
end

View file

@ -1,5 +1,45 @@
class EditableChamp::EditableChampComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
include StringToHtmlHelper
def initialize(form:, champ:, seen_at: nil)
@form, @champ, @seen_at = form, champ, seen_at
end
private
def has_label?(champ)
types_without_label = [TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)]
!types_without_label.include?(@champ.type_champ)
end
def component_class
"EditableChamp::#{@champ.type_champ.camelcase}Component".constantize
end
def html_options
{
class: "editable-champ-#{@champ.type_champ} #{'hidden' if !@champ.visible?}",
id: @champ.input_group_id,
data: { controller: stimulus_controller }
}
end
def stimulus_controller
if !@champ.repetition? && @champ.fillable?
# This is an editable champ. Lets find what controllers it might need.
controllers = []
# This is a public champ it can have an autosave controller.
if @champ.public?
controllers << 'autosave'
end
# This is a dropdown champ. Activate special behaviours it might have.
if @champ.simple_drop_down_list? || @champ.linked_drop_down_list?
controllers << 'champ-dropdown'
end
controllers.join(' ')
end
end
end

View file

@ -1,13 +1,13 @@
.editable-@champ{ class: "editable-champ-#{champ.type_champ} #{champ.visible? ? '' : 'hidden'}", id: champ.input_group_id, data: editable_champ_controller(champ) }
.editable-champ{ html_options }
- if @champ.repetition?
%h3.header-subsection= @champ.libelle
- if @champ.description.present?
%p.notice= string_to_html(@champ.description, false)
- elsif has_label?(@champ)
= render partial: 'shared/dossiers/editable_champs/champ_label', locals: { form: @form, champ: champ, seen_at: defined?(seen_at) ? seen_at : nil }
= render EditableChamp::ChampLabelComponent.new form: @form, champ: @champ, seen_at: @seen_at
- if @champ.type_champ == "titre_identite"
%p.notice Carte nationale didentité (uniquement le recto), passeport, titre de séjour ou autre justificatif didentité. Formats acceptés : jpg/png
= @form.hidden_field :id, value: @champ.id, data: champ.repetition? ? { id: true } : {}
= render partial: "shared/dossiers/editable_champs/#{champ.type_champ}", locals: { form: @form, champ: champ }
= @form.hidden_field :id, value: @champ.id, data: @champ.repetition? ? { id: true } : {}
= render component_class.new(form: @form, champ: @champ, seen_at: @seen_at)

View file

@ -1,5 +1,2 @@
class EditableChamp::EmailComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::EmailComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::EngagementComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::EngagementComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,7 +1,3 @@
class EditableChamp::ExplicationComponent < ApplicationComponent
class EditableChamp::ExplicationComponent < EditableChamp::EditableChampBaseComponent
include StringToHtmlHelper
def initialize(form:, champ:)
@form, @champ = form, champ
end
end

View file

@ -1,5 +1,2 @@
class EditableChamp::HeaderSectionComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::HeaderSectionComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::IbanComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::IbanComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::IntegerNumberComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::IntegerNumberComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,3 @@
class EditableChamp::LinkedDropDownListComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::LinkedDropDownListComponent < EditableChamp::EditableChampBaseComponent
include StringToHtmlHelper
end

View file

@ -10,7 +10,7 @@
- if @champ.type_de_champ.mandatory?
%span.mandatory *
- if @champ.drop_down_secondary_description.present?
.notice{ id: "#{@champ.describedby_id}-secondary" }= helpers.string_to_html(@champ.drop_down_secondary_description)
.notice{ id: "#{@champ.describedby_id}-secondary" }= string_to_html(@champ.drop_down_secondary_description)
= @form.select :secondary_value,
@champ.secondary_options[@champ.primary_value],
{},

View file

@ -1,5 +1,2 @@
class EditableChamp::MesriComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::MesriComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,7 +1,3 @@
class EditableChamp::MultipleDropDownListComponent < ApplicationComponent
class EditableChamp::MultipleDropDownListComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
def initialize(form:, champ:)
@form, @champ = form, champ
end
end

View file

@ -1,5 +1,2 @@
class EditableChamp::NumberComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::NumberComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,7 +1,3 @@
class EditableChamp::PaysComponent < ApplicationComponent
class EditableChamp::PaysComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
def initialize(form:, champ:)
@form, @champ = form, champ
end
end

View file

@ -1,5 +1,2 @@
class EditableChamp::PhoneComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::PhoneComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::PieceJustificativeComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::PieceJustificativeComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::PoleEmploiComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::PoleEmploiComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,7 +1,3 @@
class EditableChamp::RegionsComponent < ApplicationComponent
class EditableChamp::RegionsComponent < EditableChamp::EditableChampBaseComponent
include ApplicationHelper
def initialize(form:, champ:)
@form, @champ = form, champ
end
end

View file

@ -1,5 +1,2 @@
class EditableChamp::RepetitionComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::RepetitionComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,6 +1,6 @@
.repetition{ id: dom_id(@champ, :rows) }
- @champ.rows.each do |champs|
= render EditableChamp::RepetitionRowComponent.new(form: @form, champ: @champ, row: champs)
= render EditableChamp::RepetitionRowComponent.new(form: @form, champ: @champ, row: champs, seen_at: @seen_at)
.actions{ 'data-turbo': 'true' }
= link_to champs_repetition_path(@champ.id), data: { turbo_method: :post }, class: 'button add-row' do

View file

@ -1,5 +1,5 @@
class EditableChamp::RepetitionRowComponent < ApplicationComponent
def initialize(form:, champ:, row:)
@form, @champ, @row = form, champ, row
def initialize(form:, champ:, row:, seen_at: nil)
@form, @champ, @row, @seen_at = form, champ, row, seen_at
end
end

View file

@ -2,7 +2,7 @@
.row{ id: row_dom_id }
- @row.each do |champ|
= fields_for champ.input_name, champ do |form|
= render partial: 'shared/dossiers/editable_champs/editable_champ', locals: { form: form, champ: champ }
= render EditableChamp::EditableChampComponent.new form: form, champ: champ, seen_at: @seen_at
.flex.row-reverse{ 'data-turbo': 'true' }
= link_to champs_repetition_path(@champ.id, champ_ids: @row.map(&:id), row_id: row_dom_id), data: { turbo_method: :delete }, class: 'button danger remove-row' do

View file

@ -1,5 +1,2 @@
class EditableChamp::SiretComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::SiretComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::TextComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::TextComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,7 +1,3 @@
class EditableChamp::TextareaComponent < ApplicationComponent
class EditableChamp::TextareaComponent < EditableChamp::EditableChampBaseComponent
include HtmlToStringHelper
def initialize(form:, champ:)
@form, @champ = form, champ
end
end

View file

@ -1,5 +1,2 @@
class EditableChamp::TitreIdentiteComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::TitreIdentiteComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,5 +1,2 @@
class EditableChamp::YesNoComponent < ApplicationComponent
def initialize(form:, champ:)
@form, @champ = form, champ
end
class EditableChamp::YesNoComponent < EditableChamp::EditableChampBaseComponent
end

View file

@ -1,17 +1,4 @@
module ChampHelper
def has_label?(champ)
types_without_label = [TypeDeChamp.type_champs.fetch(:header_section), TypeDeChamp.type_champs.fetch(:explication)]
!types_without_label.include?(champ.type_champ)
end
def champ_carte_params(champ)
if champ.persisted?
{ champ_id: champ.id }
else
{ type_de_champ_id: champ.type_de_champ_id }
end
end
def format_text_value(text)
sanitized_text = sanitize(text)
auto_linked_text = Anchored::Linker.auto_link(sanitized_text, target: '_blank', rel: 'noopener') do |link_href|
@ -27,36 +14,4 @@ module ChampHelper
piece_justificative_template_admin_procedure_type_de_champ_url(stable_id: object.stable_id, procedure_id: object.procedure.id)
end
end
def autosave_available?(champ)
# FIXME: enable autosave on champs private? once we figured out how to batch audit events
champ.dossier.brouillon? && !champ.repetition?
end
def editable_champ_controller(champ)
if !champ.repetition? && !champ.non_fillable?
# This is an editable champ. Lets find what controllers it might need.
controllers = []
# This is a public champ it can have an autosave controller.
if champ.public?
# This is a champ on dossier in draft state. Activate autosave.
if champ.dossier.brouillon?
controllers << 'autosave'
# This is a champ on a dossier in en_construction state. Enable conditions checker.
elsif champ.public? && champ.dossier.en_construction?
controllers << 'check-conditions'
end
end
# This is a dropdown champ. Activate special behaviours it might have.
if champ.simple_drop_down_list? || champ.linked_drop_down_list?
controllers << 'champ-dropdown'
end
if controllers.present?
{ controller: controllers.join(' ') }
end
end
end
end

View file

@ -51,6 +51,7 @@ class Champ < ApplicationRecord
:simple_drop_down_list?,
:linked_drop_down_list?,
:non_fillable?,
:fillable?,
:cnaf?,
:dgfip?,
:pole_emploi?,

View file

@ -186,6 +186,10 @@ class TypeDeChamp < ApplicationRecord
drop_down_other == "1" || drop_down_other == true
end
def fillable?
!non_fillable?
end
def non_fillable?
type_champ.in?([
TypeDeChamp.type_champs.fetch(:header_section),

View file

@ -1,5 +1,6 @@
= fields_for @champ.input_name, @champ do |form|
= turbo_stream.morph @champ.input_group_id, partial: "shared/dossiers/editable_champs/editable_champ", locals: { champ: @champ, form: form }
= turbo_stream.morph @champ.input_group_id do
= render EditableChamp::EditableChampComponent.new champ: @champ, form: form
- if @champ.piece_justificative_file.attached?
- attachment = @champ.piece_justificative_file.attachment

View file

@ -45,9 +45,7 @@
%form.form
= form_for @dossier, url: '', html: { class: 'form' } do |f|
= f.fields_for :champs do |champ_form|
- champ = champ_form.object
= render partial: "shared/dossiers/editable_champs/editable_champ",
locals: { champ: champ, form: champ_form, seen_at: nil }
= render EditableChamp::EditableChampComponent.new champ: champ_form.object, form: champ_form
.editable-champ.editable-champ-text
%label Mot de passe

View file

@ -33,7 +33,7 @@
- dossier.champs.each do |champ|
= fields_for champ.input_name, champ do |form|
= render partial: "shared/dossiers/editable_champs/editable_champ", locals: { form: form, champ: champ }
= render EditableChamp::EditableChampComponent.new form: form, champ: champ
- if !dossier.for_procedure_preview?
.dossier-edit-sticky-footer

View file

@ -4,16 +4,11 @@
= form_for dossier, url: annotations_instructeur_dossier_path(dossier.procedure, dossier), html: { class: 'form', multipart: true } do |f|
- dossier.champs_private.each do |champ|
= fields_for champ.input_name, champ do |form|
= render partial: "shared/dossiers/editable_champs/editable_champ", locals: { form: form, champ: champ, seen_at: seen_at }
= render EditableChamp::EditableChampComponent.new form: form, champ: champ, seen_at: seen_at
- if !dossier.for_procedure_preview?
- if autosave_available?(dossier.champs_private.first)
.dossier-edit-sticky-footer
.send-dossier-actions-bar
= render partial: 'autosave'
- else
.send-wrapper
= f.submit 'Sauvegarder', class: 'button primary send', data: { disable: true }
.send-wrapper
= f.submit 'Sauvegarder', class: 'button primary send', data: { disable: true }
- else
%h2.empty-text Aucune annotation privée

View file

@ -1,10 +0,0 @@
= # we do this trick because some html elements should use 'label' and some should be plain paragraphs
- if champ.html_label?
= form.label champ.main_value_name, id: champ.labelledby_id, for: champ.input_id do
= render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at }
- else
.form-label.mb-4
= render partial: 'shared/dossiers/editable_champs/champ_label_content', locals: { champ: champ, seen_at: seen_at }
- if champ.description.present?
.notice{ id: champ.describedby_id }= string_to_html(champ.description)

View file

@ -1,11 +0,0 @@
#{champ.libelle}
- if champ.type_de_champ.mandatory?
%span.mandatory *
- if champ.updated_at.present? && seen_at.present?
%span.updated-at{ class: highlight_if_unseen_class(seen_at, champ.updated_at) }
= "modifié le #{try_format_datetime(champ.updated_at)}"
- if champ.rebased_at.present? && champ.rebased_at > (seen_at || champ.updated_at) && current_user.owns_or_invite?(champ.dossier)
%span.updated-at.highlighted
Le type de ce champ où sa description a été modifiée par l'administration. Vérifier son contenu.

View file

@ -1,13 +0,0 @@
.editable-champ{ class: "editable-champ-#{champ.type_champ} #{champ.visible? ? '' : 'hidden'}", id: champ.input_group_id, data: editable_champ_controller(champ) }
- if champ.repetition?
%h3.header-subsection= champ.libelle
- if champ.description.present?
%p.notice= string_to_html(champ.description, false)
- elsif has_label?(champ)
= render partial: 'shared/dossiers/editable_champs/champ_label', locals: { form: form, champ: champ, seen_at: defined?(seen_at) ? seen_at : nil }
- if champ.type_champ == "titre_identite"
%p.notice Carte nationale didentité (uniquement le recto), passeport, titre de séjour ou autre justificatif didentité. Formats acceptés : jpg/png
= form.hidden_field :id, value: champ.id, data: champ.repetition? ? { id: true } : {}
= render "EditableChamp::#{champ.type_champ.camelcase}Component".constantize.new(form: form, champ: champ)

View file

@ -1,46 +1,50 @@
describe ChampHelper, type: :helper do
describe EditableChamp::EditableChampComponent, type: :component do
let(:component) { described_class.new(form: nil, champ: champ) }
describe "editable_champ_controller" do
let(:dossier) { create(:dossier) }
let(:champ) { create(:champ, dossier: dossier) }
let(:controllers) { [] }
let(:data) { { controller: controllers.join(' ') } }
let(:data) { controllers.join(' ') }
subject { component.send(:stimulus_controller) }
context 'when an editable champ' do
let(:controllers) { ['autosave'] }
it { expect(editable_champ_controller(champ)).to eq(data) }
it { expect(subject).to eq(data) }
end
context 'when a repetition champ' do
let(:champ) { create(:champ_repetition, dossier: dossier) }
it { expect(editable_champ_controller(champ)).to eq(nil) }
it { expect(subject).to eq(nil) }
end
context 'when a private champ' do
let(:champ) { create(:champ, dossier: dossier, private: true) }
it { expect(editable_champ_controller(champ)).to eq(nil) }
it { expect(subject).to eq('') }
end
context 'when a dossier is en_construction' do
let(:controllers) { ['check-conditions'] }
let(:controllers) { ['autosave'] }
let(:dossier) { create(:dossier, :en_construction) }
it { expect(editable_champ_controller(champ)).to eq(data) }
it { expect(subject).to eq(data) }
context 'when a public dropdown champ' do
let(:controllers) { ['check-conditions', 'champ-dropdown'] }
let(:controllers) { ['autosave', 'champ-dropdown'] }
let(:champ) { create(:champ_drop_down_list, dossier: dossier) }
it { expect(editable_champ_controller(champ)).to eq(data) }
it { expect(subject).to eq(data) }
end
context 'when a private dropdown champ' do
let(:controllers) { ['champ-dropdown'] }
let(:champ) { create(:champ_drop_down_list, dossier: dossier, private: true) }
it { expect(editable_champ_controller(champ)).to eq(data) }
it { expect(subject).to eq(data) }
end
end
@ -48,14 +52,14 @@ describe ChampHelper, type: :helper do
let(:controllers) { ['autosave', 'champ-dropdown'] }
let(:champ) { create(:champ_drop_down_list, dossier: dossier) }
it { expect(editable_champ_controller(champ)).to eq(data) }
it { expect(subject).to eq(data) }
end
context 'when a private dropdown champ' do
let(:controllers) { ['champ-dropdown'] }
let(:champ) { create(:champ_drop_down_list, dossier: dossier, private: true) }
it { expect(editable_champ_controller(champ)).to eq(data) }
it { expect(subject).to eq(data) }
end
end
end