]> git.openstreetmap.org Git - rails.git/blob - test/application_system_test_case.rb
Merge pull request #6424 from pablobm/devcontainer
[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 after_teardown
60     Settings.reload!
61     super
62   end
63
64   private
65
66   def sign_in_as(user)
67     visit login_path
68     within "form", :text => "Email Address or Username" do
69       fill_in "username", :with => user.email
70       fill_in "password", :with => "s3cr3t"
71       click_on "Log in"
72     end
73   end
74
75   def sign_out
76     visit logout_path
77     click_on "Logout", :match => :first
78   end
79
80   def within_sidebar(&)
81     within("#sidebar_content", &)
82   end
83
84   def within_content_body(&)
85     within("#content > .content-body", &)
86   end
87
88   def within_content_heading(&)
89     within("#content > .content-heading", &)
90   end
91 end