Skip to content

Commit

Permalink
fix(test): update routing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
E-L-T committed Oct 25, 2023
1 parent e2ab1cd commit 3a5d3d0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 21 deletions.
52 changes: 52 additions & 0 deletions spec/components/conditions/routing_rules_component_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,18 @@
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
Expand Down
20 changes: 10 additions & 10 deletions spec/system/routing/rules_full_scenario_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
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
Expand Down Expand Up @@ -106,20 +106,20 @@
expect(page).to have_text("L’instructeur [email protected] 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')

Expand Down

0 comments on commit 3a5d3d0

Please sign in to comment.