Merge pull request #7659 from betagouv/fix-random-tests
Fix random tests errors
This commit is contained in:
commit
21637da8ab
5 changed files with 57 additions and 39 deletions
|
@ -138,8 +138,9 @@ GEM
|
||||||
browser (5.3.1)
|
browser (5.3.1)
|
||||||
builder (3.2.4)
|
builder (3.2.4)
|
||||||
byebug (11.1.3)
|
byebug (11.1.3)
|
||||||
capybara (3.35.3)
|
capybara (3.37.1)
|
||||||
addressable
|
addressable
|
||||||
|
matrix
|
||||||
mini_mime (>= 0.1.3)
|
mini_mime (>= 0.1.3)
|
||||||
nokogiri (~> 1.8)
|
nokogiri (~> 1.8)
|
||||||
rack (>= 1.6.0)
|
rack (>= 1.6.0)
|
||||||
|
@ -149,7 +150,7 @@ GEM
|
||||||
capybara-email (3.0.2)
|
capybara-email (3.0.2)
|
||||||
capybara (>= 2.4, < 4.0)
|
capybara (>= 2.4, < 4.0)
|
||||||
mail
|
mail
|
||||||
capybara-screenshot (1.0.25)
|
capybara-screenshot (1.0.26)
|
||||||
capybara (>= 1.0, < 4)
|
capybara (>= 1.0, < 4)
|
||||||
launchy
|
launchy
|
||||||
case_transform (0.2)
|
case_transform (0.2)
|
||||||
|
@ -450,7 +451,7 @@ GEM
|
||||||
net-protocol
|
net-protocol
|
||||||
netrc (0.11.0)
|
netrc (0.11.0)
|
||||||
nio4r (2.5.8)
|
nio4r (2.5.8)
|
||||||
nokogiri (1.13.7)
|
nokogiri (1.13.8)
|
||||||
mini_portile2 (~> 2.8.0)
|
mini_portile2 (~> 2.8.0)
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
open4 (1.3.4)
|
open4 (1.3.4)
|
||||||
|
@ -496,7 +497,7 @@ GEM
|
||||||
pry (~> 0.13.0)
|
pry (~> 0.13.0)
|
||||||
pry-rails (0.3.9)
|
pry-rails (0.3.9)
|
||||||
pry (>= 0.10.4)
|
pry (>= 0.10.4)
|
||||||
public_suffix (4.0.6)
|
public_suffix (4.0.7)
|
||||||
puma (5.6.4)
|
puma (5.6.4)
|
||||||
nio4r (~> 2.0)
|
nio4r (~> 2.0)
|
||||||
pundit (2.1.0)
|
pundit (2.1.0)
|
||||||
|
|
|
@ -18,7 +18,7 @@ class ProcedureRevisionTypeDeChamp < ApplicationRecord
|
||||||
has_many :revision_types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'ProcedureRevisionTypeDeChamp', inverse_of: :parent, dependent: :destroy
|
has_many :revision_types_de_champ, -> { ordered }, foreign_key: :parent_id, class_name: 'ProcedureRevisionTypeDeChamp', inverse_of: :parent, dependent: :destroy
|
||||||
has_one :procedure, through: :revision
|
has_one :procedure, through: :revision
|
||||||
scope :root, -> { where(parent: nil) }
|
scope :root, -> { where(parent: nil) }
|
||||||
scope :ordered, -> { order(:position) }
|
scope :ordered, -> { order(:position, :id) }
|
||||||
scope :revision_ordered, -> { order(:revision_id) }
|
scope :revision_ordered, -> { order(:revision_id) }
|
||||||
scope :public_only, -> { joins(:type_de_champ).where(types_de_champ: { private: false }) }
|
scope :public_only, -> { joins(:type_de_champ).where(types_de_champ: { private: false }) }
|
||||||
scope :private_only, -> { joins(:type_de_champ).where(types_de_champ: { private: true }) }
|
scope :private_only, -> { joins(:type_de_champ).where(types_de_champ: { private: true }) }
|
||||||
|
|
|
@ -105,7 +105,7 @@ module SystemHelpers
|
||||||
|
|
||||||
def select_combobox(libelle, fill_with, value, check: true)
|
def select_combobox(libelle, fill_with, value, check: true)
|
||||||
fill_in libelle, with: fill_with
|
fill_in libelle, with: fill_with
|
||||||
find('li[role="option"]', text: value).click
|
find('li[role="option"]', text: value, wait: 5).click
|
||||||
if check
|
if check
|
||||||
check_selected_value(libelle, with: value)
|
check_selected_value(libelle, with: value)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
require 'webmock/rspec'
|
require 'webmock/rspec'
|
||||||
|
|
||||||
WebMock.disable_net_connect!(allow_localhost: true)
|
WebMock.disable_net_connect!(allow_localhost: true, net_http_connect_on_start: true)
|
||||||
|
|
|
@ -4,6 +4,7 @@ describe 'The user' do
|
||||||
|
|
||||||
let!(:procedure) { create(:procedure, :published, :for_individual, :with_all_champs_mandatory) }
|
let!(:procedure) { create(:procedure, :published, :for_individual, :with_all_champs_mandatory) }
|
||||||
let(:user_dossier) { user.dossiers.first }
|
let(:user_dossier) { user.dossiers.first }
|
||||||
|
let!(:dossier_to_link) { create(:dossier) }
|
||||||
|
|
||||||
scenario 'fill a dossier', js: true do
|
scenario 'fill a dossier', js: true do
|
||||||
log_in(user, procedure)
|
log_in(user, procedure)
|
||||||
|
@ -39,15 +40,22 @@ describe 'The user' do
|
||||||
select_combobox('communes', 'Ambl', 'Ambléon (01300)')
|
select_combobox('communes', 'Ambl', 'Ambléon (01300)')
|
||||||
|
|
||||||
check('engagement')
|
check('engagement')
|
||||||
fill_in('dossier_link', with: '123')
|
fill_in('dossier_link', with: dossier_to_link.id)
|
||||||
find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf')
|
find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf')
|
||||||
|
|
||||||
|
expect(page).to have_css('span', text: 'Votre brouillon est automatiquement enregistré', visible: true)
|
||||||
blur
|
blur
|
||||||
sleep(0.7)
|
|
||||||
expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true)
|
expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true)
|
||||||
|
|
||||||
# check data on the dossier
|
# check data on the dossier from db
|
||||||
expect(user_dossier.brouillon?).to be true
|
# Sometimes, `user_dossier.champs` are not yet all updated with the new values
|
||||||
|
# when we first load `user_dossier`, causing random errors.
|
||||||
|
# Strategy is to retry & reload them if necessary for a few seconds,
|
||||||
|
# and raise expectation error instead of timeout error.
|
||||||
|
last_expection_error = nil
|
||||||
|
begin
|
||||||
|
Timeout.timeout(Capybara.default_max_wait_time) do
|
||||||
|
expect(user_dossier).to be_brouillon
|
||||||
expect(champ_value_for('text')).to eq('super texte')
|
expect(champ_value_for('text')).to eq('super texte')
|
||||||
expect(champ_value_for('textarea')).to eq('super textarea')
|
expect(champ_value_for('textarea')).to eq('super textarea')
|
||||||
expect(champ_value_for('date')).to eq('2012-12-12')
|
expect(champ_value_for('date')).to eq('2012-12-12')
|
||||||
|
@ -69,8 +77,17 @@ describe 'The user' do
|
||||||
expect(champ_value_for('departements')).to eq('02 - Aisne')
|
expect(champ_value_for('departements')).to eq('02 - Aisne')
|
||||||
expect(champ_value_for('communes')).to eq('Ambléon (01300)')
|
expect(champ_value_for('communes')).to eq('Ambléon (01300)')
|
||||||
expect(champ_value_for('engagement')).to eq('on')
|
expect(champ_value_for('engagement')).to eq('on')
|
||||||
expect(champ_value_for('dossier_link')).to eq('123')
|
expect(champ_value_for('dossier_link')).to eq(dossier_to_link.id.to_s)
|
||||||
expect(champ_value_for('piece_justificative')).to be_nil # antivirus hasn't approved the file yet
|
expect(champ_value_for('piece_justificative')).to be_nil # antivirus hasn't approved the file yet
|
||||||
|
rescue RSpec::Expectations::ExpectationNotMetError => e
|
||||||
|
Rails.logger.debug "Error #{e.message.tr("\n", " ")}, will retry"
|
||||||
|
last_expection_error = e
|
||||||
|
sleep(0.1)
|
||||||
|
retry
|
||||||
|
end
|
||||||
|
rescue Timeout::Error => e
|
||||||
|
raise last_expection_error || e
|
||||||
|
end
|
||||||
|
|
||||||
## check data on the gui
|
## check data on the gui
|
||||||
|
|
||||||
|
@ -94,7 +111,7 @@ describe 'The user' do
|
||||||
check_selected_value('departements', with: '02 - Aisne')
|
check_selected_value('departements', with: '02 - Aisne')
|
||||||
check_selected_value('communes', with: 'Ambléon (01300)')
|
check_selected_value('communes', with: 'Ambléon (01300)')
|
||||||
expect(page).to have_checked_field('engagement')
|
expect(page).to have_checked_field('engagement')
|
||||||
expect(page).to have_field('dossier_link', with: '123')
|
expect(page).to have_field('dossier_link', with: dossier_to_link.id.to_s)
|
||||||
expect(page).to have_text('file.pdf')
|
expect(page).to have_text('file.pdf')
|
||||||
expect(page).to have_text('analyse antivirus en cours')
|
expect(page).to have_text('analyse antivirus en cours')
|
||||||
end
|
end
|
||||||
|
@ -178,13 +195,13 @@ describe 'The user' do
|
||||||
|
|
||||||
expect(page).to have_css('.card-title', text: 'Votre dossier va expirer', visible: true)
|
expect(page).to have_css('.card-title', text: 'Votre dossier va expirer', visible: true)
|
||||||
find('#test-user-repousser-expiration').click
|
find('#test-user-repousser-expiration').click
|
||||||
expect(page).not_to have_selector('#test-user-repousser-expiration')
|
expect(page).to have_no_selector('#test-user-repousser-expiration')
|
||||||
|
|
||||||
Timecop.freeze(simple_procedure.duree_conservation_dossiers_dans_ds.month.from_now) do
|
Timecop.freeze(simple_procedure.duree_conservation_dossiers_dans_ds.month.from_now) do
|
||||||
visit brouillon_dossier_path(user_old_dossier)
|
visit brouillon_dossier_path(user_old_dossier)
|
||||||
expect(page).to have_css('.card-title', text: 'Votre dossier va expirer', visible: true)
|
expect(page).to have_css('.card-title', text: 'Votre dossier va expirer', visible: true)
|
||||||
find('#test-user-repousser-expiration').click
|
find('#test-user-repousser-expiration').click
|
||||||
expect(page).not_to have_selector('#test-user-repousser-expiration')
|
expect(page).to have_no_selector('#test-user-repousser-expiration')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -341,7 +358,7 @@ describe 'The user' do
|
||||||
log_in(user, simple_procedure)
|
log_in(user, simple_procedure)
|
||||||
fill_individual
|
fill_individual
|
||||||
|
|
||||||
expect(page).not_to have_button('Enregistrer le brouillon')
|
expect(page).to have_no_button('Enregistrer le brouillon')
|
||||||
expect(page).to have_content('Votre brouillon est automatiquement enregistré')
|
expect(page).to have_content('Votre brouillon est automatiquement enregistré')
|
||||||
|
|
||||||
fill_in('texte obligatoire', with: 'a valid user input')
|
fill_in('texte obligatoire', with: 'a valid user input')
|
||||||
|
@ -434,7 +451,7 @@ describe 'The user' do
|
||||||
end
|
end
|
||||||
|
|
||||||
def champ_value_for(libelle)
|
def champ_value_for(libelle)
|
||||||
champs = user_dossier.champs
|
champs = user_dossier.reload.champs
|
||||||
champs.find { |c| c.libelle == libelle }.value
|
champs.find { |c| c.libelle == libelle }.value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue