]> git.openstreetmap.org Git - rails.git/blob - test/application_system_test_case.rb
Test submitting no change to a user image
[rails.git] / test / application_system_test_case.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 ENV.delete("http_proxy")
6
7 ActiveSupport.on_load(:action_dispatch_system_test_case) do
8   ActionDispatch::SystemTesting::Server.silence_puma = true
9 end
10
11 class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
12   include ActionMailer::TestCase::ClearTestDeliveries
13
14   Capybara.configure do |config|
15     config.enable_aria_label = true
16   end
17
18   cattr_accessor(:capybara_server_port) { ENV.fetch("CAPYBARA_SERVER_PORT", nil) }
19
20   served_by :host => "rails-app", :port => capybara_server_port if capybara_server_port
21
22   def self.driven_by_selenium(config_name = "default", opts = {})
23     preferences = opts.fetch(:preferences, {}).reverse_merge(
24       "intl.accept_languages" => "en"
25     )
26
27     options = {
28       :name => config_name
29     }
30
31     if capybara_server_port
32       selenium_host = "http://selenium-#{config_name}:4444"
33       options = options.merge(
34         :url => selenium_host,
35         :browser => :remote
36       )
37     end
38
39     driven_by(
40       :selenium,
41       :using => Settings.system_test_headless ? :headless_firefox : :firefox,
42       :options => options
43     ) do |options|
44       preferences.each do |name, value|
45         options.add_preference(name, value)
46       end
47       options.binary = Settings.system_test_firefox_binary if Settings.system_test_firefox_binary
48     end
49   end
50
51   driven_by_selenium
52
53   def before_setup
54     super
55     osm_website_app = create(:oauth_application, :name => "OpenStreetMap Web Site", :scopes => "write_api write_notes")
56     Settings.oauth_application = osm_website_app.uid
57   end
58
59   def before_teardown
60     super
61     Capybara.reset_sessions!
62   end
63
64   def after_teardown
65     Settings.reload!
66     super
67   end
68
69   private
70
71   def sign_in_as(user)
72     visit login_path
73     within "form", :text => "Email Address or Username" do
74       fill_in "username", :with => user.email
75       fill_in "password", :with => "s3cr3t"
76       click_on "Log in"
77     end
78   end
79
80   def sign_out
81     visit logout_path
82     click_on "Logout", :match => :first
83   end
84
85   def within_sidebar(&)
86     within("#sidebar_content", &)
87   end
88
89   def within_content_body(&)
90     within("#content > .content-body", &)
91   end
92
93   def within_content_heading(&)
94     within("#content > .content-heading", &)
95   end
96 end