Merge pull request #4801 from consul/spec_support_custom_folder

Allow to customize tests common action modules
This commit is contained in:
Javi Martín
2022-04-06 17:27:30 +02:00
committed by GitHub
9 changed files with 227 additions and 230 deletions

View File

@@ -13,7 +13,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
before { set_arguments(arguments, mappable, mappable_path_arguments) }
scenario "Should not show marker by default on create #{mappable_factory_name}" do
do_login_for user
do_login_for user, management: management
visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form")
@@ -24,7 +24,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end
scenario "Should show marker on create #{mappable_factory_name} when click on map" do
do_login_for user
do_login_for user, management: management
visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form")
@@ -36,7 +36,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end
scenario "Should create #{mappable_factory_name} with map" do
do_login_for user
do_login_for user, management: management
visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form")
@@ -49,7 +49,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end
scenario "Can not display map on #{mappable_factory_name} when not fill marker on map" do
do_login_for user
do_login_for user, management: management
visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form")
@@ -61,7 +61,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
scenario "Can not display map on #{mappable_factory_name} when feature.map is disabled" do
Setting["feature.map"] = false
do_login_for user
do_login_for user, management: management
visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form")
@@ -75,7 +75,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
before { Setting["org_name"] = "CONSUL" }
scenario "map should not be duplicated" do
do_login_for user
do_login_for user, management: management
visit send(mappable_new_path, arguments)
if management
@@ -96,7 +96,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end
scenario "keeps marker and zoom defined by the user" do
do_login_for user
do_login_for user, management: management
visit send(mappable_new_path, arguments)
within ".map_location" do
@@ -130,7 +130,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end
scenario "shows marker at map center" do
do_login_for user
do_login_for user, management: management
visit send(mappable_new_path, arguments)
within ".map_location" do
@@ -163,7 +163,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end
scenario "Skip map" do
do_login_for user
do_login_for user, management: management
visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form")
@@ -177,16 +177,16 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
before { skip } if mappable_edit_path.blank?
scenario "Should edit map on #{mappable_factory_name} and contain default values" do
do_login_for mappable.author
do_login_for mappable.author, management: management
visit send(mappable_edit_path, id: mappable.id)
expect(page).to have_content "Navigate the map to the location and place the marker."
validate_latitude_longitude(mappable_factory_name)
validate_latitude_longitude(mappable, mappable_factory_name)
end
scenario "Should edit default values from map on #{mappable_factory_name} edit page" do
do_login_for mappable.author
do_login_for mappable.author, management: management
visit send(mappable_edit_path, id: mappable.id)
find(".map_location").click
@@ -199,7 +199,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end
scenario "Should edit mappable on #{mappable_factory_name} without change map" do
do_login_for mappable.author
do_login_for mappable.author, management: management
visit send(mappable_edit_path, id: mappable.id)
fill_in "#{mappable_factory_name.camelize} title", with: "New title"
@@ -212,7 +212,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end
scenario "Can not display map on #{mappable_factory_name} edit when remove map marker" do
do_login_for mappable.author
do_login_for mappable.author, management: management
visit send(mappable_edit_path, id: mappable.id)
click_link "Remove map marker"
@@ -223,7 +223,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
scenario "Can not display map on #{mappable_factory_name} edit when feature.map is disabled" do
Setting["feature.map"] = false
do_login_for mappable.author
do_login_for mappable.author, management: management
visit send(mappable_edit_path, id: mappable.id)
fill_in "#{mappable_factory_name.camelize} title", with: "New title"
@@ -234,7 +234,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
scenario "No errors on update" do
skip ""
do_login_for mappable.author
do_login_for mappable.author, management: management
visit send(mappable_edit_path, id: mappable.id)
click_link "Remove map marker"
@@ -244,7 +244,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
end
scenario "No need to skip map on update" do
do_login_for mappable.author
do_login_for mappable.author, management: management
visit send(mappable_edit_path, id: mappable.id)
click_link "Remove map marker"
@@ -262,7 +262,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
scenario "Should display map and marker on #{mappable_factory_name} show page" do
arguments[:id] = mappable.id
do_login_for(user) if management
do_login_for user, management: management if management
visit send(mappable_show_path, arguments)
within ".map_location" do
@@ -275,7 +275,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
set_arguments(arguments, mappable_without_map, mappable_path_arguments)
arguments[:id] = mappable_without_map.id
do_login_for(user) if management
do_login_for user, management: management if management
visit send(mappable_show_path, arguments)
expect(page).not_to have_css(".map_location")
@@ -285,68 +285,10 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
Setting["feature.map"] = false
arguments[:id] = mappable.id
do_login_for(user) if management
do_login_for user, management: management if management
visit send(mappable_show_path, arguments)
expect(page).not_to have_css(".map_location")
end
end
end
def do_login_for(user)
common_do_login_for(user, management: management)
end
def fill_in_proposal_form
fill_in_new_proposal_title with: "Help refugees"
fill_in "Proposal summary", with: "In summary, what we want is..."
end
def submit_proposal_form
check :proposal_terms_of_service
click_button "Create proposal"
if page.has_content?("Not now, go to my proposal")
click_link "Not now, go to my proposal"
end
end
def validate_latitude_longitude(mappable_factory_name)
expect(find("##{mappable_factory_name}_map_location_attributes_latitude", visible: false).value).to eq "51.48"
expect(find("##{mappable_factory_name}_map_location_attributes_longitude", visible: false).value).to eq "0.0"
expect(mappable.map_location.latitude).to eq 51.48
expect(mappable.map_location.longitude).to eq 0.0
end
def fill_in_budget_investment_form
fill_in_new_investment_title with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service
end
def submit_budget_investment_form
check :budget_investment_terms_of_service
click_button "Create Investment"
end
def set_arguments(arguments, mappable, mappable_path_arguments)
mappable_path_arguments&.each do |argument_name, path_to_value|
arguments.merge!("#{argument_name}": mappable.send(path_to_value))
end
end
def map_zoom_in
initial_zoom = page.execute_script("return App.Map.maps[0].getZoom();")
find(".leaflet-control-zoom-in").click
until page.execute_script("return App.Map.maps[0].getZoom() === #{initial_zoom + 1};") do
sleep 0.01
end
end
def place_map_at(latitude, longitude)
page.execute_script("App.Map.maps[0].setView(new L.LatLng(#{latitude}, #{longitude}))")
until page.execute_script("return App.Map.maps[0].getCenter().lat === #{latitude};") do
sleep 0.01
end
end

