Skip to content

Commit

Permalink
spec(dossier.eligibilite): add system spec
Browse files Browse the repository at this point in the history
  • Loading branch information
mfo committed May 24, 2024
1 parent 57821d3 commit 42a62cf
Showing 1 changed file with 118 additions and 0 deletions.
118 changes: 118 additions & 0 deletions spec/system/users/dossier_eligibilite_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
require 'system/users/dossier_shared_examples.rb'

describe 'Dossier éligibilité', js: true do
include Logic

let(:user) { create(:user) }
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
let(:dossier) { create(:dossier, procedure:, user:) }

let(:published_revision) { procedure.published_revision }
let(:first_tdc) { published_revision.types_de_champ.first }
let(:second_tdc) { published_revision.types_de_champ.last }
let(:eligibilite_message) { 'sry vous pouvez aps soumettre votre dossier' }
let(:eligibilite_params) { { eligibilite_enabled: true, eligibilite_message: } }

before do
published_revision.update(eligibilite_params.merge(eligibilite_rules:))
login_as user, scope: :user
end

context 'single condition' do
let(:types_de_champ_public) { [{ type: :yes_no }] }
let(:eligibilite_rules) { ds_eq(champ_value(first_tdc.stable_id), constant(true)) }

scenario 'can submit, can not submit, reload' do
visit brouillon_dossier_path(dossier)
# no error while dossier is empty
expect(page).to have_selector(:button, text: "Déposer le dossier", disabled: false)
expect(page).not_to have_content("Vous ne pouvez pas déposer votre dossier")

# when champs is not mandatory, i can submit, and an error guides me
click_on "Déposer le dossier"
expect(page).to have_content("doît être rempli pour determiner si votre dossier est éligible")

# raise error when dossier is filled with invalid condition
find("label", text: "Non").click
expect(page).to have_selector(:button, text: "Déposer le dossier", disabled: true)
expect(page).to have_content("Vous ne pouvez pas déposer votre dossier")

# reload page and see error because it was filled
visit brouillon_dossier_path(dossier)
expect(page).to have_selector(:button, text: "Déposer le dossier", disabled: true)
expect(page).to have_content("Vous ne pouvez pas déposer votre dossier")

# modal is closable, and we can change our dossier response to be eligible
within("#modal-eligibilite-rules-dialog") { click_on "Fermer" }
find("label", text: "Oui").click
expect(page).to have_selector(:button, text: "Déposer le dossier", disabled: false)

# it works, yay
click_on "Déposer le dossier"
wait_until { dossier.reload.en_construction? == true }
end
end

context 'or condition' do
let(:types_de_champ_public) { [{ type: :yes_no, libelle: 'l1' }, { type: :drop_down_list, libelle: 'l2', options: ['Paris', 'Marseille'] }] }
let(:eligibilite_rules) do
ds_or([
ds_eq(champ_value(first_tdc.stable_id), constant(true)),
ds_eq(champ_value(second_tdc.stable_id), constant('Paris'))
])
end

scenario 'can submit, can not submit, can edit, etc...' do
visit brouillon_dossier_path(dossier)
# no error while dossier is empty
expect(page).to have_selector(:button, text: "Déposer le dossier", disabled: false)
expect(page).not_to have_content("Vous ne pouvez pas déposer votre dossier")

# when champs is not mandatory, i can submit, and errors guides me to fill in my file
click_on "Déposer le dossier"
expect(page).to have_content("l1 doît être rempli pour determiner si votre dossier est éligible")
expect(page).to have_content("l2 doît être rempli pour determiner si votre dossier est éligible")

# only one condition is invalid, can submit dossier and error message is clear
within "#champ-#{first_tdc.stable_id}" do
find("label", text: "Non").click
end
expect(page).to have_selector(:button, text: "Déposer le dossier", disabled: false)
click_on "Déposer le dossier"
expect(page).to have_content("l2 doît être rempli pour determiner si votre dossier est éligible")

# only one condition is valid, I can submit the dossier
within "#champ-#{first_tdc.stable_id}" do
find("label", text: "Oui").click
end

# Now test dossier modification
click_on "Déposer le dossier"
click_on "Accéder à votre dossier"
click_on "Modifier le dossier"

# one condition is invalid, means i'm not blocked to send my file.
within "#champ-#{first_tdc.stable_id}" do
find("label", text: "Non").click
end
expect(page).to have_selector(:button, text: "Déposer les modifications", disabled: false)

# second condition is invalid, means i'm blocked to send my file
within "#champ-#{second_tdc.stable_id}" do
find("label", text: 'Marseille').click
end
expect(page).to have_selector(:button, text: "Déposer les modifications", disabled: true)
within("#modal-eligibilite-rules-dialog") { click_on "Fermer" }

# one of the or condiiton is valid
within "#champ-#{second_tdc.stable_id}" do
find("label", text: 'Paris').click
end
expect(page).to have_selector(:button, text: "Déposer les modifications", disabled: false)

# it works, yay
click_on "Déposer les modifications"
wait_until { dossier.reload.en_construction? == true }
end
end
end

0 comments on commit 42a62cf

Please sign in to comment.