amelioration(procedures#filtres): filtre par regions avec un enum sur la collection des regions normalisés
This commit is contained in:
parent
b0a757a89d
commit
a89f5d373f
5 changed files with 46 additions and 2 deletions
|
@ -54,6 +54,7 @@ class Champ < ApplicationRecord
|
|||
:block?,
|
||||
:dossier_link?,
|
||||
:departement?,
|
||||
:region?,
|
||||
:titre_identite?,
|
||||
:header_section?,
|
||||
:simple_drop_down_list?,
|
||||
|
|
|
@ -90,7 +90,7 @@ class ProcedurePresentation < ApplicationRecord
|
|||
|
||||
fields.concat procedure.types_de_champ_for_procedure_presentation
|
||||
.pluck(:type_champ, :libelle, :private, :stable_id)
|
||||
.map { |(type_champ, libelle, is_private, stable_id)| field_hash(is_private ? TYPE_DE_CHAMP_PRIVATE : TYPE_DE_CHAMP, stable_id.to_s, label: libelle, type: (type_champ == TypeDeChamp.type_champs.fetch(:departements) ? :enum : :text)) }
|
||||
.map { |(type_champ, libelle, is_private, stable_id)| field_hash(is_private ? TYPE_DE_CHAMP_PRIVATE : TYPE_DE_CHAMP, stable_id.to_s, label: libelle, type: (TypeDeChamp.options_for_select?(type_champ) ? :enum : :text)) }
|
||||
|
||||
fields
|
||||
end
|
||||
|
|
|
@ -373,6 +373,10 @@ class TypeDeChamp < ApplicationRecord
|
|||
type_champ == TypeDeChamp.type_champs.fetch(:departements)
|
||||
end
|
||||
|
||||
def region?
|
||||
type_champ == TypeDeChamp.type_champs.fetch(:regions)
|
||||
end
|
||||
|
||||
def mesri?
|
||||
type_champ == TypeDeChamp.type_champs.fetch(:mesri)
|
||||
end
|
||||
|
@ -409,9 +413,18 @@ class TypeDeChamp < ApplicationRecord
|
|||
self.drop_down_options = parse_drop_down_list_value(value)
|
||||
end
|
||||
|
||||
def self.options_for_select?(type_champs)
|
||||
[
|
||||
TypeDeChamp.type_champs.fetch(:departements),
|
||||
TypeDeChamp.type_champs.fetch(:regions)
|
||||
].include?(type_champs)
|
||||
end
|
||||
|
||||
def options_for_select
|
||||
if departement?
|
||||
APIGeoService.departements.map { ["#{_1[:code]} – #{_1[:name]}", _1[:name]] }
|
||||
elsif region?
|
||||
APIGeoService.regions.map { [_1[:name], _1[:name]] }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -206,6 +206,12 @@ FactoryBot.define do
|
|||
end
|
||||
end
|
||||
|
||||
trait :with_region do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
build(:type_de_champ_regions, procedure: procedure)
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_piece_justificative do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
build(:type_de_champ_piece_justificative, procedure: procedure)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
describe "procedure filters" do
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_departement, instructeurs: [instructeur]) }
|
||||
let(:procedure) { create(:procedure, :published, :with_type_de_champ, :with_departement, :with_region, instructeurs: [instructeur]) }
|
||||
let!(:type_de_champ) { procedure.active_revision.types_de_champ_public.first }
|
||||
let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction)) }
|
||||
let!(:champ) { Champ.find_by(type_de_champ_id: type_de_champ.id, dossier_id: new_unfollow_dossier.id) }
|
||||
|
@ -118,6 +118,30 @@ describe "procedure filters" do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'with a vcr cassette', vcr: { cassette_name: 'api_geo_regions' } do
|
||||
let(:memory_store) { ActiveSupport::Cache.lookup_store(:memory_store) }
|
||||
|
||||
before do
|
||||
allow(Rails).to receive(:cache).and_return(memory_store)
|
||||
Rails.cache.clear
|
||||
end
|
||||
|
||||
scenario "should be able to find by departements with custom enum lookup", js: true do
|
||||
region_champ = new_unfollow_dossier.champs.find(&:regions?)
|
||||
region_champ.update!(value: 'Bretagne', external_id: '53')
|
||||
region_champ.reload
|
||||
champ_select_value = "#{region_champ.external_id} – #{region_champ.value}"
|
||||
|
||||
click_on 'Sélectionner un filtre'
|
||||
select region_champ.libelle, from: "Colonne"
|
||||
find("select#value", visible: true)
|
||||
select champ_select_value, from: "Valeur"
|
||||
click_button "Ajouter le filtre"
|
||||
find("select#value", visible: false) # w8 for filter to be applied
|
||||
expect(page).to have_link(new_unfollow_dossier.id.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "should be able to add and remove two filters for the same field", js: true do
|
||||
add_filter(type_de_champ.libelle, champ.value)
|
||||
add_filter(type_de_champ.libelle, champ_2.value)
|
||||
|
|
Loading…
Reference in a new issue