Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ On a démarche's fiche, under `Contexte` and `Cadre juridique`, the block `Solut
- `recos-fenetre-modifier` `Modifier <solution>` → window, `Enregistrer` → window closed, card updated, draft on a published démarche, focus back on `Modifier`.
- `recos-fenetre-erreur` a refused save reopens the window, `Choisissez une solution` under `Solution`.
- `recos-ajouter` `Ajouter une solution recommandée` → the same window, empty; the new card `Ajoutée au brouillon`.
- `recos-choix` the window's `Solution` lists only the API, the jeux de données and the solutions whose types include « API »; `Modifier` keeps the card's own solution selected even outside that filter.
- `recos-changer-l-ordre` `Changer l’ordre` shows the handles; a dragged card saves its position, the mode stays open; a refused neighbour stops the whole move (`Recommandation non déplacée : …`, request spec only).
- `recos-donnees-utiles` a card's `Ajouter une donnée utile à <solution>` → its window; a line saves alone, the window stays open, the card's list follows; the blank line offers only the APIs of that solution not yet recommended.
- `recos-integrations` a card's `Ajouter une intégration à <solution>` → that solution's intégrations only; `Enregistrer` → the card lists the new one, in the draft.
Expand All @@ -26,7 +27,8 @@ Preconditions: logged in; the drive mutates then puts back every recommandation

- **Cards.** `Solutions recommandées (<n>)` and the number of données utiles lines match the base read through the drafts; first card `Position <n>`.
- **Modify.** `Modifier <solution>` of the first card, `Position` 77, `Enregistrer` → no open window, card `Position 77`, `brouillon enregistré` in `#message-recommandations`, focus on `Modifier <solution>`, base ordre unchanged, 77 in the draft.
- **Error.** `Ajouter une solution recommandée`, `Enregistrer` with no solution → the window open again, `Choisissez une solution` under `Solution`.
- **Choices.** `Ajouter une solution recommandée`: the `Solution` options are exactly the solutions of category API or Jeu de données, or whose `types_solution` contains `API`, by name; none of the others (logiciels métier, briques without « API »). The first card's `Modifier` window has its own solution selected.
- **Error.** Same window, `Enregistrer` with no solution → the window open again, `Choisissez une solution` under `Solution`.
- **Add.** Same window: the solution, `Enregistrer` → a new card `Ajoutée au brouillon`, count +1, base `visible` false.
- **Order.** The hint `Glissez une carte par sa poignée…` hidden; `Changer l’ordre` (`aria-expanded` true) shows it and the handles; drag the second card's handle onto the first card → `déplacée en position 1`, the card first in the grid and in base (draft order), the mode still open (handles shown) for the next drag.
- **Données utiles.** The card to complete: `Ajouter une donnée utile à <solution>` opens its own window; first line `Position` 55, its `Enregistrer` → message naming that line's solution in the window (and none behind it), window still open, focus on that line's form; the blank line's `Solution` offers exactly the APIs of the solution not yet recommended, the first one `Ajouter` → message naming it; `Fermer`: the card lists the line with `55` and the new one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,26 @@ def modifier(page, ctx)
Verify.evidence(DOSSIER, page, 'modifiee', "message=#{page.find('#message-recommandations').text} focus=#{focus} ordre_en_base=#{base['ordre']} brouillon=#{base['brouillon']['ordre']}")
end

def libelles_proposables = Solution.where(categorie: %w[api base_de_donnees]).or(Solution.where("'API' = ANY(types_solution)")).map { it.libelle_admin.squish }
def options(dialog) = dialog.all('select[name="recommandation[solution_id]"] option').map(&:text).compact_blank

def choix(page, ctx)
dialog = Verify.fenetre(page, "Modifier #{ctx[:carte].solution.libelle_admin}")
choisie = dialog.find('select[name="recommandation[solution_id]"] option[selected]').text
dialog.click_button 'Fermer'
page.assert_no_selector 'dialog[open]'
raise "solution choisie #{choisie}" unless choisie == ctx[:carte].solution.libelle_admin.squish

proposees = options(Verify.fenetre(page, 'Ajouter une solution recommandée'))
attendues, hors_filtre = lu { [libelles_proposables, Solution.count - libelles_proposables.size] }
raise "options en trop #{proposees - attendues}, manquantes #{attendues - proposees}" unless proposees.sort == attendues.sort && proposees.size == attendues.size
raise 'aucune solution hors filtre en base : le filtre n’est pas éprouvé' unless hors_filtre.positive?

Verify.evidence(DOSSIER, page, 'choix', "proposees=#{proposees.size} hors_filtre_en_base=#{hors_filtre} choisie_a_la_modification=#{choisie}")
end

def erreur(page)
Verify.fenetre(page, 'Ajouter une solution recommandée').click_button 'Enregistrer'
page.find('dialog[open]').click_button 'Enregistrer'
erreur = page.find('dialog[open] .fr-message--error', text: 'Choisissez une solution')
Verify.evidence(DOSSIER, page, 'erreur', "fenetre=#{page.find('dialog[open] h2').text} erreur=#{erreur.text}")
end
Expand Down Expand Up @@ -191,6 +209,7 @@ def remettre(ctx)
Verify.login(page)
Verify.check('Cards') { cartes(page, ctx) }
Verify.check('Modify') { modifier(page, ctx) }
Verify.check('Choices') { choix(page, ctx) }
Verify.check('Error') { erreur(page) }
Verify.check('Add') { ajouter(page, ctx) }
Verify.check('Order') { changer_l_ordre(page, ctx) }
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def pagination(liste, filtres)
paginate liste, params: (request.query_parameters.keys - gardes).index_with(nil)
end

