fix(test): update routing tests
This commit is contained in:
parent
cd9cc65e99
commit
3e2e5a01f9
3 changed files with 65 additions and 21 deletions
52
spec/components/conditions/routing_rules_component_spec.rb
Normal file
52
spec/components/conditions/routing_rules_component_spec.rb
Normal file
|
@ -0,0 +1,52 @@
|
|||
describe Conditions::RoutingRulesComponent, type: :component do
|
||||
include Logic
|
||||
|
||||
describe 'render' do
|
||||
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :drop_down_list, libelle: 'Votre ville', options: ['Paris', 'Lyon', 'Marseille'] }, { type: :integer_number, libelle: 'Un champ nombre entier' }]) }
|
||||
let(:groupe_instructeur) { procedure.groupe_instructeurs.first }
|
||||
let(:drop_down_tdc) { procedure.draft_revision.types_de_champ.first }
|
||||
let(:integer_number_tdc) { procedure.draft_revision.types_de_champ.last }
|
||||
let(:routing_rule) { ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')) }
|
||||
|
||||
before do
|
||||
groupe_instructeur.update(routing_rule: routing_rule)
|
||||
render_inline(described_class.new(groupe_instructeur: groupe_instructeur))
|
||||
end
|
||||
|
||||
context 'with one row' do
|
||||
context 'when routing rule is valid' do
|
||||
it do
|
||||
expect(page).to have_text('Champ Cible')
|
||||
expect(page).not_to have_text('règle invalide')
|
||||
expect(page).to have_select('groupe_instructeur[condition_form][rows][][operator_name]', options: ["Est", "N’est pas"])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when routing rule is invalid' do
|
||||
let(:routing_rule) { ds_eq(champ_value(drop_down_tdc.stable_id), empty) }
|
||||
it { expect(page).to have_text('règle invalide') }
|
||||
end
|
||||
end
|
||||
|
||||
context 'with two rows' do
|
||||
context 'when routing rule is valid' do
|
||||
let(:routing_rule) { ds_and([ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')), ds_not_eq(champ_value(integer_number_tdc.stable_id), constant(33))]) }
|
||||
|
||||
it do
|
||||
expect(page).not_to have_text('règle invalide')
|
||||
expect(page).to have_selector('tbody > tr', count: 2)
|
||||
expect(page).to have_select("groupe_instructeur_condition_form_top_operator_name", selected: "Et", options: ['Et', 'Ou'])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when routing rule is invalid' do
|
||||
let(:routing_rule) { ds_or([ds_eq(champ_value(drop_down_tdc.stable_id), constant('Lyon')), ds_not_eq(champ_value(integer_number_tdc.stable_id), empty)]) }
|
||||
it do
|
||||
expect(page).to have_text('règle invalide')
|
||||
expect(page).to have_selector('tbody > tr', count: 2)
|
||||
expect(page).to have_select("groupe_instructeur_condition_form_top_operator_name", selected: "Ou", options: ['Et', 'Ou'])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -60,26 +60,18 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
context 'group without routing rule' do
|
||||
before { get :show, params: { procedure_id: procedure.id, id: gi_1_1.id } }
|
||||
|
||||
it do
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include('règle invalide')
|
||||
end
|
||||
end
|
||||
|
||||
context 'group with routing rule matching tdc' do
|
||||
let!(:drop_down_tdc) { create(:type_de_champ_drop_down_list, procedure: procedure, drop_down_options: options) }
|
||||
let(:options) { procedure.groupe_instructeurs.pluck(:label) }
|
||||
let(:options) { ['Premier choix', 'Deuxième choix', 'Troisième choix'] }
|
||||
|
||||
before do
|
||||
gi_1_1.update(routing_rule: ds_eq(champ_value(drop_down_tdc.stable_id), constant(gi_1_1.label)))
|
||||
gi_1_1.update(routing_rule: ds_eq(champ_value(drop_down_tdc.stable_id), constant('Deuxième choix')))
|
||||
get :show, params: { procedure_id: procedure.id, id: gi_1_1.id }
|
||||
end
|
||||
|
||||
it do
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(response.body).to include('Deuxième choix')
|
||||
expect(response.body).not_to include('règle invalide')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,14 +39,14 @@ describe 'The routing with rules', js: true, retry: 3 do
|
|||
expect(page).not_to have_text('à configurer')
|
||||
|
||||
click_on 'littéraire'
|
||||
expect(page).to have_select("targeted_champ", selected: "Spécialité")
|
||||
expect(page).to have_select("value", selected: "littéraire")
|
||||
expect(page).to have_select("groupe_instructeur[condition_form][rows][][targeted_champ]", selected: "Spécialité")
|
||||
expect(page).to have_select("groupe_instructeur[condition_form][rows][][value]", selected: "littéraire")
|
||||
|
||||
click_on '3 groupes'
|
||||
click_on 'scientifique'
|
||||
|
||||
expect(page).to have_select("targeted_champ", selected: "Spécialité")
|
||||
expect(page).to have_select("value", selected: "scientifique")
|
||||
expect(page).to have_select("groupe_instructeur[condition_form][rows][][targeted_champ]", selected: "Spécialité")
|
||||
expect(page).to have_select("groupe_instructeur[condition_form][rows][][value]", selected: "scientifique")
|
||||
end
|
||||
|
||||
scenario 'Routage avancé' do
|
||||
|
@ -106,20 +106,20 @@ describe 'The routing with rules', js: true, retry: 3 do
|
|||
expect(page).to have_text("L’instructeur alain@gouv.fr a été affecté")
|
||||
|
||||
# add routing rules
|
||||
within('.target') { select('Spécialité') }
|
||||
within('.value') { select('scientifique') }
|
||||
within('.target select') { select('Spécialité') }
|
||||
within('.value select') { select('scientifique') }
|
||||
|
||||
click_on '3 groupes'
|
||||
|
||||
click_on 'littéraire'
|
||||
|
||||
within('.target') { select('Spécialité') }
|
||||
within('.value') { select('scientifique') }
|
||||
within('.target select') { select('Spécialité') }
|
||||
within('.value select') { select('scientifique') }
|
||||
|
||||
expect(page).to have_text('règle déjà attribuée à scientifique')
|
||||
|
||||
within('.target') { select('Spécialité') }
|
||||
within('.value') { select('littéraire') }
|
||||
within('.target select') { select('Spécialité') }
|
||||
within('.value select') { select('littéraire') }
|
||||
|
||||
expect(page).not_to have_text('règle déjà attribuée à scientifique')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue