2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-09-20 18:21:47 +02:00
|
|
|
RSpec.describe Dossiers::ExportLinkComponent, type: :component do
|
|
|
|
let(:procedure) { create(:procedure) }
|
2023-10-09 10:47:06 +02:00
|
|
|
let(:groupe_instructeur) { create(:groupe_instructeur, procedure: procedure, instructeurs: [build(:instructeur)]) }
|
2023-09-20 18:21:47 +02:00
|
|
|
let(:export_url) { double("ExportUrl", call: "/some/fake/path") }
|
|
|
|
|
2023-10-09 10:47:06 +02:00
|
|
|
let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: groupe_instructeur.instructeurs.first) }
|
|
|
|
let(:procedure_presentation) { create(:procedure_presentation, procedure: procedure, assign_to: assign_to) }
|
|
|
|
|
2023-09-20 18:21:47 +02:00
|
|
|
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
|
2023-10-09 10:47:06 +02:00
|
|
|
let(:export) { create(:export, :generated, groupe_instructeurs: [groupe_instructeur], updated_at: 5.minutes.ago, created_at: 10.minutes.ago) }
|
2023-09-20 18:21:47 +02:00
|
|
|
before do
|
|
|
|
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
|
2023-10-09 10:47:06 +02:00
|
|
|
|
|
|
|
context 'when export is for everything' do
|
|
|
|
it 'not display the exact dossiers count' do
|
|
|
|
expect(subject).to include("tous les dossiers")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-14 22:23:59 +02:00
|
|
|
context 'when export is from a presentation' do
|
2023-10-09 10:47:06 +02:00
|
|
|
before do
|
2024-10-14 22:23:59 +02:00
|
|
|
export.update!(sorted_column: procedure.default_sorted_column)
|
2023-10-09 10:47:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'display the persisted dossiers count' do
|
|
|
|
expect(subject).to include("10 dossiers")
|
|
|
|
end
|
|
|
|
end
|
2023-09-20 18:21:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the export is not available" do
|
2024-10-14 22:23:59 +02:00
|
|
|
let(:export) { create(:export, :pending, groupe_instructeurs: [groupe_instructeur], sorted_column: procedure.default_sorted_column, created_at: 10.minutes.ago) }
|
2023-10-09 10:47:06 +02:00
|
|
|
|
2023-09-20 18:21:47 +02:00
|
|
|
before do
|
2023-10-09 10:47:06 +02:00
|
|
|
create_list(:dossier, 3, :en_construction, procedure: procedure, groupe_instructeur: groupe_instructeur)
|
2023-09-20 18:21:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "displays the pending label" do
|
2023-09-21 13:59:14 +02:00
|
|
|
expect(subject).to include("demandé il y a 10 minutes")
|
2023-09-20 18:21:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "displays a refresh page button" do
|
|
|
|
expect(subject).to include("Recharger")
|
|
|
|
end
|
2023-10-09 10:47:06 +02:00
|
|
|
|
|
|
|
it 'displays the current dossiers count' do
|
|
|
|
expect(subject).to include("3 dossiers")
|
|
|
|
end
|
2024-01-24 13:15:59 +01:00
|
|
|
|
|
|
|
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
|
2023-09-20 18:21:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the export has failed" do
|
2023-10-09 10:47:06 +02:00
|
|
|
let(:export) { create(:export, :failed) }
|
2023-09-20 18:21:47 +02:00
|
|
|
|
|
|
|
it "displays the refresh old export button" do
|
|
|
|
expect(subject).to include("Regénérer")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|