def choix_de_solutions = @choix_de_solutions ||= Solution.par_libelle_admin.map { |solution| [solution.libelle_admin, solution.id] }
def choix_de_solutions = @choix_de_solutions ||= Solution.choix_admin

def options_traduites(modele, enum)
modele.defined_enums.fetch(enum.to_s).keys.map { |cle| [modele.human_attribute_name("#{enum}.#{cle}"), cle] }
Expand Down
1 change: 1 addition & 0 deletions app/models/recommandation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Recommandation < ApplicationRecord
scope :en_brouillon, -> { where.not(brouillon: nil).where(visible: true).or(a_publier_avec_la_demarche) }
scope :par_niveau_et_ordre, -> { order(:niveau, :ordre, :id) }
def libelle = "#{demarche&.nom} → #{solution&.libelle_admin}"
def solutions_proposables = Solution.recommandables(solution_id)

def self.sur_la_fiche = includes(:solution).map(&:appliquer_brouillon).sort_by { [it.ordre ? 0 : 1, it.ordre.to_i, it.id] }
def rangees = demarche.recommandations.sur_la_fiche.select { it.niveau == niveau }
Expand Down
2 changes: 2 additions & 0 deletions app/models/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def champ_masque?(champ)
end

scope :par_libelle_admin, -> { order(:nom, :categorie) }
scope :recommandables, ->(deja) { where(categorie: HORS_FICHES).or(where("'API' = ANY(types_solution)")).or(where(id: deja)) }
def self.choix_admin = par_libelle_admin.map { [it.libelle_admin, it.id] }
def libelle_admin = categorie ? "#{nom} (#{self.class.human_attribute_name("categorie.#{categorie}")})" : nom

def privee? = fiche? && organisations.none?(&:publique?)
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/recommandations/_fenetre.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= form_with model: [:admin, recommandation], id: formulaire, namespace: id, html: { novalidate: true }, data: { enregistre_sur_place: true } do |f| %>
<%= hidden_field_tag :ligne, 1, id: nil %>
<%= f.hidden_field :demarche_id, id: nil if recommandation.new_record? %>
<%= f.dsfr_select :solution_id, choix_de_solutions %>
<%= f.dsfr_select :solution_id, recommandation.solutions_proposables.choix_admin %>
<%= f.dsfr_select :niveau, options_traduites(Recommandation, :niveau) %>
<%= f.dsfr_number_field :ordre %>
<%= f.dsfr_text_area :description %>
Expand Down
21 changes: 21 additions & 0 deletions spec/requests/admin/crud_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,27 @@ def choisi(dans, champ) = dans.at_css("[name=\"recommandation[#{champ}]\"]").the
.to eq(['Ajouter une solution recommandée', 'Solution recommandée', nil, aides.id.to_s])
end

it 'ne propose à recommander que des API, des jeux de données et des solutions de type API' do
Solution.create!(nom: 'API QF', categorie: 'api')
Solution.create!(nom: 'Base Sirene', categorie: 'base_de_donnees')
Solution.create!(nom: 'Bouquet API Entreprise', categorie: 'brique_logicielle', types_solution: ['Portail agent', 'API'])
Solution.create!(nom: 'Brique Formulaire', categorie: 'brique_logicielle', types_solution: ['Formulaire en ligne'])
Solution.create!(nom: 'Logiciel Aides', categorie: 'logiciel_metier_cle_en_main')
fiche

expect(page.at_css('dialog#fenetre-new_recommandation select[name="recommandation[solution_id]"]').css('option').map(&:text).compact_blank)
.to eq(['API QF (API)', 'Base Sirene (Jeu de données)', 'Bouquet API Entreprise (Brique technique)'])
end

it 'garde à la modification la solution déjà recommandée, même hors des API et jeux de données' do
logiciel = Solution.create!(nom: 'Logiciel Aides', categorie: 'logiciel_metier_cle_en_main', organisations: [Organisation.create!(nom: 'DINUM', public_ou_prive: 'Public')])
recommandation = Recommandation.create!(demarche: aides, solution: logiciel, niveau: :niveau_2)
fiche

expect(choisi(fenetre(page, recommandation), :solution_id)).to eq('Logiciel Aides (Logiciel métier)')
expect(page.at_css('dialog#fenetre-new_recommandation').css('option').map(&:text)).not_to include('Logiciel Aides (Logiciel métier)')
end

it 'enregistre la fenêtre sur place : la carte à jour, en brouillon tant que la démarche publiée n’est pas publiée à nouveau' do
recommandation = Recommandation.create!(demarche: aides, solution: solution('Mes Aides'), niveau: :niveau_2, ordre: 1, visible: true)
patch "/admin/recommandations/#{recommandation.id}", params: { ligne: 1, recommandation: { ordre: '3', description: 'Aide du mois' } }
Expand Down
Loading