View File

@@ -22,7 +22,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
describe "at #{path}" do
scenario "Should show new document link when max documents allowed limit is not reached" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
expect(page).to have_css "#new_document_link"
@@ -30,7 +30,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should not show new document link when
documentable max documents allowed limit is reached" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
documentable.class.max_documents_allowed.times.each do
@@ -41,14 +41,14 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
scenario "Should not show max documents warning when no documents added" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
expect(page).not_to have_css ".max-documents-notice"
end
scenario "Should show max documents warning when max documents allowed limit is reached" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
documentable.class.max_documents_allowed.times.each do
documentable_attach_new_file(file_fixture("empty.pdf"))
@@ -59,7 +59,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
scenario "Should hide max documents warning after any document removal" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
documentable.class.max_documents_allowed.times.each do
@@ -72,7 +72,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
scenario "Should update nested document file name after choosing a file" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
click_link "Add new document"
@@ -87,7 +87,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should update nested document file title with
file name after choosing a file when no title defined" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
documentable_attach_new_file(file_fixture("empty.pdf"))
@@ -97,7 +97,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should not update nested document file title with
file name after choosing a file when title already defined" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
click_link "Add new document"
@@ -113,7 +113,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
scenario "Should update loading bar style after valid file upload" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
documentable_attach_new_file(file_fixture("empty.pdf"))
@@ -122,7 +122,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
scenario "Should update loading bar style after invalid file upload" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
documentable_attach_new_file(file_fixture("logo_header.gif"), false)
@@ -131,7 +131,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
scenario "Should update document cached_attachment field after valid file upload" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
click_link "Add new document"
@@ -146,7 +146,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
scenario "Should not update document cached_attachment field after invalid file upload" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
documentable_attach_new_file(file_fixture("logo_header.gif"), false)
@@ -157,7 +157,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should show document errors after documentable submit with
empty document fields" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
click_link "Add new document"
@@ -169,7 +169,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
scenario "Should delete document after valid file upload and click on remove button" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
documentable_attach_new_file(file_fixture("empty.pdf"))
@@ -180,7 +180,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should show successful notice when
resource filled correctly without any nested documents" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
@@ -191,7 +191,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should show successful notice when
resource filled correctly and after valid file uploads" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
@@ -205,7 +205,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
if documentable_factory_name == "dashboard_action"
skip("Not render Documents count on dashboard_actions")
end
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
@@ -227,7 +227,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
if documentable_factory_name == "dashboard_action"
skip("Not render Documents count on dashboard_actions")
end
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
@@ -245,7 +245,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
if path.include? "edit"
scenario "Should show persisted documents and remove nested_field" do
create(:document, documentable: documentable)
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
expect(page).to have_css ".document", count: 1
@@ -254,7 +254,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should not show add document button when
documentable has reached maximum of documents allowed" do
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
expect(page).not_to have_css "#new_document_link"
@@ -262,7 +262,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should show add document button after destroy one document" do
create_list(:document, documentable.class.max_documents_allowed, documentable: documentable)
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
last_document = all("#nested-documents .document").last
within last_document do
@@ -274,7 +274,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
scenario "Should remove nested field after remove document" do
create(:document, documentable: documentable)
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
click_on "Remove document"
@@ -282,7 +282,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
scenario "Same attachment URL after editing the title" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
documentable_attach_new_file(file_fixture("empty.pdf"))
@@ -308,7 +308,7 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
scenario "Add new document button should not be available" do
do_login_for user_to_login
do_login_for user_to_login, management: management
visit send(path, arguments)
expect(page).not_to have_content("Add new document")
@@ -316,54 +316,3 @@ shared_examples "nested documentable" do |login_as_name, documentable_factory_na
end
end
end
def do_login_for(user)
common_do_login_for(user, management: management)
end
def documentable_redirected_to_resource_show_or_navigate_to
find("a", text: "Not now, go to my proposal")
click_on "Not now, go to my proposal"
rescue
nil
end
def documentable_attach_new_file(path, success = true)
click_link "Add new document"
document = all(".document").last
attach_file "Choose document", path
within document do
if success
expect(page).to have_css ".loading-bar.complete"
else
expect(page).to have_css ".loading-bar.errors"
end
end
end
def expect_document_has_title(index, title)
document = all(".document")[index]
within document do
expect(find("input[name$='[title]']").value).to eq title
end
end
def documentable_fill_new_valid_proposal
fill_in_new_proposal_title with: "Proposal title #{rand(9999)}"
fill_in "Proposal summary", with: "Proposal summary"
check :proposal_terms_of_service
end
def documentable_fill_new_valid_dashboard_action
fill_in :dashboard_action_title, with: "Dashboard title"
fill_in_ckeditor "Description", with: "Dashboard description"
end
def documentable_fill_new_valid_budget_investment
fill_in_new_investment_title with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service
end

