a11y(select): cleanup select helpers in specs
This commit is contained in:
parent
968384952a
commit
cb66348916
7 changed files with 51 additions and 68 deletions
|
@ -103,41 +103,27 @@ module SystemHelpers
|
|||
end
|
||||
end
|
||||
|
||||
def select_combobox(champ, fill_with, value)
|
||||
fill_in champ, with: fill_with
|
||||
def select_combobox(libelle, fill_with, value, check: true)
|
||||
fill_in libelle, with: fill_with
|
||||
selector = "li[data-option-value=\"#{value}\"]"
|
||||
find(selector).click
|
||||
expect(page).to have_css(selector)
|
||||
expect(page).to have_css("[type=\"hidden\"][value=\"#{value}\"]")
|
||||
if check
|
||||
check_selected_value(libelle, with: value)
|
||||
end
|
||||
end
|
||||
|
||||
def select_multi_combobox(champ, fill_with, value)
|
||||
input = find("input[aria-label=\"#{champ}\"")
|
||||
input.click
|
||||
input.fill_in with: fill_with
|
||||
selector = "li[data-option-value=\"#{value}\"]"
|
||||
find(selector).click
|
||||
check_selected_value(champ, value)
|
||||
end
|
||||
|
||||
def check_selected_values(champ, values)
|
||||
combobox = find(:xpath, "//input[@aria-label=\"#{champ}\"]/ancestor::div[@data-react-class='ComboMultipleDropdownList']")
|
||||
hidden_field_id = JSON.parse(combobox["data-react-props"])["hiddenFieldId"]
|
||||
hidden_field = find("input[data-uuid=\"#{hidden_field_id}\"]")
|
||||
hidden_field_values = JSON.parse(hidden_field.value)
|
||||
expect(values.sort).to eq(hidden_field_values.sort)
|
||||
end
|
||||
|
||||
def check_selected_value(champ, value)
|
||||
combobox = find(:xpath, "//input[@aria-label=\"#{champ}\"]/ancestor::div[@data-react-class='ComboMultipleDropdownList']")
|
||||
hidden_field_id = JSON.parse(combobox["data-react-props"])["hiddenFieldId"]
|
||||
hidden_field = find("input[data-uuid=\"#{hidden_field_id}\"]")
|
||||
hidden_field_values = JSON.parse(hidden_field.value)
|
||||
expect(hidden_field_values).to include(value)
|
||||
end
|
||||
|
||||
def have_hidden_field(libelle, with:)
|
||||
have_css("##{form_id_for(libelle)}[value=\"#{with}\"]")
|
||||
def check_selected_value(libelle, with:)
|
||||
field = find_hidden_field_for(libelle)
|
||||
value = field.value.starts_with?('[') ? JSON.parse(field.value) : field.value
|
||||
if value.is_a?(Array)
|
||||
if with.is_a?(Array)
|
||||
expect(value.sort).to eq(with.sort)
|
||||
else
|
||||
expect(value).to include(with)
|
||||
end
|
||||
else
|
||||
expect(value).to eq(with)
|
||||
end
|
||||
end
|
||||
|
||||
def log_out
|
||||
|
@ -172,6 +158,18 @@ module SystemHelpers
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def find_hidden_field_for(libelle, name: 'value')
|
||||
find("#{form_group_id_for(libelle)} input[type=\"hidden\"][name$=\"[#{name}]\"]")
|
||||
end
|
||||
|
||||
def form_group_id_for(libelle)
|
||||
"#champ-#{form_id_for(libelle).gsub('-input', '')}"
|
||||
end
|
||||
|
||||
def form_id_for(libelle)
|
||||
find(:xpath, ".//label[contains(text()[normalize-space()], '#{libelle}')]")[:for]
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |config|
|
||||
|
|
|
@ -9,7 +9,7 @@ describe 'As an instructeur', js: true do
|
|||
visit admin_procedure_path(procedure)
|
||||
find('#groupe-instructeurs').click
|
||||
|
||||
find("input[aria-label='email instructeur'").send_keys(instructeur_email, :enter)
|
||||
fill_in 'Emails', with: instructeur_email
|
||||
perform_enqueued_jobs { click_on 'Affecter' }
|
||||
|
||||
expect(page).to have_text("Les instructeurs ont bien été affectés à la démarche")
|
||||
|
|
|
@ -165,8 +165,8 @@ describe 'Instructing a dossier:', js: true do
|
|||
|
||||
click_on 'Personnes impliquées'
|
||||
|
||||
select_multi_combobox('email instructeur', instructeur_2.email, instructeur_2.id)
|
||||
select_multi_combobox('email instructeur', instructeur_3.email, instructeur_3.id)
|
||||
select_combobox('Emails', instructeur_2.email, instructeur_2.id, check: false)
|
||||
select_combobox('Emails', instructeur_3.email, instructeur_3.id, check: false)
|
||||
|
||||
click_on 'Envoyer'
|
||||
|
||||
|
|
|
@ -125,13 +125,13 @@ describe "procedure filters" do
|
|||
|
||||
def add_column(column_name, column_path)
|
||||
click_on 'Personnaliser'
|
||||
select_multi_combobox('colonne', column_name, column_path)
|
||||
select_combobox('Colonne à afficher', column_name, column_path, check: false)
|
||||
click_button "Enregistrer"
|
||||
end
|
||||
|
||||
def remove_column(column_name)
|
||||
click_on 'Personnaliser'
|
||||
find(:xpath, ".//li[contains(text(), \"#{column_name}\")]/button", text: 'Désélectionner').click
|
||||
click_button column_name
|
||||
find("body").native.send_key("Escape")
|
||||
click_button "Enregistrer"
|
||||
end
|
||||
|
|
|
@ -30,14 +30,14 @@ describe 'The routing', js: true do
|
|||
expect(page).to have_field('Nom du groupe', with: 'littéraire')
|
||||
|
||||
# add victor to littéraire groupe
|
||||
find("input[aria-label='email instructeur'").send_keys('victor@inst.com', :enter)
|
||||
fill_in 'Emails', with: 'victor@inst.com'
|
||||
perform_enqueued_jobs { click_on 'Affecter' }
|
||||
expect(page).to have_text("L’instructeur victor@inst.com a été affecté au groupe « littéraire »")
|
||||
|
||||
victor = User.find_by(email: 'victor@inst.com').instructeur
|
||||
|
||||
# add superwoman to littéraire groupe
|
||||
find("input[aria-label='email instructeur'").send_keys('superwoman@inst.com', :enter)
|
||||
fill_in 'Emails', with: 'superwoman@inst.com'
|
||||
perform_enqueued_jobs { click_on 'Affecter' }
|
||||
expect(page).to have_text("L’instructeur superwoman@inst.com a été affecté au groupe « littéraire »")
|
||||
|
||||
|
@ -50,14 +50,14 @@ describe 'The routing', js: true do
|
|||
expect(page).to have_text('Le groupe d’instructeurs « scientifique » a été créé.')
|
||||
|
||||
# add marie to scientifique groupe
|
||||
find("input[aria-label='email instructeur'").send_keys('marie@inst.com', :enter)
|
||||
fill_in 'Emails', with: 'marie@inst.com'
|
||||
perform_enqueued_jobs { click_on 'Affecter' }
|
||||
expect(page).to have_text("L’instructeur marie@inst.com a été affecté")
|
||||
|
||||
marie = User.find_by(email: 'marie@inst.com').instructeur
|
||||
|
||||
# add superwoman to scientifique groupe
|
||||
find("input[aria-label='email instructeur'").send_keys('superwoman@inst.com', :enter)
|
||||
fill_in 'Emails', with: 'superwoman@inst.com'
|
||||
perform_enqueued_jobs { click_on 'Affecter' }
|
||||
expect(page).to have_text("L’instructeur superwoman@inst.com a été affecté")
|
||||
|
||||
|
@ -112,7 +112,7 @@ describe 'The routing', js: true do
|
|||
click_on litteraire_user.dossiers.first.id.to_s
|
||||
click_on 'Modifier mon dossier'
|
||||
|
||||
fill_in 'dossier_champs_attributes_0_value', with: 'some value'
|
||||
fill_in litteraire_user.dossiers.first.champs.first.libelle, with: 'some value'
|
||||
click_on 'Enregistrer les modifications du dossier'
|
||||
log_out
|
||||
|
||||
|
|
|
@ -28,13 +28,13 @@ describe 'The user' do
|
|||
check('val1')
|
||||
check('val3')
|
||||
select('bravo', from: form_id_for('simple_choice_drop_down_list_long'))
|
||||
select_multi_combobox('multiple_choice_drop_down_list_long', 'alp', 'alpha')
|
||||
select_multi_combobox('multiple_choice_drop_down_list_long', 'cha', 'charly')
|
||||
select_combobox('multiple_choice_drop_down_list_long', 'alp', 'alpha')
|
||||
select_combobox('multiple_choice_drop_down_list_long', 'cha', 'charly')
|
||||
|
||||
select_combobox('pays', 'aust', 'Australie')
|
||||
select_combobox('regions', 'Ma', 'Martinique')
|
||||
select_combobox('departements', 'Ai', '02 - Aisne')
|
||||
select_combobox('communes', 'Ai', '02 - Aisne')
|
||||
select_combobox('communes', 'Ai', '02 - Aisne', check: false)
|
||||
select_combobox('communes', 'Ambl', 'Ambléon (01300)')
|
||||
|
||||
check('engagement')
|
||||
|
@ -87,11 +87,11 @@ describe 'The user' do
|
|||
expect(page).to have_checked_field('val1')
|
||||
expect(page).to have_checked_field('val3')
|
||||
expect(page).to have_selected_value('simple_choice_drop_down_list_long', selected: 'bravo')
|
||||
check_selected_values('multiple_choice_drop_down_list_long', ['alpha', 'charly'])
|
||||
expect(page).to have_hidden_field('pays', with: 'Australie')
|
||||
expect(page).to have_hidden_field('regions', with: 'Martinique')
|
||||
expect(page).to have_hidden_field('departements', with: '02 - Aisne')
|
||||
expect(page).to have_hidden_field('communes', with: 'Ambléon (01300)')
|
||||
check_selected_value('multiple_choice_drop_down_list_long', with: ['alpha', 'charly'])
|
||||
check_selected_value('pays', with: 'Australie')
|
||||
check_selected_value('regions', with: 'Martinique')
|
||||
check_selected_value('departements', with: '02 - Aisne')
|
||||
check_selected_value('communes', with: 'Ambléon (01300)')
|
||||
expect(page).to have_checked_field('engagement')
|
||||
expect(page).to have_field('dossier_link', with: '123')
|
||||
expect(page).to have_text('file.pdf')
|
||||
|
@ -337,10 +337,6 @@ describe 'The user' do
|
|||
expect(page).to have_current_path(identite_dossier_path(user_dossier))
|
||||
end
|
||||
|
||||
def form_id_for(libelle)
|
||||
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:
|
||||
|
|
|
@ -27,16 +27,16 @@ describe 'linked dropdown lists' do
|
|||
fill_individual
|
||||
|
||||
# Select a primary value
|
||||
select('Primary 2', from: primary_id_for('linked dropdown'))
|
||||
select('Primary 2', from: 'linked dropdown')
|
||||
|
||||
# Secondary menu reflects chosen primary value
|
||||
expect(page).to have_select(secondary_id_for('linked dropdown'), options: ['', 'Secondary 2.1', 'Secondary 2.2', 'Secondary 2.3'])
|
||||
expect(page).to have_select("Valeur secondaire dépendant de la première", options: ['', 'Secondary 2.1', 'Secondary 2.2', 'Secondary 2.3'])
|
||||
|
||||
# Select another primary value
|
||||
select('Primary 1', from: primary_id_for('linked dropdown'))
|
||||
select('Primary 1', from: 'linked dropdown')
|
||||
|
||||
# Secondary menu gets updated
|
||||
expect(page).to have_select(secondary_id_for('linked dropdown'), options: ['', 'Secondary 1.1', 'Secondary 1.2'])
|
||||
expect(page).to have_select("Valeur secondaire dépendant de la première", options: ['', 'Secondary 1.1', 'Secondary 1.2'])
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -63,15 +63,4 @@ describe 'linked dropdown lists' do
|
|||
click_on 'Continuer'
|
||||
expect(page).to have_current_path(brouillon_dossier_path(user_dossier))
|
||||
end
|
||||
|
||||
def primary_id_for(libelle)
|
||||
find(:xpath, ".//label[contains(text()[normalize-space()], '#{libelle}')]")[:for]
|
||||
end
|
||||
|
||||
def secondary_id_for(libelle)
|
||||
primary_id = primary_id_for(libelle)
|
||||
find("\##{primary_id}")
|
||||
.ancestor('.editable-champ')
|
||||
.find("[data-secondary]")['id']
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue