diff --git a/.travis.yml b/.travis.yml index a5fec1a71..430d7fbb2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,13 @@ cache: bundler env: - DB=postgresql bundler_args: --without development staging production +before_install: + - "wget -N http://chromedriver.storage.googleapis.com/2.40/chromedriver_linux64.zip -P ~/" + - "unzip ~/chromedriver_linux64.zip -d ~/" + - "rm ~/chromedriver_linux64.zip" + - "sudo mv -f ~/chromedriver /usr/local/share/" + - "sudo chmod +x /usr/local/share/chromedriver" + - "sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver" before_script: - "cp config/application-example.yml config/application.yml" - "cp config/database-travis.yml config/database.yml" @@ -19,3 +26,4 @@ services: - postgresql addons: postgresql: "9.4" + chrome: stable diff --git a/CHANGELOG.md b/CHANGELOG.md index 838ff6ea4..ecefbb279 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +12.07.2018 +* Implemented JavaScript testing framework to catch web UI problems [#900](https://github.com/internetee/registry/issues/900) + 10.07.2018 * Nameserver bulk change returns list of affected doamins [#835](https://github.com/internetee/registry/issues/835) diff --git a/Gemfile b/Gemfile index 7682cdc4e..e1c3858ba 100644 --- a/Gemfile +++ b/Gemfile @@ -104,14 +104,13 @@ gem 'active_model-errors_details' # Backport from Rails 5, https://github.com/ra group :development do # deploy gem 'mina', '0.3.1' # for fast deployment - gem 'puma' end group :development, :test do gem 'factory_bot_rails' gem 'capybara' gem 'rspec-rails', '~> 3.6' - gem 'poltergeist' + gem 'selenium-webdriver' # debug gem 'pry', '0.10.1' @@ -121,6 +120,7 @@ group :development, :test do gem 'sdoc', '0.4.1' # bundle exec rake doc:rails generates the API under doc/api. gem 'railroady', '1.3.0' # to generate database diagrams gem 'autodoc' + gem 'puma' end group :staging do diff --git a/Gemfile.lock b/Gemfile.lock index 9a88e782b..9d9f99da9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -99,8 +99,8 @@ GEM minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.5.1) - public_suffix (~> 2.0, >= 2.0.2) + addressable (2.5.2) + public_suffix (>= 2.0.2, < 4.0) airbrake (6.0.0) airbrake-ruby (~> 2.0) airbrake-ruby (2.0.0) @@ -134,8 +134,9 @@ GEM rack (>= 1.0.0) rack-test (>= 0.5.4) xpath (~> 2.0) + childprocess (0.9.0) + ffi (~> 1.0, >= 1.0.11) chronic (0.10.2) - cliver (0.3.2) coderay (1.1.0) coercible (1.0.0) descendants_tracker (~> 0.0.1) @@ -180,6 +181,7 @@ GEM factory_bot_rails (4.8.2) factory_bot (~> 4.8.2) railties (>= 3.0.0) + ffi (1.9.25) figaro (1.1.1) thor (~> 0.14) globalid (0.4.1) @@ -204,7 +206,7 @@ GEM haml (>= 4.0.6, < 5.0) html2haml (>= 1.0.1) railties (>= 4.0.1) - hashdiff (0.3.4) + hashdiff (0.3.7) hashie (3.5.5) hashie-forbidden_attributes (0.1.1) hashie (>= 3.0) @@ -276,17 +278,13 @@ GEM orm_adapter (0.5.0) pdfkit (0.6.2) pg (0.19.0) - poltergeist (1.14.0) - capybara (~> 2.1) - cliver (~> 0.3.1) - websocket-driver (>= 0.2.0) polyamorous (1.3.1) activerecord (>= 3.0) pry (0.10.1) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) - public_suffix (2.0.5) + public_suffix (3.0.2) puma (3.8.2) que (0.10.0) que-web (0.4.0) @@ -368,6 +366,7 @@ GEM rspec-support (3.6.0) ruby_parser (3.8.4) sexp_processor (~> 4.1) + rubyzip (1.2.1) safe_yaml (1.0.4) sass (3.4.23) sass-rails (5.0.6) @@ -390,6 +389,9 @@ GEM select2-rails (3.5.9.3) thor (~> 0.14) selectize-rails (0.12.1) + selenium-webdriver (3.13.0) + childprocess (~> 0.5) + rubyzip (~> 1.2) sexp_processor (4.8.0) simplecov (0.15.1) docile (~> 1.1.0) @@ -436,13 +438,10 @@ GEM wasabi (3.5.0) httpi (~> 2.0) nokogiri (>= 1.4.2) - webmock (3.0.1) + webmock (3.4.2) addressable (>= 2.3.6) crack (>= 0.3.2) hashdiff - websocket-driver (0.6.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.2) whenever (0.9.4) chronic (>= 0.6.3) xpath (2.0.0) @@ -491,7 +490,6 @@ DEPENDENCIES paper_trail! pdfkit (= 0.6.2) pg (= 0.19.0) - poltergeist pry (= 0.10.1) puma que (= 0.10.0) @@ -507,6 +505,7 @@ DEPENDENCIES sdoc (= 0.4.1) select2-rails (= 3.5.9.3) selectize-rails (= 0.12.1) + selenium-webdriver simplecov simpleidn (= 0.0.7) uglifier diff --git a/spec/features/registrar/sign_in/mobile_id_spec.rb b/spec/features/registrar/sign_in/mobile_id_spec.rb deleted file mode 100644 index 35c0cc18e..000000000 --- a/spec/features/registrar/sign_in/mobile_id_spec.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'rails_helper' - -RSpec.feature 'Mobile ID login', db: true do - given!(:api_user) { create(:api_user, identity_code: 1234) } - - background do - digidoc_client = instance_double(Digidoc::Client, authenticate: OpenStruct.new(user_id_code: 1234), session_code: 1234) - allow(Digidoc::Client).to receive(:new).and_return(digidoc_client) - end - - scenario 'login with phone number' do - visit new_registrar_user_session_url - click_on 'login-with-mobile-id-btn' - - fill_in 'user[phone]', with: '1234' - click_button 'Login' - - expect(page).to have_text('Confirmation sms was sent to your phone. Verification code is') - end -end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c6110a8c2..aead0dfa5 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -2,7 +2,6 @@ ENV['RAILS_ENV'] ||= 'test' require 'spec_helper' require File.expand_path('../../config/environment', __FILE__) require 'rspec/rails' -require 'capybara/poltergeist' require 'paper_trail/frameworks/rspec' require 'money-rails/test_helpers' require 'support/requests/session_helpers' diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 7ef5009c6..5434f1a84 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -4,5 +4,3 @@ RSpec.configure do |config| config.include CapybaraViewMacros, type: :view config.include CapybaraViewMacros, type: :presenter end - -Capybara.javascript_driver = :poltergeist diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 000000000..6c06ef937 --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,42 @@ +require 'test_helper' + +require 'database_cleaner' +require 'selenium/webdriver' + +class ApplicationSystemTestCase < ActionDispatch::IntegrationTest; end + +class JavaScriptApplicationSystemTestCase < ApplicationSystemTestCase + self.use_transactional_fixtures = false + DatabaseCleaner.strategy = :truncation + + Capybara.register_driver(:chrome) do |_app| + options = ::Selenium::WebDriver::Chrome::Options.new + + options.add_argument('--headless') + options.add_argument('--no-sandbox') + options.add_argument('--disable-dev-shm-usage') + options.add_argument('--window-size=1400,1400') + + Capybara::Selenium::Driver.new(Rails.application, browser: :chrome, options: options) + end + + Capybara.register_server(:silent_puma) do |app, port, _host| + require 'rack/handler/puma' + Rack::Handler::Puma.run(app, Port: port, Threads: '0:2', Silent: true) + end + + def setup + DatabaseCleaner.start + + super + + Capybara.current_driver = :chrome + Capybara.server = :silent_puma + end + + def teardown + super + + DatabaseCleaner.clean + end +end diff --git a/test/system/registrar/sign_in_test.rb b/test/system/registrar/sign_in_test.rb new file mode 100644 index 000000000..9af5522f9 --- /dev/null +++ b/test/system/registrar/sign_in_test.rb @@ -0,0 +1,35 @@ +require 'test_helper' + +class RegistrarAreaSignInTest < JavaScriptApplicationSystemTestCase + def setup + super + WebMock.allow_net_connect! + + @user = users(:api_bestnames) + @user.identity_code = '1234' + @user.save + end + + def test_mobile_id_sign_in_page + mock_client = Minitest::Mock.new + mock_client.expect(:authenticate, + OpenStruct.new(user_id_code: '1234', challenge_id: '1234'), + [{ phone: "+3721234", + message_to_display: "Authenticating", + service_name: "Testimine" }]) + mock_client.expect(:session_code, 1234) + + Digidoc::Client.stub(:new, mock_client) do + visit registrar_login_path + + click_on 'login-with-mobile-id-btn' + + fill_in 'user[phone]', with: '1234' + click_button 'Login' + + flash_message = page.find('div.bg-success') + assert_equal('Confirmation sms was sent to your phone. Verification code is 1234.', + flash_message.text) + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index a55776fd2..500861f75 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -13,6 +13,8 @@ require 'capybara/minitest' require 'webmock/minitest' require 'support/rails5_assetions' # Remove once upgraded to Rails 5 +require 'application_system_test_case' + Setting.address_processing = false Setting.registry_country_code = 'US' @@ -38,4 +40,4 @@ class ActionDispatch::IntegrationTest Capybara.reset_sessions! Capybara.use_default_driver end -end \ No newline at end of file +end