View File

@@ -18,14 +18,14 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
describe "at #{path}" do
scenario "Should show new image link when imageable has not an associated image defined" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
expect(page).to have_selector "#new_image_link"
end
scenario "Should hide new image link after adding one image" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
click_on "Add image"
@@ -34,7 +34,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should update nested image file name after choosing any file" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
click_link "Add image"
@@ -44,7 +44,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should update nested image file title with file name after choosing a file when no title defined" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
imageable_attach_new_file(file_fixture("clippy.jpg"))
@@ -53,7 +53,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should not update nested image file title with file name after choosing a file when title already defined" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
click_link "Add image"
@@ -69,7 +69,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should update loading bar style after valid file upload" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
imageable_attach_new_file(file_fixture("clippy.jpg"))
@@ -78,7 +78,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should update loading bar style after invalid file upload" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
imageable_attach_new_file(file_fixture("logo_header.png"), false)
@@ -87,7 +87,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should update image cached_attachment field after valid file upload" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
click_link "Add image"
@@ -102,7 +102,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should not update image cached_attachment field after invalid file upload" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
imageable_attach_new_file(file_fixture("logo_header.png"), false)
@@ -113,7 +113,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should show nested image errors after invalid form submit" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
click_link "Add image"
@@ -130,7 +130,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
scenario "Render image preview after sending the form with validation errors" do
skip "Question answers behave differently" if imageable.is_a?(Poll::Question::Answer)
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
imageable_attach_new_file(file_fixture("clippy.jpg"))
@@ -142,7 +142,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should remove nested image after valid file upload and click on remove button" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
imageable_attach_new_file(file_fixture("clippy.jpg"))
@@ -158,7 +158,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
if has_many_images
skip "no need to test, there are no attributes for the parent resource"
else
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
@@ -168,7 +168,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should show successful notice when resource filled correctly and after valid file uploads" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
@@ -182,7 +182,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Should show new image after successful creation with one uploaded file" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
send(fill_resource_method_name) if fill_resource_method_name
@@ -191,7 +191,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
expect(page).to have_selector ".loading-bar.complete"
click_on submit_button
imageable_redirected_to_resource_show_or_navigate_to
imageable_redirected_to_resource_show_or_navigate_to(imageable)
if has_many_images
# Pending. Review soon and test
@@ -202,7 +202,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
scenario "Different URLs for different images" do
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
imageable_attach_new_file(file_fixture("clippy.jpg"))
@@ -220,7 +220,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
if path.include? "edit"
scenario "show persisted image" do
create(:image, imageable: imageable)
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
@@ -230,7 +230,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
scenario "remove nested field after removing the image" do
create(:image, imageable: imageable)
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
click_link "Remove image"
@@ -241,7 +241,7 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
scenario "don't duplicate fields after removing and adding an image" do
create(:image, imageable: imageable)
do_login_for user
do_login_for user, management: management
visit send(path, arguments)
click_link "Remove image"
@@ -252,59 +252,3 @@ shared_examples "nested imageable" do |imageable_factory_name, path, imageable_p
end
end
end
def do_login_for(user)
common_do_login_for(user, management: management)
end
def imageable_redirected_to_resource_show_or_navigate_to
case imageable.class.to_s
when "Budget"
visit edit_admin_budget_path(Budget.last)
when "Proposal"
click_on "Not now, go to my proposal" rescue Capybara::ElementNotFound
end
end
def imageable_attach_new_file(path, success = true)
click_link "Add image"
within "#nested-image" do
image = find(".image")
attach_file "Choose image", path
within image do
if success
expect(page).to have_css(".loading-bar.complete")
else
expect(page).to have_css(".loading-bar.errors")
end
end
end
end
def imageable_fill_new_valid_proposal
fill_in_new_proposal_title with: "Proposal title"
fill_in "Proposal summary", with: "Proposal summary"
check :proposal_terms_of_service
end
def imageable_fill_new_valid_budget
fill_in "Name", with: "Budget name"
end
def imageable_fill_new_valid_budget_investment
fill_in_new_investment_title with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service
end
def expect_image_has_title(title)
image = find(".image")
within image do
expect(find("input[name$='[title]']").value).to eq title
end
end
def show_caption_for?(imageable_factory_name)
imageable_factory_name != "budget"
end

