Use JavaScript in tests using the user menu
This way we click on the "menu" link first before clicking on any sections, just like real users do.
This commit is contained in:
@@ -68,10 +68,11 @@ describe "Admin" do
|
||||
expect(page).not_to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Admin access links", :admin do
|
||||
scenario "Admin access links", :admin, :js do
|
||||
Setting["feature.sdg"] = true
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link("Administration")
|
||||
expect(page).to have_link("Moderation")
|
||||
@@ -80,9 +81,10 @@ describe "Admin" do
|
||||
expect(page).to have_link("SDG content")
|
||||
end
|
||||
|
||||
scenario "Admin dashboard", :admin do
|
||||
scenario "Admin dashboard", :admin, :js do
|
||||
visit root_path
|
||||
|
||||
click_link "Menu"
|
||||
click_link "Administration"
|
||||
|
||||
expect(page).to have_current_path(admin_root_path)
|
||||
|
||||
@@ -15,8 +15,10 @@ describe "Poll budget ballot sheets" do
|
||||
set_officing_booth(booth)
|
||||
end
|
||||
|
||||
scenario "Budget polls are visible" do
|
||||
scenario "Budget polls are visible", :js do
|
||||
visit root_path
|
||||
|
||||
click_link "Menu"
|
||||
click_link "Polling officers"
|
||||
|
||||
within("#side_menu") do
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Management" do
|
||||
describe "Management", :js do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
scenario "Should show admin menu if logged user is admin" do
|
||||
create(:administrator, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_link("Management")
|
||||
|
||||
click_link "Menu"
|
||||
click_link "Management"
|
||||
|
||||
expect(page).to have_content("My content")
|
||||
@@ -22,8 +21,7 @@ describe "Management" do
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_link("Management")
|
||||
|
||||
click_link "Menu"
|
||||
click_link "Management"
|
||||
|
||||
expect(page).not_to have_content("My content")
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Moderation" do
|
||||
describe "Moderation", :js do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
scenario "Access as regular user is not authorized" do
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
|
||||
expect(page).not_to have_link("Menu")
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
visit moderation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(moderation_root_path)
|
||||
@@ -17,11 +20,13 @@ describe "Moderation" do
|
||||
|
||||
scenario "Access as valuator is not authorized" do
|
||||
create(:valuator, user: user)
|
||||
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
visit moderation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(moderation_root_path)
|
||||
@@ -31,11 +36,13 @@ describe "Moderation" do
|
||||
|
||||
scenario "Access as manager is not authorized" do
|
||||
create(:manager, user: user)
|
||||
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
visit moderation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(moderation_root_path)
|
||||
@@ -45,9 +52,10 @@ describe "Moderation" do
|
||||
|
||||
scenario "Access as SDG manager is not authorized", :js do
|
||||
create(:sdg_manager, user: user)
|
||||
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
@@ -60,11 +68,13 @@ describe "Moderation" do
|
||||
|
||||
scenario "Access as poll officer is not authorized" do
|
||||
create(:poll_officer, user: user)
|
||||
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Moderation")
|
||||
|
||||
visit moderation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(moderation_root_path)
|
||||
@@ -77,9 +87,8 @@ describe "Moderation" do
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_link("Moderation")
|
||||
click_on "Moderation"
|
||||
click_link "Menu"
|
||||
click_link "Moderation"
|
||||
|
||||
expect(page).to have_current_path(moderation_root_path)
|
||||
expect(page).not_to have_content "You do not have permission to access this page"
|
||||
@@ -90,9 +99,8 @@ describe "Moderation" do
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_link("Moderation")
|
||||
click_on "Moderation"
|
||||
click_link "Menu"
|
||||
click_link "Moderation"
|
||||
|
||||
expect(page).to have_current_path(moderation_root_path)
|
||||
expect(page).not_to have_content "You do not have permission to access this page"
|
||||
@@ -101,7 +109,9 @@ describe "Moderation" do
|
||||
scenario "Moderation access links" do
|
||||
create(:moderator, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link("Moderation")
|
||||
expect(page).not_to have_link("Administration")
|
||||
@@ -116,8 +126,9 @@ describe "Moderation" do
|
||||
scenario "Contains correct elements" do
|
||||
create(:moderator, user: user)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
click_link "Moderation"
|
||||
|
||||
expect(page).to have_link("Go back to OrgName")
|
||||
|
||||
@@ -19,12 +19,13 @@ describe "Officing Results", :with_frozen_time do
|
||||
set_officing_booth(booth)
|
||||
end
|
||||
|
||||
scenario "Only polls where user is officer for results are accessible" do
|
||||
scenario "Only polls where user is officer for results are accessible", :js do
|
||||
not_allowed_poll_1 = create(:poll, :expired)
|
||||
not_allowed_poll_2 = create(:poll, officers: [poll_officer], ends_at: 1.day.ago)
|
||||
not_allowed_poll_3 = create(:poll, officers: [poll_officer])
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
click_link "Polling officers"
|
||||
|
||||
expect(page).to have_content("Poll officing")
|
||||
|
||||
@@ -83,51 +83,54 @@ describe "Poll Officing" do
|
||||
expect(page).to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Access as an administrator with poll officer role is authorized" do
|
||||
scenario "Access as an administrator with poll officer role is authorized", :js do
|
||||
create(:administrator, user: user)
|
||||
create(:poll_officer, user: user)
|
||||
create(:poll)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_link("Polling officers")
|
||||
click_on "Polling officers"
|
||||
click_link "Menu"
|
||||
click_link "Polling officers"
|
||||
|
||||
expect(page).to have_current_path(officing_root_path)
|
||||
expect(page).not_to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Access as an poll officer is authorized" do
|
||||
scenario "Access as an poll officer is authorized", :js do
|
||||
create(:poll_officer, user: user)
|
||||
create(:poll)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_link("Polling officers")
|
||||
click_on "Polling officers"
|
||||
click_link "Menu"
|
||||
click_link "Polling officers"
|
||||
|
||||
expect(page).to have_current_path(officing_root_path)
|
||||
expect(page).not_to have_content "You do not have permission to access this page"
|
||||
end
|
||||
|
||||
scenario "Poll officer access links" do
|
||||
scenario "Poll officer access links", :js do
|
||||
create(:poll)
|
||||
create(:poll_officer, user: user)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link("Polling officers")
|
||||
expect(page).not_to have_link("Valuation")
|
||||
expect(page).not_to have_link("Administration")
|
||||
expect(page).not_to have_link("Moderation")
|
||||
end
|
||||
|
||||
scenario "Officing dashboard" do
|
||||
scenario "Officing dashboard", :js do
|
||||
create(:poll_officer, user: user)
|
||||
create(:poll)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
click_link "Menu"
|
||||
click_link "Polling officers"
|
||||
|
||||
expect(page).to have_current_path(officing_root_path)
|
||||
|
||||
@@ -20,8 +20,10 @@ describe "Valuation budget investments" do
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Display link to valuation section" do
|
||||
scenario "Display link to valuation section", :js do
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link "Valuation", href: valuation_root_path
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Valuation" do
|
||||
describe "Valuation", :js do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
context "Access" do
|
||||
@@ -8,7 +8,9 @@ describe "Valuation" do
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).not_to have_link("Menu")
|
||||
expect(page).not_to have_link("Valuation")
|
||||
|
||||
visit valuation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(valuation_root_path)
|
||||
@@ -19,9 +21,12 @@ describe "Valuation" do
|
||||
scenario "Access as moderator is not authorized" do
|
||||
create(:moderator, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Valuation")
|
||||
|
||||
visit valuation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(valuation_root_path)
|
||||
@@ -32,9 +37,12 @@ describe "Valuation" do
|
||||
scenario "Access as manager is not authorized" do
|
||||
create(:manager, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Valuation")
|
||||
|
||||
visit valuation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(valuation_root_path)
|
||||
@@ -45,9 +53,12 @@ describe "Valuation" do
|
||||
scenario "Access as SDG manager is not authorized" do
|
||||
create(:sdg_manager, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Valuation")
|
||||
|
||||
visit valuation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(valuation_root_path)
|
||||
@@ -58,9 +69,12 @@ describe "Valuation" do
|
||||
scenario "Access as poll officer is not authorized" do
|
||||
create(:poll_officer, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).not_to have_link("Valuation")
|
||||
|
||||
visit valuation_root_path
|
||||
|
||||
expect(page).not_to have_current_path(valuation_root_path)
|
||||
@@ -71,12 +85,11 @@ describe "Valuation" do
|
||||
scenario "Access as a valuator is authorized" do
|
||||
create(:valuator, user: user)
|
||||
create(:budget)
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_link("Valuation")
|
||||
click_on "Valuation"
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
click_link "Valuation"
|
||||
|
||||
expect(page).to have_current_path(valuation_root_path)
|
||||
expect(page).not_to have_content "You do not have permission to access this page"
|
||||
@@ -85,12 +98,11 @@ describe "Valuation" do
|
||||
scenario "Access as an administrator is authorized" do
|
||||
create(:administrator, user: user)
|
||||
create(:budget)
|
||||
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_link("Valuation")
|
||||
click_on "Valuation"
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
click_link "Valuation"
|
||||
|
||||
expect(page).to have_current_path(valuation_root_path)
|
||||
expect(page).not_to have_content "You do not have permission to access this page"
|
||||
@@ -100,9 +112,10 @@ describe "Valuation" do
|
||||
scenario "Valuation access links" do
|
||||
create(:valuator, user: user)
|
||||
create(:budget)
|
||||
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
|
||||
expect(page).to have_link("Valuation")
|
||||
expect(page).not_to have_link("Administration")
|
||||
@@ -116,6 +129,7 @@ describe "Valuation" do
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
click_link "Menu"
|
||||
click_link "Valuation"
|
||||
|
||||
expect(page).to have_current_path(valuation_root_path)
|
||||
|
||||
Reference in New Issue
Block a user