From 2b617b766abd8df1ec72255f8bd436935a8b40fa Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 6 Sep 2017 11:24:54 +0100 Subject: [PATCH] Add a basic feature test for reporting diary entries. --- config/routes.rb | 2 +- test/features/can_access_home_test.rb | 12 ++++++++++++ test/features/report_diary_entry_test.rb | 24 ++++++++++++++++++++++++ test/test_helper.rb | 9 +++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/features/can_access_home_test.rb create mode 100644 test/features/report_diary_entry_test.rb diff --git a/config/routes.rb b/config/routes.rb index c92926bd5..2fec73c4e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -223,7 +223,7 @@ OpenStreetMap::Application.routes.draw do match "/user/:display_name/diary" => "diary_entry#list", :via => :get match "/diary/:language" => "diary_entry#list", :via => :get match "/diary" => "diary_entry#list", :via => :get - match "/user/:display_name/diary/:id" => "diary_entry#view", :via => :get, :id => /\d+/ + match "/user/:display_name/diary/:id" => "diary_entry#view", :via => :get, :id => /\d+/, :as => :diary_entry match "/user/:display_name/diary/:id/newcomment" => "diary_entry#comment", :via => :post, :id => /\d+/ match "/user/:display_name/diary/:id/edit" => "diary_entry#edit", :via => [:get, :post], :id => /\d+/ match "/user/:display_name/diary/:id/hide" => "diary_entry#hide", :via => :post, :id => /\d+/, :as => :hide_diary_entry diff --git a/test/features/can_access_home_test.rb b/test/features/can_access_home_test.rb new file mode 100644 index 000000000..396ffc927 --- /dev/null +++ b/test/features/can_access_home_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +class CanAccessHomeTest < Capybara::Rails::TestCase + def setup + stub_hostip_requests + end + + def test_it_works + visit root_path + assert page.has_content? "BOpenStreetMap" + end +end diff --git a/test/features/report_diary_entry_test.rb b/test/features/report_diary_entry_test.rb new file mode 100644 index 000000000..aaa89ad5b --- /dev/null +++ b/test/features/report_diary_entry_test.rb @@ -0,0 +1,24 @@ +require "test_helper" + +class ReportDiaryEntryTest < Capybara::Rails::TestCase + def setup + create(:language, :code => "en") + @diary_entry = create(:diary_entry) + end + + def test_it_works + sign_in_as(create(:user)) + visit diary_entry_path(@diary_entry.user.display_name, @diary_entry) + assert page.has_content? @diary_entry.title + + click_on "\u2690" + assert page.has_content? "Report" + assert page.has_content? I18n.t("issues.new.disclaimer.intro") + + choose "report_type__SPAM" # FIXME: use label text when the radio button labels are working + fill_in "report_details", :with => "This is advertising" + click_on "Save changes" + + assert page.has_content? "Your report has been registered sucessfully" + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index d41a369f8..0e06c3c9e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,6 +5,7 @@ ENV["RAILS_ENV"] = "test" require File.expand_path("../../config/environment", __FILE__) require "rails/test_help" require "webmock/minitest" +require "minitest/rails/capybara" module ActiveSupport class TestCase @@ -150,5 +151,13 @@ module ActiveSupport end end end + + def sign_in_as(user) + stub_hostip_requests + visit login_path + fill_in "username", :with => user.email + fill_in "password", :with => "test" + click_on "Login", :match => :first + end end end -- 2.39.5