Skip to content

Commit

Permalink
pj attachment input described_by add champ.error_id target
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSim authored and inseo committed Dec 19, 2024
1 parent 05b1884 commit 1573fc4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/components/attachment/edit_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def file_field_options
describedby = []
describedby << champ.describedby_id if champ&.description.present?
describedby << describedby_hint_id if show_hint?
describedby << champ.error_id if champ&.errors&.has_key?(:value)

options[:aria] = { describedby: describedby.join(' ') }

options.merge!(has_content_type_validator? ? { accept: accept_content_type } : {})
Expand Down
25 changes: 19 additions & 6 deletions spec/components/attachment/edit_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,27 @@
expect(subject).to have_content(/Formats supportés : jpeg, png/)
end

it 'sets up its aria describedby' do
subject
describe 'aria describedby' do
let(:describedby_attribute) { page.find('input')['aria-describedby'].split }

hint_element = page.find('.fr-hint-text')
expect(hint_element['id']).to eq("#{champ.input_id}-pj-hint")
it 'targets describedby_id and pj-hint' do
subject

input_describedby = page.find('input')['aria-describedby'].split
expect(input_describedby).to eq([champ.describedby_id, "#{champ.input_id}-pj-hint"])
hint_element = page.find('.fr-hint-text')
expect(hint_element['id']).to eq("#{champ.input_id}-pj-hint")

expect(describedby_attribute).to eq([champ.describedby_id, "#{champ.input_id}-pj-hint"])
end

context 'when there is an error' do
before { champ.errors.add(:value, 'is invalid') }

it 'targets error_id' do
subject

expect(describedby_attribute).to eq([champ.describedby_id, "#{champ.input_id}-pj-hint", champ.error_id])
end
end
end
end

Expand Down

0 comments on commit 1573fc4

Please sign in to comment.