From 41ea39abb166d103710fdf6d03e3de1c5df7194b Mon Sep 17 00:00:00 2001 From: mfo Date: Sat, 20 Jul 2024 07:43:44 +0200 Subject: [PATCH] ProcedurePresentation.filterable_fields_options -> InstructeurFilterComponent.filterable_fields_options --- .../dossiers/instructeur_filter_component.rb | 10 +++++++- app/models/procedure_presentation.rb | 8 ------- .../instructeur_filter_component_spec.rb | 19 +++++++++++++++ spec/models/procedure_presentation_spec.rb | 24 ------------------- 4 files changed, 28 insertions(+), 33 deletions(-) diff --git a/app/components/dossiers/instructeur_filter_component.rb b/app/components/dossiers/instructeur_filter_component.rb index 6337b1bd5..66796b4da 100644 --- a/app/components/dossiers/instructeur_filter_component.rb +++ b/app/components/dossiers/instructeur_filter_component.rb @@ -27,7 +27,7 @@ class Dossiers::InstructeurFilterComponent < ApplicationComponent def filter_react_props { selected_key: facet.present? ? facet.id : '', - items: procedure_presentation.filterable_fields_options, + items: filterable_fields_options, name: :field, id: 'search-filter', 'aria-describedby': 'instructeur-filter-combo-label', @@ -36,6 +36,14 @@ class Dossiers::InstructeurFilterComponent < ApplicationComponent } end + def filterable_fields_options + procedure.facets.filter_map do |facet| + next if facet.filterable == false + + [facet.label, facet.id] + end + end + private def find_type_de_champ(column) diff --git a/app/models/procedure_presentation.rb b/app/models/procedure_presentation.rb index 5fc4095b0..cd6853a68 100644 --- a/app/models/procedure_presentation.rb +++ b/app/models/procedure_presentation.rb @@ -31,14 +31,6 @@ class ProcedurePresentation < ApplicationRecord ] end - def filterable_fields_options - procedure.facets.filter_map do |facet| - next if facet.filterable == false - - [facet.label, facet.id] - end - end - def displayed_fields_for_headers [ Facet.new(table: 'self', column: 'id', classname: 'number-col'), diff --git a/spec/components/dossiers/instructeur_filter_component_spec.rb b/spec/components/dossiers/instructeur_filter_component_spec.rb index 5cd6d9fe0..801433961 100644 --- a/spec/components/dossiers/instructeur_filter_component_spec.rb +++ b/spec/components/dossiers/instructeur_filter_component_spec.rb @@ -10,6 +10,25 @@ describe Dossiers::InstructeurFilterComponent, type: :component do allow(component).to receive(:current_instructeur).and_return(instructeur) end + describe ".filterable_fields_options" do + context 'filders' do + let(:facet) { nil } + let(:included_displayable_field) do + [ + Facet.new(label: 'email', table: 'user', column: 'email'), + Facet.new(label: "depose_since", table: "self", column: "depose_since", virtual: true) + ] + end + + before do + allow(Facet).to receive(:facets).and_return(included_displayable_field) + end + subject { component.filterable_fields_options } + + it { is_expected.to eq([["email", "user/email"], ["depose_since", "self/depose_since"]]) } + end + end + describe '.options_for_select_of_field' do subject { component.options_for_select_of_field } diff --git a/spec/models/procedure_presentation_spec.rb b/spec/models/procedure_presentation_spec.rb index 926d476f9..a778655b6 100644 --- a/spec/models/procedure_presentation_spec.rb +++ b/spec/models/procedure_presentation_spec.rb @@ -66,30 +66,6 @@ describe ProcedurePresentation do it { expect(subject.displayable_fields_for_select).to eq([[["email", "user/email"]], ["user/email"]]) } end - describe "#filterable_fields_options" do - subject { create(:procedure_presentation, assign_to: assign_to) } - - context 'filders' do - let(:included_displayable_field) do - [ - Facet.new(label: 'email', table: 'user', column: 'email'), - Facet.new(label: "depose_since", table: "self", column: "depose_since", virtual: true) - ] - end - - before do - allow(procedure).to receive(:facets).and_return(included_displayable_field) - end - - it { expect(subject.filterable_fields_options).to eq([["label1", "table1/column1"], ["depose_since", "self/depose_since"]]) } - end - context 'with rna' do - let(:procedure) { create(:procedure, :published, types_de_champ_public: [{ type: :rna, libelle: 'rna', stable_id: 1 }]) } - it { expect(subject.filterable_fields_options.map { _1[0] }).to include('rna – commune') } - it { expect(subject.filterable_fields_options.map { _1[1] }).to include('type_de_champ/1->data.commune') } - it { expect(subject.filterable_fields_options).to eq([["email", "user/email"], ["depose_since", "self/depose_since"]]) } - end - end describe '#sorted_ids' do let(:instructeur) { create(:instructeur) }