View File

@@ -1,10 +1,14 @@
Dir["./spec/support/common_actions/*.rb"].each { |f| require f }
Dir["./spec/support/common_actions/custom/*.rb"].each { |f| require f }
module CommonActions
include Budgets
include Comments
include Debates
include Documents
include Emails
include Images
include Maps
include Notifications
include Polls
include Proposals

View File

View File

@@ -0,0 +1,48 @@
module Documents
def documentable_redirected_to_resource_show_or_navigate_to
find("a", text: "Not now, go to my proposal")
click_on "Not now, go to my proposal"
rescue
nil
end
def documentable_attach_new_file(path, success = true)
click_link "Add new document"
document = all(".document").last
attach_file "Choose document", path
within document do
if success
expect(page).to have_css ".loading-bar.complete"
else
expect(page).to have_css ".loading-bar.errors"
end
end
end
def expect_document_has_title(index, title)
document = all(".document")[index]
within document do
expect(find("input[name$='[title]']").value).to eq title
end
end
def documentable_fill_new_valid_proposal
fill_in_new_proposal_title with: "Proposal title #{rand(9999)}"
fill_in "Proposal summary", with: "Proposal summary"
check :proposal_terms_of_service
end
def documentable_fill_new_valid_dashboard_action
fill_in :dashboard_action_title, with: "Dashboard title"
fill_in_ckeditor "Description", with: "Dashboard description"
end
def documentable_fill_new_valid_budget_investment
fill_in_new_investment_title with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service
end
end

