From 2283c7eba703fa0b8abf8fb1f877e9a7b2cf31ca Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Wed, 20 Sep 2023 18:21:47 +0200 Subject: [PATCH] test(exports): minimal coverage for ExportLinkComponent --- .../dossiers/export_link_component.rb | 4 -- .../dossiers/export_link_component_spec.rb | 55 +++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 spec/components/dossiers/export_link_component_spec.rb diff --git a/app/components/dossiers/export_link_component.rb b/app/components/dossiers/export_link_component.rb index fe3a358a2..fede6c759 100644 --- a/app/components/dossiers/export_link_component.rb +++ b/app/components/dossiers/export_link_component.rb @@ -11,10 +11,6 @@ class Dossiers::ExportLinkComponent < ApplicationComponent @export_url = export_url end - def allowed_format?(item) - item.fetch(:format) != :json || @procedure.active_revision.carte? - end - def download_export_path(export_format:, statut:, force_export: false, no_progress_notification: nil) @export_url.call(@procedure, export_format: export_format, diff --git a/spec/components/dossiers/export_link_component_spec.rb b/spec/components/dossiers/export_link_component_spec.rb new file mode 100644 index 000000000..7e3f812fc --- /dev/null +++ b/spec/components/dossiers/export_link_component_spec.rb @@ -0,0 +1,55 @@ +RSpec.describe Dossiers::ExportLinkComponent, type: :component do + let(:procedure) { create(:procedure) } + let(:groupe_instructeur) { create(:groupe_instructeur, procedure: procedure) } + let(:export) { create(:export, groupe_instructeurs: [groupe_instructeur], updated_at: 5.minutes.ago) } + let(:export_url) { double("ExportUrl", call: "/some/fake/path") } + + let(:component) { described_class.new(procedure:, exports: [export], export_url:) } + + describe "rendering" do + subject { render_inline(component).to_html } + + context "when the export is available" do + before do + allow(export).to receive(:available?).and_return(true) + attachment = ActiveStorage::Attachment.new(name: "export", record: export, blob: ActiveStorage::Blob.new(byte_size: 10.kilobytes, content_type: "text/csv", filename: "export.csv")) + allow(export).to receive(:file).and_return(attachment) + end + + it "displays the time info" do + expect(subject).to include("généré il y a 5 minutes") + end + + it "displays the download button with the correct label" do + expect(subject).to include("Télécharger") + expect(subject).to include("CSV") + expect(subject).to include("10 ko") + end + end + + context "when the export is not available" do + before do + allow(export).to receive(:available?).and_return(false) + allow(export).to receive(:failed?).and_return(false) + end + + it "displays the pending label" do + expect(subject).to include("demandé il y a 5 minutes") + end + + it "displays a refresh page button" do + expect(subject).to include("Recharger") + end + end + + context "when the export has failed" do + before do + allow(export).to receive(:failed?).and_return(true) + end + + it "displays the refresh old export button" do + expect(subject).to include("Regénérer") + end + end + end +end