Skip to content

Commit

Permalink
✨ Détermine si la question clic dans image est clic multiple ou simpl…
Browse files Browse the repository at this point in the history
…e en fonction de la zone cliquable ajoutéex
  • Loading branch information
marouria committed Oct 2, 2024
1 parent e304665 commit 4a08e45
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/helpers/active_admin/views_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ module ViewsHelper
include ErreurHelper
include PriseEnMainHelper
include TranscriptionHelper
include QuestionHelper
end
end
7 changes: 7 additions & 0 deletions app/helpers/question_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module QuestionHelper
def type_clic(question)
question.clic_multiple? ? 'multiple' : 'simple'
end
end
11 changes: 11 additions & 0 deletions app/models/question_clic_dans_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ def as_json(_options = nil)
json.merge!(json_audio_fields, additional_json_fields)
end

def clic_multiple?
return false unless zone_cliquable.attached?

svg_content = zone_cliquable.download

doc = Nokogiri::XML(svg_content, nil, 'UTF-8')
elements_cliquables = doc.css('.bonne-reponse')

elements_cliquables.size > 1
end

private

def base_json
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/questions_clic_dans_image/_show.html.arb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ panel 'Détails de la question' do
row :audio_consigne do
tag_audio(consigne)
end
row :clic do
type_clic(question_clic_dans_image)
end
row :created_at
end
end
28 changes: 28 additions & 0 deletions spec/models/question_clic_dans_image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,32 @@
end
end
end

describe '#clic_multiple?' do
context 'avec plusieurs éléments cliquables' do
let(:question) do
create(:question_clic_dans_image,
zone_cliquable: Rack::Test::UploadedFile.new(
Rails.root.join('spec/support/accessibilite-avec-reponse-multiple.svg')
))
end

it 'est clic simple' do
expect(question.clic_multiple?).to be true
end
end

context 'avec un seul élément cliquable' do
let(:question) do
create(:question_clic_dans_image,
zone_cliquable: Rack::Test::UploadedFile.new(
Rails.root.join('spec/support/accessibilite-avec-reponse.svg')
))
end

it 'est clic multiple' do
expect(question.clic_multiple?).to be false
end
end
end
end
1 change: 1 addition & 0 deletions spec/support/accessibilite-avec-reponse-multiple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4a08e45

Please sign in to comment.