Validate result publication enabled processes have a date

Just like we do with the rest of the phases.

The reason why we're making this change right now is that we were
getting an accessibility error with processes with no result publication
date:

```
link-name: Links must have discernible text (serious)
https://dequeuniversity.com/rules/axe/4.10/link-name?application=axeAPI
The following 1 node violate this rule:

  Selector: p:nth-child(6) > a
  HTML: <a href="/legislation/processes/39/result_publication">
          <strong></strong>
        </a>
  Fix all of the following:
  - Element is in tab order and does not have accessible text
  Fix any of the following:
  - Element does not have text that is visible to screen readers
  - aria-label attribute does not exist or is empty
  - aria-labelledby attribute does not exist, references elements that
    do not exist or references elements that are empty
  - Element has no title attribute
```
This commit is contained in:
Javi Martín
2025-02-26 11:40:35 +01:00
parent d29fca1162
commit da53a6acae
3 changed files with 17 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ class Legislation::Process < ApplicationRecord
validates_translation :title, presence: true validates_translation :title, presence: true
validates :start_date, presence: true validates :start_date, presence: true
validates :end_date, presence: true validates :end_date, presence: true
validates :result_publication_date, presence: true, if: :result_publication_enabled?
%i[draft debate proposals_phase allegations].each do |phase_name| %i[draft debate proposals_phase allegations].each do |phase_name|
enabled_attribute = :"#{phase_name.to_s.gsub("_phase", "")}_phase_enabled?" enabled_attribute = :"#{phase_name.to_s.gsub("_phase", "")}_phase_enabled?"

View File

@@ -154,6 +154,21 @@ describe Legislation::Process do
expect(proposals_disabled).to be_valid expect(proposals_disabled).to be_valid
expect(allegations_disabled).to be_valid expect(allegations_disabled).to be_valid
end end
it "is invalid if result publication is enabled but result_publication_date is not present" do
process = build(:legislation_process, result_publication_enabled: true, result_publication_date: "")
expect(process).not_to be_valid
expect(process.errors.messages[:result_publication_date]).to include("can't be blank")
end
it "is valid if result publication is enabled and result_publication_date is present" do
process = build(:legislation_process,
result_publication_enabled: true,
result_publication_date: Date.tomorrow)
expect(process).to be_valid
end
end end
describe "date ranges validations" do describe "date ranges validations" do

View File

@@ -22,6 +22,7 @@ describe "Legislation" do
scenario "empty process" do scenario "empty process" do
process = create(:legislation_process, :empty, process = create(:legislation_process, :empty,
result_publication_enabled: true, result_publication_enabled: true,
result_publication_date: 1.day.ago,
end_date: Date.current - 1.day) end_date: Date.current - 1.day)
visit summary_legislation_process_path(process) visit summary_legislation_process_path(process)