Update specs

This commit is contained in:
Paul Chavard 2020-10-07 17:44:21 +02:00
parent 8a2f079acb
commit 653270d02f
2 changed files with 18 additions and 15 deletions

View file

@ -8,6 +8,6 @@ class APIGeoTestController < ActionController::Base
end
def communes
render json: [{ nom: 'Ambléon' }]
render json: [{ nom: 'Ambléon', code: '01006', codesPostaux: ['01300'] }]
end
end

View file

@ -5,7 +5,7 @@ feature 'The user' do
let!(:procedure) { create(:procedure, :published, :for_individual, :with_all_champs_mandatory) }
let(:user_dossier) { user.dossiers.first }
scenario 'fill a dossier', js: true, vcr: { cassette_name: 'api_geo_departements_regions_et_communes' } do
scenario 'fill a dossier', js: true do
log_in(user, procedure)
fill_individual
@ -30,13 +30,10 @@ feature 'The user' do
select('AUSTRALIE', from: 'pays')
select_champ_geo('regions', 'Ma', 'Martinique')
select('Martinique', from: 'regions')
select_champ_geo('departements', 'Ai', '02 - Aisne')
select('02 - Aisne', from: 'departements')
select_champ_geo('communes', 'Am', 'Ambléon')
select('Ambléon', from: 'communes')
select_champ_geo('communes', 'Ambl', 'Ambléon (01300)')
check('engagement')
fill_in('dossier_link', with: '123')
@ -64,7 +61,7 @@ feature 'The user' do
expect(champ_value_for('pays')).to eq('AUSTRALIE')
expect(champ_value_for('regions')).to eq('Martinique')
expect(champ_value_for('departements')).to eq('02 - Aisne')
expect(champ_value_for('communes')).to eq('Ambléon')
expect(champ_value_for('communes')).to eq('Ambléon (01300)')
expect(champ_value_for('engagement')).to eq('on')
expect(champ_value_for('dossier_link')).to eq('123')
expect(champ_value_for('piece_justificative')).to be_nil # antivirus hasn't approved the file yet
@ -87,9 +84,9 @@ feature 'The user' do
expect(page).to have_selected_value('simple_choice_drop_down_list_long', selected: 'bravo')
expect(page).to have_selected_value('multiple_choice_drop_down_list_long', selected: ['alpha', 'charly'])
expect(page).to have_selected_value('pays', selected: 'AUSTRALIE')
expect(page).to have_selected_value('regions', selected: 'Martinique')
expect(page).to have_selected_value('departements', selected: '02 - Aisne')
expect(page).to have_selected_value('communes', selected: 'Ambléon')
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)')
expect(page).to have_checked_field('engagement')
expect(page).to have_field('dossier_link', with: '123')
expect(page).to have_text('file.pdf')
@ -321,6 +318,10 @@ feature 'The user' do
e.sibling('.datetime').first('select')[:id][0..-4]
end
def have_hidden_field(libelle, with:)
have_css("##{form_id_for(libelle)}[value=\"#{with}\"]")
end
def champ_value_for(libelle)
champs = user_dossier.champs
champs.find { |c| c.libelle == libelle }.value
@ -351,10 +352,12 @@ feature 'The user' do
end
def select_champ_geo(champ, fill_with, value)
find(".editable-champ-#{champ} .select2-container").click
id = find('.select2-container--open [role=listbox]')[:id]
find("[aria-controls=#{id}]").fill_in with: fill_with
expect(page).to have_content(value)
find('li', text: value).click
input = find("input[aria-label=#{champ}")
input.click
input.fill_in with: fill_with
selector = "li[data-option-value=\"#{value}\"]"
find(selector).click
expect(page).to have_css(selector)
expect(page).to have_hidden_field(champ, with: value)
end
end