diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index e9bfe02a4..be8cc74c3 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -80,6 +80,10 @@ class Legislation::Process < ActiveRecord::Base Legislation::Process::Publication.new(result_publication_date, result_publication_enabled) end + def enabled_phases? + PHASES_AND_PUBLICATIONS.any? { |process| send(process).enabled? } + end + def enabled_phases_and_publications_count PHASES_AND_PUBLICATIONS.count { |process| send(process).enabled? } end diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb index 6fbea5053..7181e68cf 100644 --- a/app/views/legislation/processes/_key_dates.html.erb +++ b/app/views/legislation/processes/_key_dates.html.erb @@ -1,65 +1,65 @@ - diff --git a/spec/factories/legislations.rb b/spec/factories/legislations.rb index 79a617d67..e911f574e 100644 --- a/spec/factories/legislations.rb +++ b/spec/factories/legislations.rb @@ -100,6 +100,25 @@ FactoryBot.define do end_date { 1.week.from_now } end + trait :empty do + start_date { Date.current - 5.days } + end_date { Date.current + 5.days } + debate_start_date nil + debate_end_date nil + draft_publication_date nil + allegations_start_date nil + allegations_end_date nil + proposals_phase_start_date nil + proposals_phase_end_date nil + result_publication_date nil + debate_phase_enabled false + allegations_phase_enabled false + proposals_phase_enabled false + draft_publication_enabled false + result_publication_enabled false + published true + end + end factory :legislation_draft_version, class: 'Legislation::DraftVersion' do diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index 4b71a0ccd..6d732bfd1 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -47,17 +47,32 @@ feature 'Legislation' do end end - scenario 'Key dates are displayed on current locale' do + scenario 'Participation phases are displayed only if there is a phase enabled' do + process = create(:legislation_process, :empty) + process_debate = create(:legislation_process) + + visit legislation_process_path(process) + + expect(page).not_to have_content("Participation phases") + + visit legislation_process_path(process_debate) + + expect(page).to have_content("Participation phases") + end + + scenario 'Participation phases are displayed on current locale' do process = create(:legislation_process, proposals_phase_start_date: Date.new(2018, 01, 01), proposals_phase_end_date: Date.new(2018, 12, 01)) visit legislation_process_path(process) + expect(page).to have_content("Participation phases") expect(page).to have_content("Proposals") expect(page).to have_content("01 Jan 2018 - 01 Dec 2018") visit legislation_process_path(process, locale: "es") + expect(page).to have_content("Fases de participación") expect(page).to have_content("Propuestas") expect(page).to have_content("01 ene 2018 - 01 dic 2018") end