demarches-normaliennes/spec/helpers/dossier_helper_spec.rb
Pierre de La Morinerie 33c743ab77 helper: simplify DossierHelper.url_for_dossier
The argument is never an Invite
2018-07-04 11:43:39 +02:00

99 lines
2.5 KiB
Ruby

require 'rails_helper'
RSpec.describe DossierHelper, type: :helper do
describe ".highlight_if_unseen_class" do
let(:seen_at) { DateTime.now }
subject { highlight_if_unseen_class(seen_at, updated_at) }
context "when commentaire date is created before last seen datetime" do
let(:updated_at) { seen_at - 2.days }
it { is_expected.to eq nil }
end
context "when commentaire date is created after last seen datetime" do
let(:updated_at) { seen_at + 2.hours }
it { is_expected.to eq "highlighted" }
end
context "when there is no last seen datetime" do
let(:updated_at) { DateTime.now }
let(:seen_at) { nil }
it { is_expected.to eq nil }
end
end
describe ".url_for_dossier" do
subject { url_for_dossier(dossier) }
context "when the dossier is in the brouillon state" do
let(:dossier) { create(:dossier, state: 'brouillon') }
it { is_expected.to eq "/dossiers/#{dossier.id}/modifier" }
end
context "when the dossier is any other state" do
let(:dossier) { create(:dossier, state: 'en_construction') }
it { is_expected.to eq "/users/dossiers/#{dossier.id}/recapitulatif" }
end
end
describe ".dossier_submission_is_closed?" do
let(:dossier) { create(:dossier, state: state) }
let(:state) { "brouillon" }
subject { dossier_submission_is_closed?(dossier) }
context "when dossier state is brouillon" do
it { is_expected.to be false }
context "when dossier state is brouillon and procedure is archivee" do
before { dossier.procedure.archive }
it { is_expected.to be true }
end
end
shared_examples_for "returns false" do
it { is_expected.to be false }
context "and procedure is archivee" do
before { dossier.procedure.archive }
it { is_expected.to be false }
end
end
context "when dossier state is en_construction" do
let(:state) { "en_construction" }
it_behaves_like "returns false"
end
context "when dossier state is en_construction" do
let(:state) { "en_instruction" }
it_behaves_like "returns false"
end
context "when dossier state is en_construction" do
let(:state) { "accepte" }
it_behaves_like "returns false"
end
context "when dossier state is en_construction" do
let(:state) { "refuse" }
it_behaves_like "returns false"
end
context "when dossier state is en_construction" do
let(:state) { "sans_suite" }
it_behaves_like "returns false"
end
end
end