From bbfbba3f154e2854769446afad40775edc59d7ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Mon, 10 Feb 2025 15:07:33 +0100 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=90=9B=20Corrige=20l'import=20XLS=20p?= =?UTF-8?q?our=20les=20questions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/questions.rb | 22 ++++++++++++------ spec/features/admin/import_xls_spec.rb | 22 ++++++++++++++++++ .../import_question_glisser_deposer.xls | Bin 0 -> 20480 bytes 3 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 spec/features/admin/import_xls_spec.rb create mode 100644 spec/support/import_question_glisser_deposer.xls diff --git a/app/admin/questions.rb b/app/admin/questions.rb index 49a1c5659..58f8327c2 100644 --- a/app/admin/questions.rb +++ b/app/admin/questions.rb @@ -15,8 +15,8 @@ controller do def import_xls - return if params[:file_xls].blank? - return invalide_format_xls unless ImportExport::ImportXls.fichier_xls?(params[:file_xls]) + return if fichier_import.blank? + return invalide_format_xls unless ImportExport::ImportXls.fichier_xls?(fichier_import) initialise_import flash[:success] = I18n.t('.layouts.succes.import_question') @@ -29,14 +29,22 @@ def import_xls private + def fichier_import + params[:question][:file_xls] + end + + def type_question + params[:question][:type] + end + def initialise_import - ImportExport::Questions::ImportExportDonnees.new(type: params[:type]) - .importe_donnees(params[:file_xls]) + ImportExport::Questions::ImportExportDonnees.new(type: type_question) + .importe_donnees(fichier_import) end def erreur_import(error) flash[:error] = error.message - redirect_to admin_import_xls_path(type: params[:type]) + redirect_to admin_import_xls_path(type: type_question) end private @@ -51,12 +59,12 @@ def redirection_apres_import QuestionClicDansTexte::QUESTION_TYPE => admin_questions_clic_dans_texte_path } - redirection_paths[params[:type]] || admin_questions_path + redirection_paths[type_question] || admin_questions_path end def invalide_format_xls flash[:error] = I18n.t('.layouts.erreurs.import_question.format_invalide', format: 'XLS') - redirect_to admin_import_xls_path(type: params[:type]) + redirect_to admin_import_xls_path(type: type_question) end end end diff --git a/spec/features/admin/import_xls_spec.rb b/spec/features/admin/import_xls_spec.rb new file mode 100644 index 000000000..08ab7d2b8 --- /dev/null +++ b/spec/features/admin/import_xls_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'Import XLS', type: :feature do + let!(:compte) { create :compte_superadmin } + + before { connecte(compte) } + + it 'importe un fichier XLS de type QuestionGlisserDeposer' do + visit admin_import_xls_path(type: 'QuestionGlisserDeposer') + + stub_request(:get, %r{^https://stockagepreprod\.eva\.beta\.gouv\.fr(/.*)?$}) + .to_return(status: 200, body: '', headers: {}) + + chemin_fichier = Rails.root.join('spec/support/import_question_glisser_deposer.xls').to_s + attach_file('question[file_xls]', chemin_fichier) + click_button 'Importer le fichier' + + expect(page).to have_http_status(200) + end +end diff --git a/spec/support/import_question_glisser_deposer.xls b/spec/support/import_question_glisser_deposer.xls new file mode 100644 index 0000000000000000000000000000000000000000..4143de3dfdf3c499fbedd5a184fe51bb749ec5fa GIT binary patch literal 20480 zcmeHPS+pfrS>AW*zPI~^B!npe!XZFNB)K^?R{SNIx2UIFJ=_N|K-FJke{ zaKPy^pYI?B_IAOLCw9oASDinJHbi^Bk!+GrZR;DGaDFFzZ;)q02_e_f?>hm}&+ExV zr6(KYzsOCr?pg4?K|W7g{wpov$aBd*g4D%#e-K?|bA#-VH{`w^brl;>@g=#fufEO#IEw&I9((LD_;Z$=J9m+s z6CB7Z=gE1Hci_K^P);1c=kbD|3jf1XdOdmtdJWV9jcB{`(Ej4ZbL1T0i|3#%T=(Mn zb3|}165;%LC znj{zO0>O98=b89_CXWpB$Z>Iw`S-Z;XX5{u`2Qa=nW!+>{R2=2!`OYkVMmdD6(RSh z@uaj(FY#xUy-&znqNpm$Trd4Jc^1H=^vf!;C$^dUWxqhLEI);UyVIob-DEAn3aG?s zLhi8(Xq@2{PZ9FY6l5(sOUvgIlEdGmu+MO3k~BW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Lm>-u>Rs zeED5p-5|@q7&`xQ_py@Sb%iV2J@fawlL3rb{P){19B~4GgT)CrFk@lz!GQqN3J%{m zAYp>Xw0<=l*T8{^8`Jf5a6AVNOvspqaTt989GGY^y}l3*927BuV%o%EZvw|l;kXHo Tm%)Meu{yr_-D!@ez1RN>iwV}) literal 0 HcmV?d00001 From 3414ee64521922b755450b3ffb23cc43f257d393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Tue, 11 Feb 2025 11:47:21 +0100 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=90=9B=20L'export=20de=20QuestionSais?= =?UTF-8?q?ie=20retourne=20la=20colonne=20Texte=20a=20trous?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/import_export/questions/export.rb | 3 +- .../import_export/questions/export_spec.rb | 72 +++++++++---------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/app/models/import_export/questions/export.rb b/app/models/import_export/questions/export.rb index e034a783e..64ce91673 100644 --- a/app/models/import_export/questions/export.rb +++ b/app/models/import_export/questions/export.rb @@ -74,6 +74,7 @@ def remplis_champs_saisie @onglet.set_valeur(@ligne, 8, @question.suffix_reponse) @onglet.set_valeur(@ligne, 9, @question.reponse_placeholder) @onglet.set_valeur(@ligne, 10, @question.type_saisie) + @onglet.set_valeur(@ligne, 11, @question.texte_a_trous) @question.reponses.each_with_index { |reponse, index| ajoute_saisies(reponse, index) } end @@ -98,7 +99,7 @@ def ajoute_choix(choix, index) def ajoute_saisies(reponse, index) columns = %w[intitule nom_technique type_choix] columns.each_with_index do |col, i| - colonne = 11 + (index * columns.size) + i + colonne = 12 + (index * columns.size) + i @onglet.set_valeur(0, colonne, "reponse_#{index + 1}_#{col}") @onglet.set_valeur(@ligne, colonne, reponse.send(col)) end diff --git a/spec/models/import_export/questions/export_spec.rb b/spec/models/import_export/questions/export_spec.rb index bc71324f6..5e3875361 100644 --- a/spec/models/import_export/questions/export_spec.rb +++ b/spec/models/import_export/questions/export_spec.rb @@ -14,6 +14,8 @@ let(:spreadsheet) { response_service.export.workbook } let(:worksheet) { spreadsheet.worksheet(0) } + let(:headers_xls) { worksheet.row(0).map { |header| header.parameterize.underscore.to_sym } } + describe 'pour une question clic' do let(:question) do create(:question_clic_dans_image, description: 'Ceci est une description', @@ -34,16 +36,11 @@ it 'génére un fichier xls avec les entêtes sur chaque colonnes' do expect(spreadsheet.worksheets.count).to eq(1) - expect(worksheet.row(0)[0]).to eq('Libelle') - expect(worksheet.row(0)[1]).to eq('Nom technique') - expect(worksheet.row(0)[2]).to eq('Illustration') - expect(worksheet.row(0)[3]).to eq('Intitule ecrit') - expect(worksheet.row(0)[4]).to eq('Intitule audio') - expect(worksheet.row(0)[5]).to eq('Consigne ecrit') - expect(worksheet.row(0)[6]).to eq('Consigne audio') - expect(worksheet.row(0)[7]).to eq('Description') - expect(worksheet.row(0)[8]).to eq('Zone cliquable') - expect(worksheet.row(0)[9]).to eq('Image au clic') + + headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ + QuestionClicDansImage::QUESTION_TYPE + ] + expect(headers_xls).to eq headers_attendus end it 'génére un fichier xls avec les détails de la question' do @@ -71,15 +68,16 @@ it 'génére un fichier xls avec les entêtes spécifiques' do expect(spreadsheet.worksheets.count).to eq(1) - expect(worksheet.row(0)[8]).to eq('Zone depot') - expect(worksheet.row(0)[9]).to eq('reponse_1_nom_technique') - expect(worksheet.row(0)[10]).to eq('reponse_1_position_client') - expect(worksheet.row(0)[11]).to eq('reponse_1_type_choix') - expect(worksheet.row(0)[12]).to eq('reponse_1_illustration_url') - expect(worksheet.row(0)[13]).to eq('reponse_2_nom_technique') - expect(worksheet.row(0)[14]).to eq('reponse_2_position_client') - expect(worksheet.row(0)[15]).to eq('reponse_2_type_choix') - expect(worksheet.row(0)[16]).to eq('reponse_2_illustration_url') + + headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ + QuestionGlisserDeposer::QUESTION_TYPE + ] + headers_attendus += %i[reponse_1_nom_technique reponse_1_position_client reponse_1_type_choix + reponse_1_illustration_url reponse_2_nom_technique + reponse_2_position_client reponse_2_type_choix + reponse_2_illustration_url] + + expect(headers_xls).to eq headers_attendus end it 'génére un fichier xls avec les détails de la question' do @@ -106,12 +104,13 @@ it 'génére un fichier xls avec les entêtes spécifiques' do expect(spreadsheet.worksheets.count).to eq(1) - expect(worksheet.row(0)[8]).to eq('Suffix reponse') - expect(worksheet.row(0)[9]).to eq('Reponse placeholder') - expect(worksheet.row(0)[10]).to eq('Type saisie') - expect(worksheet.row(0)[11]).to eq('reponse_1_intitule') - expect(worksheet.row(0)[12]).to eq('reponse_1_nom_technique') - expect(worksheet.row(0)[13]).to eq('reponse_1_type_choix') + + headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ + QuestionSaisie::QUESTION_TYPE + ] + headers_attendus += %i[reponse_1_intitule reponse_1_nom_technique reponse_1_type_choix] + + expect(headers_xls).to eq headers_attendus end it 'génére un fichier xls avec les détails de la question' do @@ -119,8 +118,9 @@ expect(ligne[8]).to eq(question.suffix_reponse) expect(ligne[9]).to eq(question.reponse_placeholder) expect(ligne[10]).to eq(question.type_saisie) - expect(ligne[11]).to eq(question.reponses.last.intitule) - expect(ligne[12]).to eq(question.reponses.last.nom_technique) + expect(ligne[11]).to eq(question.texte_a_trous) + expect(ligne[12]).to eq(question.reponses.last.intitule) + expect(ligne[13]).to eq(question.reponses.last.nom_technique) end end @@ -134,15 +134,15 @@ it 'génére un fichier xls avec les entêtes spécifiques' do expect(spreadsheet.worksheets.count).to eq(1) - expect(worksheet.row(0)[8]).to eq('Type qcm') - expect(worksheet.row(0)[9]).to eq('choix_1_intitule') - expect(worksheet.row(0)[10]).to eq('choix_1_nom_technique') - expect(worksheet.row(0)[11]).to eq('choix_1_type_choix') - expect(worksheet.row(0)[12]).to eq('choix_1_audio_url') - expect(worksheet.row(0)[13]).to eq('choix_2_intitule') - expect(worksheet.row(0)[14]).to eq('choix_2_nom_technique') - expect(worksheet.row(0)[15]).to eq('choix_2_type_choix') - expect(worksheet.row(0)[16]).to eq('choix_2_audio_url') + + headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ + QuestionQcm::QUESTION_TYPE + ] + headers_attendus += %i[choix_1_intitule choix_1_nom_technique choix_1_type_choix + choix_1_audio_url choix_2_intitule choix_2_nom_technique + choix_2_type_choix choix_2_audio_url] + + expect(headers_xls).to eq headers_attendus end it 'génére un fichier xls avec les détails de la question' do From b6359bfc43a8c4f6c19ac4a3e7c1058ca4de0fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Wed, 12 Feb 2025 15:33:35 +0100 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=90=9B=20Exporte=20la=20colonne=20ori?= =?UTF-8?q?entation=20pour=20les=20questions=20glisser-deposer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://captive-team.atlassian.net/browse/EVA-332 --- app/models/import_export/questions/export.rb | 3 ++- .../questions/import_export_donnees.rb | 2 +- .../import_export/questions/export_spec.rb | 17 +++++++++-------- spec/support/import_question_glisser.xls | Bin 11776 -> 11776 bytes 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/models/import_export/questions/export.rb b/app/models/import_export/questions/export.rb index 64ce91673..d2df5c720 100644 --- a/app/models/import_export/questions/export.rb +++ b/app/models/import_export/questions/export.rb @@ -67,6 +67,7 @@ def remplis_champs_clic_dans_image def remplis_champs_glisser_deposer @onglet.set_valeur(@ligne, 8, @question.zone_depot_url) + @onglet.set_valeur(@ligne, 9, @question.orientation) @question.reponses.each_with_index { |choix, index| ajoute_reponses(choix, index) } end @@ -108,7 +109,7 @@ def ajoute_saisies(reponse, index) def ajoute_reponses(choix, index) columns = %w[nom_technique position_client type_choix illustration_url] columns.each_with_index do |col, i| - colonne = 9 + (index * columns.size) + i + colonne = 10 + (index * columns.size) + i @onglet.set_valeur(0, colonne, "reponse_#{index + 1}_#{col}") @onglet.set_valeur(@ligne, colonne, choix.send(col).to_s) end diff --git a/app/models/import_export/questions/import_export_donnees.rb b/app/models/import_export/questions/import_export_donnees.rb index 73774e42e..a62711905 100644 --- a/app/models/import_export/questions/import_export_donnees.rb +++ b/app/models/import_export/questions/import_export_donnees.rb @@ -5,7 +5,7 @@ module Questions class ImportExportDonnees HEADERS_CLIC_DANS_IMAGE = %i[zone_cliquable image_au_clic].freeze HEADERS_CLIC_DANS_TEXTE = %i[texte_sur_illustration].freeze - HEADERS_GLISSER_DEPOSER = %i[zone_depot].freeze + HEADERS_GLISSER_DEPOSER = %i[zone_depot orientation].freeze HEADERS_QCM = %i[type_qcm].freeze HEADERS_SAISIE = %i[suffix_reponse reponse_placeholder type_saisie texte_a_trous].freeze HEADERS_SOUS_CONSIGNE = %i[libelle nom_technique illustration intitule_ecrit diff --git a/spec/models/import_export/questions/export_spec.rb b/spec/models/import_export/questions/export_spec.rb index 5e3875361..4913d13e6 100644 --- a/spec/models/import_export/questions/export_spec.rb +++ b/spec/models/import_export/questions/export_spec.rb @@ -84,14 +84,15 @@ ligne = worksheet.row(1) expect(ligne[8]).to eq(question.zone_depot_url) - expect(ligne[9]).to eq(reponse.nom_technique) - expect(ligne[10]).to eq(reponse.position_client.to_s) - expect(ligne[11]).to eq(reponse.type_choix) - expect(ligne[12]).to eq(reponse.illustration_url.to_s) - expect(ligne[13]).to eq(reponse2.nom_technique) - expect(ligne[14]).to eq(reponse2.position_client.to_s) - expect(ligne[15]).to eq(reponse2.type_choix) - expect(ligne[16]).to eq(reponse2.illustration_url.to_s) + expect(ligne[9]).to eq(question.orientation) + expect(ligne[10]).to eq(reponse.nom_technique) + expect(ligne[11]).to eq(reponse.position_client.to_s) + expect(ligne[12]).to eq(reponse.type_choix) + expect(ligne[13]).to eq(reponse.illustration_url.to_s) + expect(ligne[14]).to eq(reponse2.nom_technique) + expect(ligne[15]).to eq(reponse2.position_client.to_s) + expect(ligne[16]).to eq(reponse2.type_choix) + expect(ligne[17]).to eq(reponse2.illustration_url.to_s) end end diff --git a/spec/support/import_question_glisser.xls b/spec/support/import_question_glisser.xls index b1baf446a57c4b06623a147dd9c17e1d791d4cdb..6443e80a46a65f8ea85607d91b8d132d92c0a827 100644 GIT binary patch delta 1945 zcmZvdO=uHA6vyArB-zd8tD7d<&$Vf+jT8^1f_N-=@gP;a2}LQoXfU)A+a83t^$P?+ zgt?1|9y|zQE?$)4&6{_j^yo=E+laoGNq2Ud2?X}{fA7uA|INVx7HE6gcLyN|J9MbZAEz%tq42ea9Rx)VR!=v5u z3>tMj&Wi@E9!-h^tzyt<598uNo^Q~`4BEIsizW=>q(Pf9XwwEQFlfgN+Kkl1u6Gat zzMek*0si6hRu5v?vF_p^f_oi88iF_C*k zN%ssd3FV&Q6`|ZSydac&hKEeKXOMKyz=<$;=$-+&KORq?bk88^p5eWv+%rhJXOMKy zAnBe#(mlg%&q?=RU;(&zRXvd%N0BH+WDiLEsx;zAM*Oa*JX@=Bw5pd?Rpn}VIc0yNYm+J-EJD$P67kZ56g&z=8#JJ_;t$kYNuqe_ zMH#$^AO$^G5X4+WQS6`K*-Lv+y!NUz`hEK&J4q)Y;l1~L^Jd;`X3|~huDriuDBJw1 z@hI__foGFelmSS`v(R}+v%s(V^9aEU#K5hYOgdo-?1cn*6KhrFblc7EKU;5jVVhf}zc z?xI91c@8~^Ls`;Yk!V%V;k%tvZ2r?e=+F}{;7S1w@VBktTVxC-fpYsb6>GU6i(!qD z`!x+~l-Xx-WR%ut3B;2_rX!=gUabR3q!iU}HIPwApQVsZ4Vj6IV*0f-G79Lk3^I!5 zv+T$?3)yr~qaSktYD0$kMJncHctoST3=e3Om*Me@@-jS}QC77&gR&ia^+sf+twZ(f;A#mNubkn^Cun5gk`wg2 zfE~ht`z1F_(s9FiT%orp;F5r+1Y8#8tdJgf?-WDFX;Kx77fX+4bZBDY@KwPlqSAu^ z@8U;f^}m$#Dhc7ESzg kKRrLk?=))qi^Vf5zgj;O-iyumzco&)Y^U7+b3Cs82SPX3!2kdN From a13a02a658162abc73e68391a0a368affc75b431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Wed, 12 Feb 2025 15:59:40 +0100 Subject: [PATCH 4/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Introduit=20le=20compt?= =?UTF-8?q?eur=20de=20colonne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/import_export/questions/export.rb | 89 +++++++++++--------- 1 file changed, 48 insertions(+), 41 deletions(-) diff --git a/app/models/import_export/questions/export.rb b/app/models/import_export/questions/export.rb index d2df5c720..ceb5782e5 100644 --- a/app/models/import_export/questions/export.rb +++ b/app/models/import_export/questions/export.rb @@ -33,83 +33,90 @@ def remplis_la_feuille end def remplis_champs_commun - @onglet.set_valeur(@ligne, 0, @question.libelle) - @onglet.set_valeur(@ligne, 1, @question.nom_technique) - @onglet.set_valeur(@ligne, 2, @question.illustration_url) - @onglet.set_valeur(@ligne, 3, @question.transcription_intitule&.ecrit) - @onglet.set_valeur(@ligne, 4, @question.transcription_intitule&.audio_url) - remplis_champs_additionnels + col = -1 + @onglet.set_valeur(@ligne, col += 1, @question.libelle) + @onglet.set_valeur(@ligne, col += 1, @question.nom_technique) + @onglet.set_valeur(@ligne, col += 1, @question.illustration_url) + @onglet.set_valeur(@ligne, col += 1, @question.transcription_intitule&.ecrit) + @onglet.set_valeur(@ligne, col += 1, @question.transcription_intitule&.audio_url) + remplis_champs_additionnels(col) end - def remplis_champs_additionnels + def remplis_champs_additionnels(col) return if @question.sous_consigne? - @onglet.set_valeur(@ligne, 5, @question.transcription_modalite_reponse&.ecrit) - @onglet.set_valeur(@ligne, 6, @question.transcription_modalite_reponse&.audio_url) - @onglet.set_valeur(@ligne, 7, @question.description) - remplis_champs_specifiques + @onglet.set_valeur(@ligne, col += 1, @question.transcription_modalite_reponse&.ecrit) + @onglet.set_valeur(@ligne, col += 1, @question.transcription_modalite_reponse&.audio_url) + @onglet.set_valeur(@ligne, col += 1, @question.description) + remplis_champs_specifiques(col) end - def remplis_champs_specifiques + def remplis_champs_specifiques(col) case @question.type - when QuestionClicDansImage::QUESTION_TYPE then remplis_champs_clic_dans_image - when QuestionGlisserDeposer::QUESTION_TYPE then remplis_champs_glisser_deposer - when QuestionQcm::QUESTION_TYPE then remplis_champs_qcm - when QuestionSaisie::QUESTION_TYPE then remplis_champs_saisie - when QuestionClicDansTexte::QUESTION_TYPE then remplis_champs_clic_dans_texte + when QuestionClicDansImage::QUESTION_TYPE then remplis_champs_clic_dans_image(col) + when QuestionGlisserDeposer::QUESTION_TYPE then remplis_champs_glisser_deposer(col) + when QuestionQcm::QUESTION_TYPE then remplis_champs_qcm(col) + when QuestionSaisie::QUESTION_TYPE then remplis_champs_saisie(col) + when QuestionClicDansTexte::QUESTION_TYPE then remplis_champs_clic_dans_texte(col) end end - def remplis_champs_clic_dans_image - @onglet.set_valeur(@ligne, 8, @question.zone_cliquable_url) - @onglet.set_valeur(@ligne, 9, @question.image_au_clic_url) + def remplis_champs_clic_dans_image(col) + @onglet.set_valeur(@ligne, col += 1, @question.zone_cliquable_url) + @onglet.set_valeur(@ligne, col += 1, @question.image_au_clic_url) # rubocop:disable Lint/UselessAssignment end - def remplis_champs_glisser_deposer - @onglet.set_valeur(@ligne, 8, @question.zone_depot_url) - @onglet.set_valeur(@ligne, 9, @question.orientation) - @question.reponses.each_with_index { |choix, index| ajoute_reponses(choix, index) } + def remplis_champs_glisser_deposer(col) + @onglet.set_valeur(@ligne, col += 1, @question.zone_depot_url) + @onglet.set_valeur(@ligne, col += 1, @question.orientation) + @question.reponses.each_with_index do |choix, index| + ajoute_reponses(choix, index, col + 1) + end end - def remplis_champs_saisie - @onglet.set_valeur(@ligne, 8, @question.suffix_reponse) - @onglet.set_valeur(@ligne, 9, @question.reponse_placeholder) - @onglet.set_valeur(@ligne, 10, @question.type_saisie) - @onglet.set_valeur(@ligne, 11, @question.texte_a_trous) - @question.reponses.each_with_index { |reponse, index| ajoute_saisies(reponse, index) } + def remplis_champs_qcm(col) + @onglet.set_valeur(@ligne, col += 1, @question.type_qcm) + @question.choix.each_with_index do |choix, index| + ajoute_choix(choix, index, col + 1) + end end - def remplis_champs_qcm - @onglet.set_valeur(@ligne, 8, @question.type_qcm) - @question.choix.each_with_index { |choix, index| ajoute_choix(choix, index) } + def remplis_champs_saisie(col) + @onglet.set_valeur(@ligne, col += 1, @question.suffix_reponse) + @onglet.set_valeur(@ligne, col += 1, @question.reponse_placeholder) + @onglet.set_valeur(@ligne, col += 1, @question.type_saisie) + @onglet.set_valeur(@ligne, col += 1, @question.texte_a_trous) + @question.reponses.each_with_index do |reponse, index| + ajoute_saisies(reponse, index, col + 1) + end end - def remplis_champs_clic_dans_texte - @onglet.set_valeur(@ligne, 8, @question.texte_sur_illustration) + def remplis_champs_clic_dans_texte(col) + @onglet.set_valeur(@ligne, col += 1, @question.texte_sur_illustration) # rubocop:disable Lint/UselessAssignment end - def ajoute_choix(choix, index) + def ajoute_choix(choix, index, col_debut) columns = %w[intitule nom_technique type_choix audio_url] columns.each_with_index do |col, i| - colonne = 9 + (index * columns.size) + i + colonne = col_debut + (index * columns.size) + i @onglet.set_valeur(0, colonne, "choix_#{index + 1}_#{col}") @onglet.set_valeur(@ligne, colonne, choix.send(col)) end end - def ajoute_saisies(reponse, index) + def ajoute_saisies(reponse, index, col_debut) columns = %w[intitule nom_technique type_choix] columns.each_with_index do |col, i| - colonne = 12 + (index * columns.size) + i + colonne = col_debut + (index * columns.size) + i @onglet.set_valeur(0, colonne, "reponse_#{index + 1}_#{col}") @onglet.set_valeur(@ligne, colonne, reponse.send(col)) end end - def ajoute_reponses(choix, index) + def ajoute_reponses(choix, index, col_debut) columns = %w[nom_technique position_client type_choix illustration_url] columns.each_with_index do |col, i| - colonne = 10 + (index * columns.size) + i + colonne = col_debut + (index * columns.size) + i @onglet.set_valeur(0, colonne, "reponse_#{index + 1}_#{col}") @onglet.set_valeur(@ligne, colonne, choix.send(col).to_s) end From 3e739323d926453e3811587d2ac9e3518e2e18da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Wed, 12 Feb 2025 16:44:48 +0100 Subject: [PATCH 5/7] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20S=C3=A9pare=20les=20ex?= =?UTF-8?q?porteurs=20par=20type=20de=20question?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/import_export/questions/export.rb | 71 +------------------ .../export/question_clic_dans_image.rb | 19 +++++ .../export/question_clic_dans_texte.rb | 20 ++++++ .../export/question_glisser_deposer.rb | 33 +++++++++ .../questions/export/question_qcm.rb | 32 +++++++++ .../questions/export/question_saisie.rb | 36 ++++++++++ .../export/question_sous_consigne.rb | 19 +++++ .../questions/import_export_donnees.rb | 11 ++- .../import_export/questions/export_spec.rb | 12 +++- 9 files changed, 179 insertions(+), 74 deletions(-) create mode 100644 app/models/import_export/questions/export/question_clic_dans_image.rb create mode 100644 app/models/import_export/questions/export/question_clic_dans_texte.rb create mode 100644 app/models/import_export/questions/export/question_glisser_deposer.rb create mode 100644 app/models/import_export/questions/export/question_qcm.rb create mode 100644 app/models/import_export/questions/export/question_saisie.rb create mode 100644 app/models/import_export/questions/export/question_sous_consigne.rb diff --git a/app/models/import_export/questions/export.rb b/app/models/import_export/questions/export.rb index ceb5782e5..51573d74f 100644 --- a/app/models/import_export/questions/export.rb +++ b/app/models/import_export/questions/export.rb @@ -51,76 +51,7 @@ def remplis_champs_additionnels(col) remplis_champs_specifiques(col) end - def remplis_champs_specifiques(col) - case @question.type - when QuestionClicDansImage::QUESTION_TYPE then remplis_champs_clic_dans_image(col) - when QuestionGlisserDeposer::QUESTION_TYPE then remplis_champs_glisser_deposer(col) - when QuestionQcm::QUESTION_TYPE then remplis_champs_qcm(col) - when QuestionSaisie::QUESTION_TYPE then remplis_champs_saisie(col) - when QuestionClicDansTexte::QUESTION_TYPE then remplis_champs_clic_dans_texte(col) - end - end - - def remplis_champs_clic_dans_image(col) - @onglet.set_valeur(@ligne, col += 1, @question.zone_cliquable_url) - @onglet.set_valeur(@ligne, col += 1, @question.image_au_clic_url) # rubocop:disable Lint/UselessAssignment - end - - def remplis_champs_glisser_deposer(col) - @onglet.set_valeur(@ligne, col += 1, @question.zone_depot_url) - @onglet.set_valeur(@ligne, col += 1, @question.orientation) - @question.reponses.each_with_index do |choix, index| - ajoute_reponses(choix, index, col + 1) - end - end - - def remplis_champs_qcm(col) - @onglet.set_valeur(@ligne, col += 1, @question.type_qcm) - @question.choix.each_with_index do |choix, index| - ajoute_choix(choix, index, col + 1) - end - end - - def remplis_champs_saisie(col) - @onglet.set_valeur(@ligne, col += 1, @question.suffix_reponse) - @onglet.set_valeur(@ligne, col += 1, @question.reponse_placeholder) - @onglet.set_valeur(@ligne, col += 1, @question.type_saisie) - @onglet.set_valeur(@ligne, col += 1, @question.texte_a_trous) - @question.reponses.each_with_index do |reponse, index| - ajoute_saisies(reponse, index, col + 1) - end - end - - def remplis_champs_clic_dans_texte(col) - @onglet.set_valeur(@ligne, col += 1, @question.texte_sur_illustration) # rubocop:disable Lint/UselessAssignment - end - - def ajoute_choix(choix, index, col_debut) - columns = %w[intitule nom_technique type_choix audio_url] - columns.each_with_index do |col, i| - colonne = col_debut + (index * columns.size) + i - @onglet.set_valeur(0, colonne, "choix_#{index + 1}_#{col}") - @onglet.set_valeur(@ligne, colonne, choix.send(col)) - end - end - - def ajoute_saisies(reponse, index, col_debut) - columns = %w[intitule nom_technique type_choix] - columns.each_with_index do |col, i| - colonne = col_debut + (index * columns.size) + i - @onglet.set_valeur(0, colonne, "reponse_#{index + 1}_#{col}") - @onglet.set_valeur(@ligne, colonne, reponse.send(col)) - end - end - - def ajoute_reponses(choix, index, col_debut) - columns = %w[nom_technique position_client type_choix illustration_url] - columns.each_with_index do |col, i| - colonne = col_debut + (index * columns.size) + i - @onglet.set_valeur(0, colonne, "reponse_#{index + 1}_#{col}") - @onglet.set_valeur(@ligne, colonne, choix.send(col).to_s) - end - end + def remplis_champs_specifiques(col); end end end end diff --git a/app/models/import_export/questions/export/question_clic_dans_image.rb b/app/models/import_export/questions/export/question_clic_dans_image.rb new file mode 100644 index 000000000..241927606 --- /dev/null +++ b/app/models/import_export/questions/export/question_clic_dans_image.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module ImportExport + module Questions + class Export + class QuestionClicDansImage < ImportExport::Questions::Export + def initialize(questions, headers_commun) + headers = headers_commun + %i[zone_cliquable image_au_clic].freeze + super(questions, headers) + end + + def remplis_champs_specifiques(col) + @onglet.set_valeur(@ligne, col += 1, @question.zone_cliquable_url) + @onglet.set_valeur(@ligne, col += 1, @question.image_au_clic_url) # rubocop:disable Lint/UselessAssignment + end + end + end + end +end diff --git a/app/models/import_export/questions/export/question_clic_dans_texte.rb b/app/models/import_export/questions/export/question_clic_dans_texte.rb new file mode 100644 index 000000000..f89ab6b20 --- /dev/null +++ b/app/models/import_export/questions/export/question_clic_dans_texte.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module ImportExport + module Questions + class Export + class QuestionClicDansTexte < ImportExport::Questions::Export + def initialize(questions, headers_commun) + headers = headers_commun + %i[texte_sur_illustration].freeze + super(questions, headers) + end + + private + + def remplis_champs_specifiques(col) + @onglet.set_valeur(@ligne, col += 1, @question.texte_sur_illustration) # rubocop:disable Lint/UselessAssignment + end + end + end + end +end diff --git a/app/models/import_export/questions/export/question_glisser_deposer.rb b/app/models/import_export/questions/export/question_glisser_deposer.rb new file mode 100644 index 000000000..6ebc0ef93 --- /dev/null +++ b/app/models/import_export/questions/export/question_glisser_deposer.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module ImportExport + module Questions + class Export + class QuestionGlisserDeposer < ImportExport::Questions::Export + def initialize(questions, headers_commun) + headers = headers_commun + %i[zone_depot orientation].freeze + super(questions, headers) + end + + private + + def remplis_champs_specifiques(col) + @onglet.set_valeur(@ligne, col += 1, @question.zone_depot_url) + @onglet.set_valeur(@ligne, col += 1, @question.orientation) + @question.reponses.each_with_index do |choix, index| + ajoute_reponses(choix, index, col + 1) + end + end + + def ajoute_reponses(choix, index, col_debut) + columns = %w[nom_technique position_client type_choix illustration_url] + columns.each_with_index do |col, i| + colonne = col_debut + (index * columns.size) + i + @onglet.set_valeur(0, colonne, "reponse_#{index + 1}_#{col}") + @onglet.set_valeur(@ligne, colonne, choix.send(col).to_s) + end + end + end + end + end +end diff --git a/app/models/import_export/questions/export/question_qcm.rb b/app/models/import_export/questions/export/question_qcm.rb new file mode 100644 index 000000000..e31a5c223 --- /dev/null +++ b/app/models/import_export/questions/export/question_qcm.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module ImportExport + module Questions + class Export + class QuestionQcm < ImportExport::Questions::Export + def initialize(questions, headers_commun) + headers = headers_commun + %i[type_qcm].freeze + super(questions, headers) + end + + private + + def remplis_champs_specifiques(col) + @onglet.set_valeur(@ligne, col += 1, @question.type_qcm) + @question.choix.each_with_index do |choix, index| + ajoute_choix(choix, index, col + 1) + end + end + + def ajoute_choix(choix, index, col_debut) + columns = %w[intitule nom_technique type_choix audio_url] + columns.each_with_index do |col, i| + colonne = col_debut + (index * columns.size) + i + @onglet.set_valeur(0, colonne, "choix_#{index + 1}_#{col}") + @onglet.set_valeur(@ligne, colonne, choix.send(col)) + end + end + end + end + end +end diff --git a/app/models/import_export/questions/export/question_saisie.rb b/app/models/import_export/questions/export/question_saisie.rb new file mode 100644 index 000000000..86b59d197 --- /dev/null +++ b/app/models/import_export/questions/export/question_saisie.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +module ImportExport + module Questions + class Export + class QuestionSaisie < ImportExport::Questions::Export + def initialize(questions, headers_commun) + headers = headers_commun + %i[suffix_reponse reponse_placeholder type_saisie + texte_a_trous].freeze + super(questions, headers) + end + + private + + def remplis_champs_specifiques(col) + @onglet.set_valeur(@ligne, col += 1, @question.suffix_reponse) + @onglet.set_valeur(@ligne, col += 1, @question.reponse_placeholder) + @onglet.set_valeur(@ligne, col += 1, @question.type_saisie) + @onglet.set_valeur(@ligne, col += 1, @question.texte_a_trous) + @question.reponses.each_with_index do |reponse, index| + ajoute_saisies(reponse, index, col + 1) + end + end + + def ajoute_saisies(reponse, index, col_debut) + columns = %w[intitule nom_technique type_choix] + columns.each_with_index do |col, i| + colonne = col_debut + (index * columns.size) + i + @onglet.set_valeur(0, colonne, "reponse_#{index + 1}_#{col}") + @onglet.set_valeur(@ligne, colonne, reponse.send(col)) + end + end + end + end + end +end diff --git a/app/models/import_export/questions/export/question_sous_consigne.rb b/app/models/import_export/questions/export/question_sous_consigne.rb new file mode 100644 index 000000000..50515944a --- /dev/null +++ b/app/models/import_export/questions/export/question_sous_consigne.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module ImportExport + module Questions + class Export + class QuestionSousConsigne < ImportExport::Questions::Export + def initialize(questions, _headers_commun) + headers = %i[libelle nom_technique illustration intitule_ecrit intitule_audio + consigne_ecrit consigne_audio description].freeze + super(questions, headers) + end + + private + + def remplis_champs_specifiques(col); end + end + end + end +end diff --git a/app/models/import_export/questions/import_export_donnees.rb b/app/models/import_export/questions/import_export_donnees.rb index a62711905..a86507611 100644 --- a/app/models/import_export/questions/import_export_donnees.rb +++ b/app/models/import_export/questions/import_export_donnees.rb @@ -20,6 +20,14 @@ class ImportExportDonnees QuestionSaisie::QUESTION_TYPE => HEADERS_COMMUN + HEADERS_SAISIE, QuestionSousConsigne::QUESTION_TYPE => HEADERS_SOUS_CONSIGNE }.freeze + EXPORTEURS = { + QuestionClicDansImage::QUESTION_TYPE => Export::QuestionClicDansImage, + QuestionClicDansTexte::QUESTION_TYPE => Export::QuestionClicDansTexte, + QuestionGlisserDeposer::QUESTION_TYPE => Export::QuestionGlisserDeposer, + QuestionQcm::QUESTION_TYPE => Export::QuestionQcm, + QuestionSaisie::QUESTION_TYPE => Export::QuestionSaisie, + QuestionSousConsigne::QUESTION_TYPE => Export::QuestionSousConsigne + }.freeze def initialize(questions: nil, type: nil) @questions = questions @@ -33,7 +41,8 @@ def importe_donnees(file) end def exporte_donnees - export = Export.new(@questions, HEADERS_ATTENDUS[@type]) + Rails.logger.debug EXPORTEURS[@type] + export = EXPORTEURS[@type].new(@questions, HEADERS_COMMUN) { xls: export.to_xls, content_type: export.content_type_xls, diff --git a/spec/models/import_export/questions/export_spec.rb b/spec/models/import_export/questions/export_spec.rb index 4913d13e6..07dc4af00 100644 --- a/spec/models/import_export/questions/export_spec.rb +++ b/spec/models/import_export/questions/export_spec.rb @@ -4,19 +4,22 @@ describe ImportExport::Questions::Export do subject(:response_service) do - response_service = described_class.new([question], headers) + response_service = exporteur.new( + [question], ImportExport::Questions::ImportExportDonnees::HEADERS_COMMUN + ) response_service.to_xls response_service end + let(:exporteur) { described_class } let(:headers) { [] } let(:question) { create(:question) } let(:spreadsheet) { response_service.export.workbook } let(:worksheet) { spreadsheet.worksheet(0) } - let(:headers_xls) { worksheet.row(0).map { |header| header.parameterize.underscore.to_sym } } - describe 'pour une question clic' do + describe 'pour une question clic dans image' do + let(:exporteur) { ImportExport::Questions::Export::QuestionClicDansImage } let(:question) do create(:question_clic_dans_image, description: 'Ceci est une description', nom_technique: 'clic') @@ -59,6 +62,7 @@ end describe 'pour une question glisser deposer' do + let(:exporteur) { ImportExport::Questions::Export::QuestionGlisserDeposer } let!(:question) { create(:question_glisser_deposer) } let(:headers) do ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] @@ -97,6 +101,7 @@ end describe 'pour une question saisie' do + let(:exporteur) { ImportExport::Questions::Export::QuestionSaisie } let(:question) { create(:question_saisie) } let(:headers) do ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] @@ -126,6 +131,7 @@ end describe 'pour une question qcm' do + let(:exporteur) { ImportExport::Questions::Export::QuestionQcm } let(:question) { create(:question_qcm) } let(:headers) do ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] From 93c1996219f3565bf4edd35777b63ef6025bf593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Wed, 12 Feb 2025 17:04:03 +0100 Subject: [PATCH 6/7] =?UTF-8?q?=E2=9C=85=20Extraie=20les=20tests=20d'expor?= =?UTF-8?q?t=20par=20type=20de=20question?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../export/question_sous_consigne.rb | 3 +- .../export/question_clic_dans_image_spec.rb | 57 +++++++ .../export/question_clic_dans_texte_spec.rb | 56 +++++++ .../export/question_glisser_deposer_spec.rb | 53 ++++++ .../questions/export/question_qcm_spec.rb | 50 ++++++ .../questions/export/question_saisie_spec.rb | 44 +++++ .../export/question_sous_consigne_spec.rb | 56 +++++++ .../import_export/questions/export_spec.rb | 158 +----------------- 8 files changed, 321 insertions(+), 156 deletions(-) create mode 100644 spec/models/import_export/questions/export/question_clic_dans_image_spec.rb create mode 100644 spec/models/import_export/questions/export/question_clic_dans_texte_spec.rb create mode 100644 spec/models/import_export/questions/export/question_glisser_deposer_spec.rb create mode 100644 spec/models/import_export/questions/export/question_qcm_spec.rb create mode 100644 spec/models/import_export/questions/export/question_saisie_spec.rb create mode 100644 spec/models/import_export/questions/export/question_sous_consigne_spec.rb diff --git a/app/models/import_export/questions/export/question_sous_consigne.rb b/app/models/import_export/questions/export/question_sous_consigne.rb index 50515944a..0c2d39f5c 100644 --- a/app/models/import_export/questions/export/question_sous_consigne.rb +++ b/app/models/import_export/questions/export/question_sous_consigne.rb @@ -5,8 +5,7 @@ module Questions class Export class QuestionSousConsigne < ImportExport::Questions::Export def initialize(questions, _headers_commun) - headers = %i[libelle nom_technique illustration intitule_ecrit intitule_audio - consigne_ecrit consigne_audio description].freeze + headers = %i[libelle nom_technique illustration intitule_ecrit intitule_audio].freeze super(questions, headers) end diff --git a/spec/models/import_export/questions/export/question_clic_dans_image_spec.rb b/spec/models/import_export/questions/export/question_clic_dans_image_spec.rb new file mode 100644 index 000000000..dca0ee1e0 --- /dev/null +++ b/spec/models/import_export/questions/export/question_clic_dans_image_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ImportExport::Questions::Export::QuestionClicDansImage do + subject(:response_service) do + response_service = described_class.new( + [question], ImportExport::Questions::ImportExportDonnees::HEADERS_COMMUN + ) + response_service.to_xls + response_service + end + + let(:spreadsheet) { response_service.export.workbook } + let(:worksheet) { spreadsheet.worksheet(0) } + let(:headers_xls) { worksheet.row(0).map { |header| header.parameterize.underscore.to_sym } } + + let(:question) do + create(:question_clic_dans_image, description: 'Ceci est une description', + nom_technique: 'clic') + end + let!(:intitule) do + create(:transcription, :avec_audio, question_id: question.id, categorie: :intitule, + ecrit: 'Ceci est un intitulé') + end + let!(:consigne) do + create(:transcription, :avec_audio, question_id: question.id, + categorie: :modalite_reponse, + ecrit: 'Ceci est une consigne') + end + let(:headers) do + ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] + end + + it 'génére un fichier xls avec les entêtes sur chaque colonnes' do + expect(spreadsheet.worksheets.count).to eq(1) + + headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ + QuestionClicDansImage::QUESTION_TYPE + ] + expect(headers_xls).to eq headers_attendus + end + + it 'génére un fichier xls avec les détails de la question' do + ligne = worksheet.row(1) + expect(ligne[0]).to eq('Question clic dans image') + expect(ligne[1]).to eq('clic') + expect(ligne[2]).to be_nil + expect(ligne[3]).to eq('Ceci est un intitulé') + expect(ligne[4]).to eq(intitule.audio_url) + expect(ligne[5]).to eq('Ceci est une consigne') + expect(ligne[6]).to eq(consigne.audio_url) + expect(ligne[7]).to eq('Ceci est une description') + expect(ligne[8]).to eq(question.zone_cliquable_url) + expect(ligne[9]).to eq(question.image_au_clic_url) + end +end diff --git a/spec/models/import_export/questions/export/question_clic_dans_texte_spec.rb b/spec/models/import_export/questions/export/question_clic_dans_texte_spec.rb new file mode 100644 index 000000000..8857bda4f --- /dev/null +++ b/spec/models/import_export/questions/export/question_clic_dans_texte_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ImportExport::Questions::Export::QuestionClicDansTexte do + subject(:response_service) do + response_service = described_class.new( + [question], ImportExport::Questions::ImportExportDonnees::HEADERS_COMMUN + ) + response_service.to_xls + response_service + end + + let(:spreadsheet) { response_service.export.workbook } + let(:worksheet) { spreadsheet.worksheet(0) } + let(:headers_xls) { worksheet.row(0).map { |header| header.parameterize.underscore.to_sym } } + + let(:question) do + create(:question_clic_dans_image, description: 'Ceci est une description', + nom_technique: 'clic') + end + let!(:intitule) do + create(:transcription, :avec_audio, question_id: question.id, categorie: :intitule, + ecrit: 'Ceci est un intitulé') + end + let!(:consigne) do + create(:transcription, :avec_audio, question_id: question.id, + categorie: :modalite_reponse, + ecrit: 'Ceci est une consigne') + end + let(:headers) do + ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] + end + + it 'génére un fichier xls avec les entêtes sur chaque colonnes' do + expect(spreadsheet.worksheets.count).to eq(1) + + headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ + QuestionClicDansTexte::QUESTION_TYPE + ] + expect(headers_xls).to eq headers_attendus + end + + it 'génére un fichier xls avec les détails de la question' do + ligne = worksheet.row(1) + expect(ligne[0]).to eq('Question clic dans image') + expect(ligne[1]).to eq('clic') + expect(ligne[2]).to be_nil + expect(ligne[3]).to eq('Ceci est un intitulé') + expect(ligne[4]).to eq(intitule.audio_url) + expect(ligne[5]).to eq('Ceci est une consigne') + expect(ligne[6]).to eq(consigne.audio_url) + expect(ligne[7]).to eq('Ceci est une description') + expect(ligne[8]).to eq(question.texte_sur_illustration) + end +end diff --git a/spec/models/import_export/questions/export/question_glisser_deposer_spec.rb b/spec/models/import_export/questions/export/question_glisser_deposer_spec.rb new file mode 100644 index 000000000..08713bc05 --- /dev/null +++ b/spec/models/import_export/questions/export/question_glisser_deposer_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ImportExport::Questions::Export::QuestionGlisserDeposer do + subject(:response_service) do + response_service = described_class.new( + [question], ImportExport::Questions::ImportExportDonnees::HEADERS_COMMUN + ) + response_service.to_xls + response_service + end + + let(:spreadsheet) { response_service.export.workbook } + let(:worksheet) { spreadsheet.worksheet(0) } + let(:headers_xls) { worksheet.row(0).map { |header| header.parameterize.underscore.to_sym } } + + let!(:question) { create(:question_glisser_deposer) } + let(:headers) do + ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] + end + let!(:reponse) { create(:choix, :bon, question_id: question.id) } + let!(:reponse2) { create(:choix, :mauvais, question_id: question.id) } + + it 'génére un fichier xls avec les entêtes spécifiques' do + expect(spreadsheet.worksheets.count).to eq(1) + + headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ + QuestionGlisserDeposer::QUESTION_TYPE + ] + headers_attendus += %i[reponse_1_nom_technique reponse_1_position_client reponse_1_type_choix + reponse_1_illustration_url reponse_2_nom_technique + reponse_2_position_client reponse_2_type_choix + reponse_2_illustration_url] + + expect(headers_xls).to eq headers_attendus + end + + it 'génére un fichier xls avec les détails de la question' do + ligne = worksheet.row(1) + + expect(ligne[8]).to eq(question.zone_depot_url) + expect(ligne[9]).to eq(question.orientation) + expect(ligne[10]).to eq(reponse.nom_technique) + expect(ligne[11]).to eq(reponse.position_client.to_s) + expect(ligne[12]).to eq(reponse.type_choix) + expect(ligne[13]).to eq(reponse.illustration_url.to_s) + expect(ligne[14]).to eq(reponse2.nom_technique) + expect(ligne[15]).to eq(reponse2.position_client.to_s) + expect(ligne[16]).to eq(reponse2.type_choix) + expect(ligne[17]).to eq(reponse2.illustration_url.to_s) + end +end diff --git a/spec/models/import_export/questions/export/question_qcm_spec.rb b/spec/models/import_export/questions/export/question_qcm_spec.rb new file mode 100644 index 000000000..1b52ba069 --- /dev/null +++ b/spec/models/import_export/questions/export/question_qcm_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ImportExport::Questions::Export::QuestionQcm do + subject(:response_service) do + response_service = described_class.new( + [question], ImportExport::Questions::ImportExportDonnees::HEADERS_COMMUN + ) + response_service.to_xls + response_service + end + + let(:spreadsheet) { response_service.export.workbook } + let(:worksheet) { spreadsheet.worksheet(0) } + let(:headers_xls) { worksheet.row(0).map { |header| header.parameterize.underscore.to_sym } } + + let(:question) { create(:question_qcm) } + let(:headers) do + ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] + end + let!(:reponse) { create(:choix, :bon, question_id: question.id) } + let!(:reponse2) { create(:choix, :mauvais, question_id: question.id) } + + it 'génére un fichier xls avec les entêtes spécifiques' do + expect(spreadsheet.worksheets.count).to eq(1) + + headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ + QuestionQcm::QUESTION_TYPE + ] + headers_attendus += %i[choix_1_intitule choix_1_nom_technique choix_1_type_choix + choix_1_audio_url choix_2_intitule choix_2_nom_technique + choix_2_type_choix choix_2_audio_url] + + expect(headers_xls).to eq headers_attendus + end + + it 'génére un fichier xls avec les détails de la question' do + ligne = worksheet.row(1) + expect(ligne[8]).to eq(question.type_qcm) + expect(ligne[9]).to eq(reponse.intitule) + expect(ligne[10]).to eq(reponse.nom_technique) + expect(ligne[11]).to eq(reponse.type_choix) + expect(ligne[12]).to eq(reponse.audio_url) + expect(ligne[13]).to eq(reponse2.intitule) + expect(ligne[14]).to eq(reponse2.nom_technique) + expect(ligne[15]).to eq(reponse2.type_choix) + expect(ligne[16]).to eq(reponse2.audio_url) + end +end diff --git a/spec/models/import_export/questions/export/question_saisie_spec.rb b/spec/models/import_export/questions/export/question_saisie_spec.rb new file mode 100644 index 000000000..7966bf999 --- /dev/null +++ b/spec/models/import_export/questions/export/question_saisie_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ImportExport::Questions::Export::QuestionSaisie do + subject(:response_service) do + response_service = described_class.new( + [question], ImportExport::Questions::ImportExportDonnees::HEADERS_COMMUN + ) + response_service.to_xls + response_service + end + + let(:spreadsheet) { response_service.export.workbook } + let(:worksheet) { spreadsheet.worksheet(0) } + let(:headers_xls) { worksheet.row(0).map { |header| header.parameterize.underscore.to_sym } } + + let(:question) { create(:question_saisie) } + let(:headers) do + ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] + end + let!(:reponse) { create(:choix, :bon, question_id: question.id) } + + it 'génére un fichier xls avec les entêtes spécifiques' do + expect(spreadsheet.worksheets.count).to eq(1) + + headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ + QuestionSaisie::QUESTION_TYPE + ] + headers_attendus += %i[reponse_1_intitule reponse_1_nom_technique reponse_1_type_choix] + + expect(headers_xls).to eq headers_attendus + end + + it 'génére un fichier xls avec les détails de la question' do + ligne = worksheet.row(1) + expect(ligne[8]).to eq(question.suffix_reponse) + expect(ligne[9]).to eq(question.reponse_placeholder) + expect(ligne[10]).to eq(question.type_saisie) + expect(ligne[11]).to eq(question.texte_a_trous) + expect(ligne[12]).to eq(question.reponses.last.intitule) + expect(ligne[13]).to eq(question.reponses.last.nom_technique) + end +end diff --git a/spec/models/import_export/questions/export/question_sous_consigne_spec.rb b/spec/models/import_export/questions/export/question_sous_consigne_spec.rb new file mode 100644 index 000000000..18f2152d6 --- /dev/null +++ b/spec/models/import_export/questions/export/question_sous_consigne_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe ImportExport::Questions::Export::QuestionSousConsigne do + subject(:response_service) do + response_service = described_class.new( + [question], ImportExport::Questions::ImportExportDonnees::HEADERS_COMMUN + ) + response_service.to_xls + response_service + end + + let(:spreadsheet) { response_service.export.workbook } + let(:worksheet) { spreadsheet.worksheet(0) } + let(:headers_xls) { worksheet.row(0).map { |header| header.parameterize.underscore.to_sym } } + + let(:question) do + create(:question_clic_dans_image, description: 'Ceci est une description', + nom_technique: 'clic') + end + let!(:intitule) do + create(:transcription, :avec_audio, question_id: question.id, categorie: :intitule, + ecrit: 'Ceci est un intitulé') + end + let!(:consigne) do + create(:transcription, :avec_audio, question_id: question.id, + categorie: :modalite_reponse, + ecrit: 'Ceci est une consigne') + end + let(:headers) do + ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] + end + + it 'génére un fichier xls avec les entêtes sur chaque colonnes' do + expect(spreadsheet.worksheets.count).to eq(1) + + headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ + QuestionSousConsigne::QUESTION_TYPE + ] + expect(headers_xls).to eq headers_attendus + end + + it 'génére un fichier xls avec les détails de la question' do + ligne = worksheet.row(1) + expect(ligne[0]).to eq('Question clic dans image') + expect(ligne[1]).to eq('clic') + expect(ligne[2]).to be_nil + expect(ligne[3]).to eq('Ceci est un intitulé') + expect(ligne[4]).to eq(intitule.audio_url) + expect(ligne[5]).to eq('Ceci est une consigne') + expect(ligne[6]).to eq(consigne.audio_url) + expect(ligne[7]).to eq('Ceci est une description') + expect(ligne[8]).to eq(question.texte_sur_illustration) + end +end diff --git a/spec/models/import_export/questions/export_spec.rb b/spec/models/import_export/questions/export_spec.rb index 07dc4af00..7921de28f 100644 --- a/spec/models/import_export/questions/export_spec.rb +++ b/spec/models/import_export/questions/export_spec.rb @@ -18,162 +18,12 @@ let(:worksheet) { spreadsheet.worksheet(0) } let(:headers_xls) { worksheet.row(0).map { |header| header.parameterize.underscore.to_sym } } - describe 'pour une question clic dans image' do - let(:exporteur) { ImportExport::Questions::Export::QuestionClicDansImage } - let(:question) do - create(:question_clic_dans_image, description: 'Ceci est une description', - nom_technique: 'clic') - end - let!(:intitule) do - create(:transcription, :avec_audio, question_id: question.id, categorie: :intitule, - ecrit: 'Ceci est un intitulé') - end - let!(:consigne) do - create(:transcription, :avec_audio, question_id: question.id, - categorie: :modalite_reponse, - ecrit: 'Ceci est une consigne') - end - let(:headers) do - ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] - end - - it 'génére un fichier xls avec les entêtes sur chaque colonnes' do - expect(spreadsheet.worksheets.count).to eq(1) - - headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ - QuestionClicDansImage::QUESTION_TYPE - ] - expect(headers_xls).to eq headers_attendus - end - - it 'génére un fichier xls avec les détails de la question' do - ligne = worksheet.row(1) - expect(ligne[0]).to eq('Question clic dans image') - expect(ligne[1]).to eq('clic') - expect(ligne[2]).to be_nil - expect(ligne[3]).to eq('Ceci est un intitulé') - expect(ligne[4]).to eq(intitule.audio_url) - expect(ligne[5]).to eq('Ceci est une consigne') - expect(ligne[6]).to eq(consigne.audio_url) - expect(ligne[7]).to eq('Ceci est une description') - expect(ligne[8]).to eq(question.zone_cliquable_url) - expect(ligne[9]).to eq(question.image_au_clic_url) - end - end - - describe 'pour une question glisser deposer' do - let(:exporteur) { ImportExport::Questions::Export::QuestionGlisserDeposer } - let!(:question) { create(:question_glisser_deposer) } - let(:headers) do - ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] - end - let!(:reponse) { create(:choix, :bon, question_id: question.id) } - let!(:reponse2) { create(:choix, :mauvais, question_id: question.id) } - - it 'génére un fichier xls avec les entêtes spécifiques' do - expect(spreadsheet.worksheets.count).to eq(1) - - headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ - QuestionGlisserDeposer::QUESTION_TYPE - ] - headers_attendus += %i[reponse_1_nom_technique reponse_1_position_client reponse_1_type_choix - reponse_1_illustration_url reponse_2_nom_technique - reponse_2_position_client reponse_2_type_choix - reponse_2_illustration_url] - - expect(headers_xls).to eq headers_attendus - end - - it 'génére un fichier xls avec les détails de la question' do - ligne = worksheet.row(1) - - expect(ligne[8]).to eq(question.zone_depot_url) - expect(ligne[9]).to eq(question.orientation) - expect(ligne[10]).to eq(reponse.nom_technique) - expect(ligne[11]).to eq(reponse.position_client.to_s) - expect(ligne[12]).to eq(reponse.type_choix) - expect(ligne[13]).to eq(reponse.illustration_url.to_s) - expect(ligne[14]).to eq(reponse2.nom_technique) - expect(ligne[15]).to eq(reponse2.position_client.to_s) - expect(ligne[16]).to eq(reponse2.type_choix) - expect(ligne[17]).to eq(reponse2.illustration_url.to_s) - end - end - - describe 'pour une question saisie' do - let(:exporteur) { ImportExport::Questions::Export::QuestionSaisie } - let(:question) { create(:question_saisie) } - let(:headers) do - ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] - end - let!(:reponse) { create(:choix, :bon, question_id: question.id) } - - it 'génére un fichier xls avec les entêtes spécifiques' do - expect(spreadsheet.worksheets.count).to eq(1) - - headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ - QuestionSaisie::QUESTION_TYPE - ] - headers_attendus += %i[reponse_1_intitule reponse_1_nom_technique reponse_1_type_choix] - - expect(headers_xls).to eq headers_attendus - end - - it 'génére un fichier xls avec les détails de la question' do - ligne = worksheet.row(1) - expect(ligne[8]).to eq(question.suffix_reponse) - expect(ligne[9]).to eq(question.reponse_placeholder) - expect(ligne[10]).to eq(question.type_saisie) - expect(ligne[11]).to eq(question.texte_a_trous) - expect(ligne[12]).to eq(question.reponses.last.intitule) - expect(ligne[13]).to eq(question.reponses.last.nom_technique) - end - end - - describe 'pour une question qcm' do - let(:exporteur) { ImportExport::Questions::Export::QuestionQcm } - let(:question) { create(:question_qcm) } - let(:headers) do - ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[question.type] - end - let!(:reponse) { create(:choix, :bon, question_id: question.id) } - let!(:reponse2) { create(:choix, :mauvais, question_id: question.id) } - - it 'génére un fichier xls avec les entêtes spécifiques' do - expect(spreadsheet.worksheets.count).to eq(1) - - headers_attendus = ImportExport::Questions::ImportExportDonnees::HEADERS_ATTENDUS[ - QuestionQcm::QUESTION_TYPE - ] - headers_attendus += %i[choix_1_intitule choix_1_nom_technique choix_1_type_choix - choix_1_audio_url choix_2_intitule choix_2_nom_technique - choix_2_type_choix choix_2_audio_url] - - expect(headers_xls).to eq headers_attendus - end - - it 'génére un fichier xls avec les détails de la question' do - ligne = worksheet.row(1) - expect(ligne[8]).to eq(question.type_qcm) - expect(ligne[9]).to eq(reponse.intitule) - expect(ligne[10]).to eq(reponse.nom_technique) - expect(ligne[11]).to eq(reponse.type_choix) - expect(ligne[12]).to eq(reponse.audio_url) - expect(ligne[13]).to eq(reponse2.intitule) - expect(ligne[14]).to eq(reponse2.nom_technique) - expect(ligne[15]).to eq(reponse2.type_choix) - expect(ligne[16]).to eq(reponse2.audio_url) - end - end - describe '#nom_du_fichier' do - let(:question) { create(:question_qcm) } - it 'genere le nom du fichier' do - date = DateTime.current.strftime('%Y%m%d') - nom_du_fichier_attendu = "#{date}-#{question.type}.xls" - - expect(response_service.nom_du_fichier(question.type)).to eq(nom_du_fichier_attendu) + Timecop.freeze(Date.new(2025, 2, 28)) do + nom_du_fichier_attendu = '20250228-QuestionQcm.xls' + expect(response_service.nom_du_fichier('QuestionQcm')).to eq(nom_du_fichier_attendu) + end end end From 6f79386678a38243400db361ab78e86fceeae150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Prod=27homme?= Date: Wed, 12 Feb 2025 17:18:11 +0100 Subject: [PATCH 7/7] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20Supprime=20log=20inuti?= =?UTF-8?q?le?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/import_export/questions/import_export_donnees.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/import_export/questions/import_export_donnees.rb b/app/models/import_export/questions/import_export_donnees.rb index a86507611..4b0010246 100644 --- a/app/models/import_export/questions/import_export_donnees.rb +++ b/app/models/import_export/questions/import_export_donnees.rb @@ -41,7 +41,6 @@ def importe_donnees(file) end def exporte_donnees - Rails.logger.debug EXPORTEURS[@type] export = EXPORTEURS[@type].new(@questions, HEADERS_COMMUN) { xls: export.to_xls,