add groupes_search_component

This commit is contained in:
simon lehericey 2023-05-09 11:15:02 +02:00 committed by LeSim
parent 171a6b35fb
commit 142ac9173d
4 changed files with 42 additions and 7 deletions

View file

@ -0,0 +1,5 @@
class Procedure::GroupesSearchComponent < ApplicationComponent
def initialize(procedure:, query:, to_configure_count:)
@procedure, @query, @to_configure_count = procedure, query, to_configure_count
end
end

View file

@ -0,0 +1,9 @@
= form_for admin_procedure_groupe_instructeurs_path(@procedure),
method: :get do
#header-search.fr-search-bar.fr-mb-2w{ role: "search" }
= label_tag :q, 'Rechercher par nom', class: 'fr-label'
= text_field_tag :q, @query, class: 'fr-input', type: 'search', autocomplete: 'off', placeholder: 'Rechercher par nom'
%button.fr-btn{ title: "Rechercher" } Rechercher
- if @to_configure_count > 0
%span #{ @to_configure_count } à configurer

View file

@ -291,8 +291,17 @@ module Administrateurs
end
def paginated_groupe_instructeurs
groupes = if params[:q].present?
query = ActiveRecord::Base.sanitize_sql_like(params[:q])
procedure
.groupe_instructeurs
.where('unaccent(label) ILIKE unaccent(?)', "%#{query}%")
else
procedure.groupe_instructeurs
end
groupes
.page(params[:page])
.per(ITEMS_PER_PAGE)
end

View file

@ -13,13 +13,25 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
describe '#index' do
context 'of a procedure I own' do
before { get :index, params: { procedure_id: procedure.id } }
before { get :index, params: }
context 'when a procedure has multiple groups' do
it { expect(response).to have_http_status(:ok) }
it { expect(response.body).to include(gi_1_1.label) }
it { expect(response.body).to include(gi_1_2.label) }
it { expect(response.body).not_to include(gi_2_2.label) }
let(:params) { { procedure_id: procedure.id } }
it do
expect(response).to have_http_status(:ok)
expect(response.body).to include(gi_1_1.label)
expect(response.body).to include(gi_1_2.label)
expect(response.body).not_to include(gi_2_2.label)
end
context 'when there is a search' do
let(:params) { { procedure_id: procedure.id, q: '2' } }
it do
expect(assigns(:groupes_instructeurs)).to match_array([gi_1_2])
end
end
end
end
end