View File

@@ -0,0 +1,53 @@
module Images
def imageable_redirected_to_resource_show_or_navigate_to(imageable)
case imageable.class.to_s
when "Budget"
visit edit_admin_budget_path(Budget.last)
when "Proposal"
click_on "Not now, go to my proposal" rescue Capybara::ElementNotFound
end
end
def imageable_attach_new_file(path, success = true)
click_link "Add image"
within "#nested-image" do
image = find(".image")
attach_file "Choose image", path
within image do
if success
expect(page).to have_css(".loading-bar.complete")
else
expect(page).to have_css(".loading-bar.errors")
end
end
end
end
def imageable_fill_new_valid_proposal
fill_in_new_proposal_title with: "Proposal title"
fill_in "Proposal summary", with: "Proposal summary"
check :proposal_terms_of_service
end
def imageable_fill_new_valid_budget
fill_in "Name", with: "Budget name"
end
def imageable_fill_new_valid_budget_investment
fill_in_new_investment_title with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service
end
def expect_image_has_title(title)
image = find(".image")
within image do
expect(find("input[name$='[title]']").value).to eq title
end
end
def show_caption_for?(imageable_factory_name)
imageable_factory_name != "budget"
end
end

View File

@@ -0,0 +1,57 @@
module Maps
def fill_in_proposal_form
fill_in_new_proposal_title with: "Help refugees"
fill_in "Proposal summary", with: "In summary, what we want is..."
end
def submit_proposal_form
check :proposal_terms_of_service
click_button "Create proposal"
if page.has_content?("Not now, go to my proposal")
click_link "Not now, go to my proposal"
end
end
def validate_latitude_longitude(mappable, mappable_factory_name)
latitude_attribute = "##{mappable_factory_name}_map_location_attributes_latitude"
longitude_attribute = "##{mappable_factory_name}_map_location_attributes_longitude"
expect(find(latitude_attribute, visible: false).value).to eq "51.48"
expect(find(longitude_attribute, visible: false).value).to eq "0.0"
expect(mappable.map_location.latitude).to eq 51.48
expect(mappable.map_location.longitude).to eq 0.0
end
def fill_in_budget_investment_form
fill_in_new_investment_title with: "Budget investment title"
fill_in_ckeditor "Description", with: "Budget investment description"
check :budget_investment_terms_of_service
end
def submit_budget_investment_form
check :budget_investment_terms_of_service
click_button "Create Investment"
end
def set_arguments(arguments, mappable, mappable_path_arguments)
mappable_path_arguments&.each do |argument_name, path_to_value|
arguments.merge!("#{argument_name}": mappable.send(path_to_value))
end
end
def map_zoom_in
initial_zoom = page.execute_script("return App.Map.maps[0].getZoom();")
find(".leaflet-control-zoom-in").click
until page.execute_script("return App.Map.maps[0].getZoom() === #{initial_zoom + 1};") do
sleep 0.01
end
end
def place_map_at(latitude, longitude)
page.execute_script("App.Map.maps[0].setView(new L.LatLng(#{latitude}, #{longitude}))")
until page.execute_script("return App.Map.maps[0].getCenter().lat === #{latitude};") do
sleep 0.01
end
end
end

View File

@@ -82,7 +82,7 @@ module Users
expect(find(".top-bar-right")).not_to have_content "My account"
end
def common_do_login_for(user, management:)
def do_login_for(user, management:)
if management
login_managed_user(user)
login_as_manager