]> git.openstreetmap.org Git - rails.git/blob - test/application_system_test_case.rb
$ ./bin/rails devcontainer # DB config written as config/devcontainer.database.yml
[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   if ENV["CAPYBARA_SERVER_PORT"]
18     served_by host: "rails-app", port: ENV["CAPYBARA_SERVER_PORT"]
19
20     driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ], options: {
21       browser: :remote,
22       url: "http://#{ENV["SELENIUM_HOST"]}:4444"
23     }
24   else
25     driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ]
26   end
27     options.add_preference("intl.accept_languages", "en")
28     options.binary = Settings.system_test_firefox_binary if Settings.system_test_firefox_binary
29   end
30
31   def before_setup
32     super
33     osm_website_app = create(:oauth_application, :name => "OpenStreetMap Web Site", :scopes => "write_api write_notes")
34     Settings.oauth_application = osm_website_app.uid
35   end
36
37   def after_teardown
38     Settings.reload!
39     super
40   end
41
42   private
43
44   def sign_in_as(user)
45     visit login_path
46     within "form", :text => "Email Address or Username" do
47       fill_in "username", :with => user.email
48       fill_in "password", :with => "s3cr3t"
49       click_on "Log in"
50     end
51   end
52
53   def sign_out
54     visit logout_path
55     click_on "Logout", :match => :first
56   end
57
58   def within_sidebar(&)
59     within("#sidebar_content", &)
60   end
61
62   def within_content_body(&)
63     within("#content > .content-body", &)
64   end
65
66   def within_content_heading(&)
67     within("#content > .content-heading", &)
68   end
69 end