use it in filter_value_component

This commit is contained in:
simon lehericey 2024-11-06 20:58:08 +01:00
parent 1277500069
commit 60947f2b97
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 11 additions and 40 deletions

View file

@ -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

View file

@ -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