Skip to content

Commit 6bc8dbe

Browse files
E-L-Tmfo
andcommitted
refactor(siret): move degraded-mode message into InputStatusMessageComponent
The degraded-mode message was rendered directly in SiretComponent, bypassing the component that owns the a11y contract (fr-messages-group, aria-describedby). Move it into the :siret branch, keeping it hidden when the champ feeds a condition since submission is then blocked. Co-authored-by: mfo <mfo@users.noreply.github.com>
1 parent 730bf73 commit 6bc8dbe

10 files changed

Lines changed: 20 additions & 95 deletions

File tree

app/components/dsfr/input_status_message_component.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ def compute_statut_message
7171
when TypeDeChamp.type_champs[:siret]
7272
# TODO: use fetched? after T20251029backfillChampSiretExternalStateTask
7373
if @champ.etablissement&.as_degraded_mode?
74-
nil # the non-blocking banner in SiretComponent explains the situation
74+
# When the champ feeds a condition, submission is blocked until the
75+
# backfill completes: no "you can continue" message in that case.
76+
if !@champ.external_data_required_for_conditions?
77+
{ state: :info, text: t('.siret.technical_error') }
78+
end
7579
elsif @champ.etablissement && @champ.etablissement.entreprise_capital_social.present?
7680
{ state: :info, text: t('.siret.fetched_with_capital', raison_sociale_or_name: displayable_raison_sociale_or_name(@champ.etablissement), forme_juridique: @champ.etablissement.entreprise_forme_juridique, capital_sociale: pretty_currency(@champ.etablissement.entreprise_capital_social)) }
7781
elsif @champ.etablissement && @champ.etablissement.entreprise_capital_social.blank?

app/components/dsfr/input_status_message_component/input_status_message_component.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ en:
55
pending: "Search in progress for RNA %{value}…"
66
success: "This RNA number is linked to: %{title}, %{address}."
77
siret:
8+
technical_error: "Automatic verification is temporarily unavailable. You can continue submitting; the information will be retrieved as soon as possible."
89
pending: "Search in progress for SIRET %{value}…"
910
fetched_with_capital: "%{raison_sociale_or_name} %{forme_juridique} with a share capital of %{capital_sociale}"
1011
fetched: "%{raison_sociale_or_name} %{forme_juridique}"

app/components/dsfr/input_status_message_component/input_status_message_component.fr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ fr:
55
pending: "Recherche en cours pour le RNA %{value}…"
66
success: "Ce RNA correspond à : %{title}, %{address}"
77
siret:
8+
technical_error: "La vérification automatique est temporairement indisponible. Vous pouvez poursuivre le dépôt ; les informations seront récupérées dès que possible."
89
pending: "Recherche en cours pour le SIRET %{value}…"
910
fetched_with_capital: "%{raison_sociale_or_name} %{forme_juridique} au capital social de %{capital_sociale}"
1011
fetched: "%{raison_sociale_or_name} %{forme_juridique}"
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
= @form.text_field(:external_id, input_opts(value: pretty_siret(@champ.external_id), id: @champ.focusable_input_id, aria: { **labelledby_id_attr, describedby: "#{@champ.describedby_id} #{@champ.error_id(:value)}" }, data: { controller: 'format', format: 'siret' }, required: @champ.required?, class: "width-33-desktop"))
2-
3-
- if @champ.external_data_status_message.present?
4-
%p.fr-info-text{ role: 'status' }= t("shared.champs.external_data.#{@champ.external_data_status_message}")

app/models/champs/siret_champ.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ def external_data_required_for_conditions?
1919
dependent_conditions?
2020
end
2121

22-
def external_data_status_message
23-
return nil if external_data_required_for_conditions?
24-
return :technical_error if etablissement&.as_degraded_mode?
25-
return :technical_error if external_error? && !external_data_not_found?
26-
27-
nil
28-
end
29-
3022
def focusable_input_id(attribute = :value)
3123
[input_id, :value].compact.join('-')
3224
end

config/i18n-tasks.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ search:
9494
## Consider these keys used:
9595
ignore_unused:
9696
- 'errors.format'
97-
- 'shared.champs.external_data.*' # dynamic key: t("shared.champs.external_data.#{external_data_status_message}")
9897
- 'user_mailer.*.subject'
9998
- 'groupe_gestionnaire_mailer.*.subject'
10099
- 'invite_mailer.*.subject'

config/locales/shared.en.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ en:
2828
move_down: Move down
2929

3030
champs:
31-
external_data:
32-
technical_error: "Automatic verification is temporarily unavailable. You can continue submitting; the information will be retrieved as soon as possible."
3331
drop_down_list:
3432
other: Enter another option
3533
other_label: Enter your option

config/locales/shared.fr.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ fr:
3030
move_down: Déplacer vers le bas
3131

