Merge pull request #9934 from colinux/fix-export-link-witout-file

ETQ instructeur, n'affiche pas encore de lien vers un export quand le fichier n'est pas encore disponible
This commit is contained in:
Colin Darie 2024-01-29 10:11:33 +00:00 committed by GitHub
commit a582fef1e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 6 deletions

View file

@ -41,7 +41,7 @@ module TransientModelsWithPurgeableJobConcern
} }
def available? def available?
generated? generated? && file.url.present?
end end
def compute_with_safe_stale_for_purge(&block) def compute_with_safe_stale_for_purge(&block)

View file

@ -1,11 +1,11 @@
- if export.present? - if export.present?
%div{ data: export.pending? ? { controller: "turbo-poll", turbo_poll_url_value: polling_last_export_instructeur_procedure_path(export_format: export.format, statut: statut), turbo_poll_interval_value: 5_000, turbo_poll_max_checks_value: 6 } : {} } %div{ data: !export.available? && !export.failed? ? { controller: "turbo-poll", turbo_poll_url_value: polling_last_export_instructeur_procedure_path(export_format: export.format, statut: statut), turbo_poll_interval_value: 5_000, turbo_poll_max_checks_value: 6 } : {} }
= render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: 'fr-my-2w') do |c| = render Dsfr::AlertComponent.new(state: :info, size: :sm, extra_class_names: 'fr-my-2w') do |c|
- c.with_body do - c.with_body do
%p %p
- if export.pending?
= t('instructeurs.procedures.last_export_pending')
- if export.generated?
= t('instructeurs.procedures.last_export_available_html', file_format: export.format, file_url: export.file.url)
- if export.failed? - if export.failed?
= t('instructeurs.procedures.last_export_failed', file_format: export.format) = t('instructeurs.procedures.last_export_failed', file_format: export.format)
- elsif export.available?
= t('instructeurs.procedures.last_export_available_html', file_format: export.format, file_url: export.file.url)
- else
= t('instructeurs.procedures.last_export_pending')

View file

@ -63,6 +63,14 @@ RSpec.describe Dossiers::ExportLinkComponent, type: :component do
it 'displays the current dossiers count' do it 'displays the current dossiers count' do
expect(subject).to include("3 dossiers") expect(subject).to include("3 dossiers")
end end
context "when export is generated, but file not yet available" do
let(:export) { create(:export, :generated, groupe_instructeurs: [groupe_instructeur], procedure_presentation: procedure_presentation) }
it "displays the pending label" do
expect(subject).to include("demandé il y a")
end
end
end end
context "when the export has failed" do context "when the export has failed" do

View file

@ -520,6 +520,11 @@ describe Instructeurs::ProceduresController, type: :controller do
it { expect(assigns(:last_export)).to eq(export) } it { expect(assigns(:last_export)).to eq(export) }
it { expect(response.body).to include("Votre dernier export est en cours de création") } it { expect(response.body).to include("Votre dernier export est en cours de création") }
context 'when export is generated but file not yet attached' do
let!(:export) { create(:export, :generated, groupe_instructeurs: [gi_2]) }
it { expect(response.body).to include("Votre dernier export est en cours de création") }
end
end end
context 'with recent generated export' do context 'with recent generated export' do
@ -527,6 +532,7 @@ describe Instructeurs::ProceduresController, type: :controller do
let!(:export) { create(:export, :generated, groupe_instructeurs: [gi_2], updated_at: 1.minute.ago) } let!(:export) { create(:export, :generated, groupe_instructeurs: [gi_2], updated_at: 1.minute.ago) }
render_views render_views
before do before do
export.file.attach(io: StringIO.new, filename: 'file')
subject subject
end end