test(exports): minimal coverage for ExportLinkComponent

This commit is contained in:
Colin Darie 2023-09-20 18:21:47 +02:00
parent daa8eac9cc
commit 2283c7eba7
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
2 changed files with 55 additions and 4 deletions

View file

@ -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,

View file

@ -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