From d49f6e703e162b041baf0a9dd679e0b6b30bae95 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Mon, 16 Mar 2020 17:42:49 +0100 Subject: [PATCH] fix tests for datetime --- spec/features/users/brouillon_spec.rb | 30 +++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/spec/features/users/brouillon_spec.rb b/spec/features/users/brouillon_spec.rb index 3acd1adc2..42bd5ec3c 100644 --- a/spec/features/users/brouillon_spec.rb +++ b/spec/features/users/brouillon_spec.rb @@ -19,7 +19,7 @@ feature 'The user' do fill_in('text', with: 'super texte') fill_in('textarea', with: 'super textarea') fill_in('date', with: '12-12-2012') - select_date_and_time(Time.zone.parse('06/01/1985 7h05'), form_id_for('datetime')) + select_date_and_time(Time.zone.parse('06/01/1985 7h05'), form_id_for_datetime('datetime')) fill_in('number', with: '42') check('checkbox') choose('Madame') @@ -74,7 +74,7 @@ feature 'The user' do expect(page).to have_field('text', with: 'super texte') expect(page).to have_field('textarea', with: 'super textarea') expect(page).to have_field('date', with: '2012-12-12') - check_date_and_time(Time.zone.parse('06/01/1985 7:05'), form_id_for('datetime')) + check_date_and_time(Time.zone.parse('06/01/1985 7:05'), form_id_for_datetime('datetime')) expect(page).to have_field('number', with: '42') expect(page).to have_checked_field('checkbox') expect(page).to have_checked_field('Madame') @@ -250,6 +250,32 @@ feature 'The user' do find(:xpath, ".//label[contains(text()[normalize-space()], '#{libelle}')]")[:for] end + def form_id_for_datetime(libelle) + # The HTML for datetime is a bit specific since it has 5 selects, below here is a sample HTML + # So, we want to find the partial id of a datetime (partial because there are 5 ids: + # dossier_champs_attributes_3_value_1i, 2i, ... 5i) ; we are interested in the 'dossier_champs_attributes_3_value' part + # which is then completed in select_date_and_time and check_date_and_time + # + # We find the H2, find the first select in the next .datetime div, then strip the last 3 characters + # + #

+ # libelle + #

+ #
+ # + # + # + #
+ e = find(:xpath, ".//h4[contains(text()[normalize-space()], '#{libelle}')]") + e.sibling('.datetime').first('select')[:id][0..-4] + end + def champ_value_for(libelle) champs = user_dossier.champs champs.find { |c| c.libelle == libelle }.value