From 60947f2b975142cfc5703782141cc5a26f72e422 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 6 Nov 2024 20:58:08 +0100 Subject: [PATCH] use it in filter_value_component --- .../column_filter_value_component.rb | 16 +-------- .../column_filter_value_component_spec.rb | 35 ++++++------------- 2 files changed, 11 insertions(+), 40 deletions(-) diff --git a/app/components/instructeurs/column_filter_value_component.rb b/app/components/instructeurs/column_filter_value_component.rb index 3a313b087..89713b985 100644 --- a/app/components/instructeurs/column_filter_value_component.rb +++ b/app/components/instructeurs/column_filter_value_component.rb @@ -12,7 +12,7 @@ class Instructeurs::ColumnFilterValueComponent < ApplicationComponent def call if column_type.in?([:enum, :enums, :boolean]) select_tag :filter, - options_for_select(options_for_select_of_column), + options_for_select(column.options_for_select), id: 'value', name: "filters[][filter]", class: 'fr-select', @@ -44,18 +44,4 @@ class Instructeurs::ColumnFilterValueComponent < ApplicationComponent 'text' end end - - def options_for_select_of_column - if column.groupe_instructeur? - current_instructeur.groupe_instructeurs.filter_map do - if _1.procedure_id == procedure_id - [_1.label, _1.id] - end - end - else - column.options_for_select - end - end - - def procedure_id = @column.h_id[:procedure_id] end diff --git a/spec/components/instructeurs/column_filter_value_component_spec.rb b/spec/components/instructeurs/column_filter_value_component_spec.rb index 11452b963..22df5dddc 100644 --- a/spec/components/instructeurs/column_filter_value_component_spec.rb +++ b/spec/components/instructeurs/column_filter_value_component_spec.rb @@ -2,34 +2,19 @@ describe Instructeurs::ColumnFilterValueComponent, type: :component do let(:component) { described_class.new(column:) } - let(:instructeur) { create(:instructeur) } - let(:procedure) { create(:procedure, instructeurs: [instructeur]) } - let(:procedure_id) { procedure.id } - before do - allow(component).to receive(:current_instructeur).and_return(instructeur) + before { render_inline(component) } + + describe 'the select case' do + let(:column) { double("Column", type: :enum, options_for_select:) } + let(:options_for_select) { ['option1', 'option2'] } + + it { expect(page).to have_select('filters[][filter]', options: options_for_select) } end - describe '.options_for_select_of_column' do - subject { component.send(:options_for_select_of_column) } + describe 'the input case' do + let(:column) { double("Column", type: :datetime) } - context "column is groupe_instructeur" do - let(:column) { double("Column", scope: nil, table: 'groupe_instructeur', h_id: { procedure_id: }) } - let!(:gi_2) { instructeur.groupe_instructeurs.create(label: 'gi2', procedure:) } - let!(:gi_3) { instructeur.groupe_instructeurs.create(label: 'gi3', procedure: create(:procedure)) } - - it { is_expected.to eq([['défaut', procedure.defaut_groupe_instructeur.id], ['gi2', gi_2.id]]) } - end - - context 'when column is dropdown' do - let(:types_de_champ_public) { [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }] } - let(:procedure) { create(:procedure, :published, types_de_champ_public:) } - let(:drop_down_stable_id) { procedure.active_revision.types_de_champ.first.stable_id } - let(:column) { procedure.find_column(label: 'Votre ville') } - - it 'find most recent tdc' do - is_expected.to eq(['Paris', 'Lyon', 'Marseille']) - end - end + it { expect(page).to have_selector('input[name="filters[][filter]"][type="date"]') } end end