I want to test that a user can skip the shipping_address form after his registration.
So I have this button in the form, with some Javasrcipt that redirect to the page the user was before.
If I remove the :jsin the scenario Capybara is able to find #subscription but the test fails because of the path (no js no redirection). If I put the:jsit can't find the #subscription Would you please give me hints for this?
shipping_addresses/new.html.erb
<%= link_to 'Remplir plus tard', 'javascript:history.go(-1);', class: "btn btn-secondary btn-block" %> Here is the test
scenario "skipping the address form for now", :js do visit root_path find('#subscription').click choose "Monsieur" fill_in "user[first_name]", with: "Benoit" fill_in "user[last_name]", with: "Durant" fill_in "user[birth_date]", with: "08/05/1981" fill_in "user[email]", with: "[email protected]" fill_in "user[email_confirmation]", with: "[email protected]" fill_in "user[password]", with: "password" fill_in "user[password_confirmation]", with: "password" click_on "Valider mon inscription" expect(page).to have_content("REMPLISSEZ VOTRE ADRESSE DE LIVRAISON") click_on "Remplir plus tard" expect(current_path).to eq root_path end This is the dropdown in my navbar
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink"> <%= link_to "Connection", new_user_session_path, class: "dropdown-item" %> <%= link_to "Inscription", new_user_registration_path, class: "dropdown-item", id:"subscription" %> </div> edit more of my navbar
<div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav ml-auto"> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <% if current_user %> <%= current_user.first_name %> <% else %> Mon Compte <% end %> </a> <% if current_user %> <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink"> #Just removed the links to clear the code </div> <% else %> <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink"> <%= link_to "Connection", new_user_session_path, class: "dropdown-item" %> <%= link_to "Inscription", new_user_registration_path, class: "dropdown-item", id:"subscription" %> </div> <% end %> </li> </ul> </div>
<%= link_to "Inscription", new_user_registration_path, class: "dropdown-item", id:"subscription" %>new_user_registration_path