Improve feature tests for procedure cloning and creation

This commit is contained in:
Nicolas Bouilleaud 2019-08-14 18:05:01 +02:00
parent 543f9894c1
commit 78da268ded
2 changed files with 33 additions and 12 deletions

View file

@ -7,23 +7,39 @@ feature 'As an administrateur I wanna clone a procedure', js: true do
let(:administrateur) { create(:administrateur) } let(:administrateur) { create(:administrateur) }
before do before do
create :procedure, :with_service,
aasm_state: :publiee, published_at: Time.zone.now,
administrateurs: [administrateur],
libelle: 'libellé de la procédure',
path: 'libelle-de-la-procedure'
login_as administrateur.user, scope: :user login_as administrateur.user, scope: :user
visit new_from_existing_admin_procedures_path
end end
context 'Cloning procedure' do context 'Cloning a procedure owned by the current admin' do
before 'Create procedure' do scenario do
page.find_by_id('from-scratch').click visit admin_procedures_path
fill_in_dummy_procedure_details
page.find_by_id('save-procedure').click
end
scenario 'Cloning' do
visit admin_procedures_draft_path
expect(page.find_by_id('procedures')['data-item-count']).to eq('1') expect(page.find_by_id('procedures')['data-item-count']).to eq('1')
page.all('.clone-btn').first.click page.all('.clone-btn').first.click
visit admin_procedures_draft_path visit admin_procedures_draft_path
expect(page.find_by_id('procedures')['data-item-count']).to eq('2') expect(page.find_by_id('procedures')['data-item-count']).to eq('1')
click_on Procedure.last.libelle
expect(page).to have_current_path(admin_procedure_path(Procedure.last))
find('#publish-procedure').click
within '#publish-modal' do
expect(find_field('procedure_path').value).to eq 'libelle-de-la-procedure'
expect(page).to have_text('ancienne sera archivée')
fill_in 'lien_site_web', with: 'http://some.website'
click_on 'publish'
end
page.refresh
visit admin_procedures_archived_path
expect(page.find_by_id('procedures')['data-item-count']).to eq('1')
visit admin_procedures_draft_path
expect(page.find_by_id('procedures')['data-item-count']).to eq('0')
end end
end end
end end

View file

@ -98,11 +98,16 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
click_on Procedure.last.libelle click_on Procedure.last.libelle
expect(page).to have_current_path(admin_procedure_path(Procedure.last)) expect(page).to have_current_path(admin_procedure_path(Procedure.last))
expect(page).to have_content('en test')
# Only check the path even though the link is the complete URL
# (Capybara runs the app on an arbitrary host/port.)
expect(page).to have_link(nil, href: /#{commencer_test_path(Procedure.last.path)}/)
expect(page).to have_selector('#publish-procedure', visible: true) expect(page).to have_selector('#publish-procedure', visible: true)
find('#publish-procedure').click find('#publish-procedure').click
within '#publish-modal' do within '#publish-modal' do
expect(page).to have_field('procedure_path') expect(find_field('procedure_path').value).to eq 'libelle-de-la-procedure'
fill_in 'lien_site_web', with: 'http://some.website' fill_in 'lien_site_web', with: 'http://some.website'
click_on 'publish' click_on 'publish'
end end