3232
champs:
33-
external_data:
34-
technical_error: "La vérification automatique est temporairement indisponible. Vous pouvez poursuivre le dépôt ; les informations seront récupérées dès que possible."
3533
rna:
3634
association:
3735
data_fetched: "Ce RNA correspond à : %{title}, %{address}"

spec/components/input_status_message_component_spec.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
)
251251
end
252252

253-
it "does not render a warning message (the non-blocking info banner already covers it)" do
253+
it "does not render a warning message (submission is not blocked)" do
254254
expect(subject).not_to have_css(".fr-message--warning")
255255
end
256256
end
@@ -260,10 +260,20 @@
260260
champ.update!(value: '44011762001530', external_id: '44011762001530', external_state: 'fetched', etablissement: Etablissement.new(siret: '44011762001530'))
261261
end
262262

263-
it "does not render a fetched message (the non-blocking info banner covers it)" do
264-
expect(subject).not_to have_css(".fr-message--info")
263+
it "renders an info message explaining verification is postponed" do
264+
expect(subject).to have_css(".fr-message--info", text: "La vérification automatique est temporairement indisponible")
265265
expect(subject).not_to have_text("Non-diffusible")
266266
end
267+
268+
context "when the champ feeds a condition (submission is blocked until backfill)" do
269+
before do
270+
allow(champ).to receive(:external_data_required_for_conditions?).and_return(true)
271+
end
272+
273+
it "does not render the 'you can continue' message" do
274+
expect(subject).not_to have_css(".fr-message--info")
275+
end
276+
end
267277
end
268278

269279
context "when etablissement is non-diffusible (diffusable_commercialement: false)" do

spec/models/champs/siret_champ_spec.rb

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -292,81 +292,6 @@
292292
end
293293
end
294294

295-
describe '#external_data_status_message' do
296-
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) }
297-
let(:dossier) { create(:dossier, procedure:) }
298-
let(:champ) { dossier.champs.first }
299-
300-
context 'when fetched with a degraded-mode etablissement (API Entreprise was down)' do
301-
before do
302-
champ.update!(external_id: '44011762001530', external_state: 'fetched', etablissement: Etablissement.new(siret: '44011762001530'))
303-
end
304-
305-
it 'returns :technical_error so the user knows verification is postponed' do
306-
expect(champ.external_data_status_message).to eq(:technical_error)
307-
end
308-
end
309-
310-
context 'when fetched with a complete etablissement' do
311-
before do
312-
champ.update!(external_id: '44011762001530', external_state: 'fetched', etablissement: create(:etablissement))
313-
end
314-
315-
it 'returns nil' do
316-
expect(champ.external_data_status_message).to be_nil
317-
end
318-
end
319-
end
320-
321-
describe '#external_data_status_message (unit)' do
322-
let(:champ) { Champs::SiretChamp.new }
323-
324-
it 'returns nil when fetched' do
325-
allow(champ).to receive_messages(pending?: false, external_error?: false, external_data_required_for_conditions?: false)
326-
expect(champ.external_data_status_message).to be_nil
327-
end
328-
329-
it 'returns nil when pending (message already handled by InputStatusMessageComponent)' do
330-
allow(champ).to receive_messages(pending?: true, external_error?: false, external_data_required_for_conditions?: false)
331-
expect(champ.external_data_status_message).to be_nil
332-
end
333-
334-
it 'returns :technical_error on external_error with a non-404 code' do
335-
allow(champ).to receive_messages(
336-
pending?: false, external_error?: true,
337-
external_data_required_for_conditions?: false,
338-
fetch_external_data_exceptions: [ExternalDataException.new(error: 'x', code: 503)]
339-
)
340-
expect(champ.external_data_status_message).to eq(:technical_error)
341-
end
342-
343-
it 'returns nil on a 404 (handled by the validation error)' do
344-
allow(champ).to receive_messages(
345-
pending?: false, external_error?: true,
346-
external_data_required_for_conditions?: false,
347-
fetch_external_data_exceptions: [ExternalDataException.new(error: 'x', code: 404)]
348-
)
349-
expect(champ.external_data_status_message).to be_nil
350-
end
351-
352-
it 'returns nil when a technical retry was followed by a 404 (exceptions accumulate)' do
353-
allow(champ).to receive_messages(
354-
pending?: false, external_error?: true,
355-
external_data_required_for_conditions?: false,
356-
fetch_external_data_exceptions: [
357-
ExternalDataException.new(error: 'boom', code: 503),
358-
ExternalDataException.new(error: 'NF', code: 404),
359-
]
360-
)
361-
expect(champ.external_data_status_message).to be_nil
362-
end
363-
364-
it 'returns nil when external_data_required_for_conditions? is true' do
365-
allow(champ).to receive_messages(external_data_required_for_conditions?: true)
366-
expect(champ.external_data_status_message).to be_nil
367-
end
368-
end
369-
370295
describe '#handle_exhausted_external_data_retries!' do
371296
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) }
372297
let(:dossier) { create(:dossier, procedure:) }

0 commit comments

Comments
 (0)