diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fef098be1..cfe393ebe 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -18,6 +18,8 @@ jobs: env: RAILS_MASTER_KEY: "acf7c0d9c0f69afd05048c8a58b2e9ee" + FERRUM_PROCESS_TIMEOUT: 25 + FERRUM_DEFAULT_TIMEOUT: 15 services: postgres: @@ -45,6 +47,11 @@ jobs: rubygems: "latest" bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - name: Setup Chrome + uses: browser-actions/setup-chrome@latest + with: + chrome-version: stable + - name: Set up Database env: RAILS_ENV: test diff --git a/Gemfile b/Gemfile index 3e1488a49..53cc412bf 100644 --- a/Gemfile +++ b/Gemfile @@ -57,6 +57,8 @@ end group :test do gem "capybara", ">= 2.15" + gem "cuprite" + gem "formulaic" gem "rails-controller-testing" gem "rspec-activemodel-mocks" gem "rspec-html-matchers" @@ -65,7 +67,6 @@ group :test do gem "simplecov", require: false gem "simplecov-console", require: false # gem "minitest-rails-capybara" - # gem "formulaic" # gem "sinatra", require: false # gem "vcr" # gem "webmock" diff --git a/Gemfile.lock b/Gemfile.lock index 23807e527..1aedea9e7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -121,6 +121,9 @@ GEM css_parser (1.17.1) addressable csv (3.3.0) + cuprite (0.15.1) + capybara (~> 3.0) + ferrum (~> 0.15.0) dalli (3.2.8) dartsass-sprockets (3.1.0) railties (>= 4.0.0) @@ -170,7 +173,16 @@ GEM faraday (>= 1, < 3) faraday-net_http (3.1.0) net-http + ferrum (0.15) + addressable (~> 2.5) + concurrent-ruby (~> 1.1) + webrick (~> 1.7) + websocket-driver (~> 0.7) ffi (1.16.3) + formulaic (0.4.2) + activesupport + capybara + i18n friendly_id (5.5.1) activerecord (>= 4.0.0) geocoder (1.8.2) @@ -406,8 +418,8 @@ GEM responders (3.1.1) actionpack (>= 5.2) railties (>= 5.2) - rexml (3.2.8) - strscan (>= 3.0.9) + rexml (3.3.3) + strscan rouge (4.2.1) rspec (3.13.0) rspec-core (~> 3.13.0) @@ -584,6 +596,7 @@ DEPENDENCIES byebug capybara (>= 2.15) csv + cuprite dalli dartsass-sprockets datagrid @@ -595,6 +608,7 @@ DEPENDENCIES diffy (~> 3.4) exception_notification faraday + formulaic friendly_id (~> 5.2) geocoder high_voltage diff --git a/spec/features/rooms/browse_room_spec.rb b/spec/features/rooms/browse_room_spec.rb new file mode 100644 index 000000000..cdbcbff5b --- /dev/null +++ b/spec/features/rooms/browse_room_spec.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "Rooms::BrowseRoom", :js do + let(:room) { rooms(:one) } + + # The 2nd bay created an empty "couple div" in rooms #Show view, causing the test to fail. + before do + room.islets.first.bays.last.destroy! + end + + it("browse a room, islets and bays, change view and background color") do # rubocop:disable RSpec/MultipleExpectations + sign_in(users(:one)) + + visit room_path(room) + expect(page).to have_current_path(room_path(room)) + + frame = room.frames.first + + # 1. Select a frame + overview_frame = find("div[data-frame-id=#{frame.slug}]") + overview_frame.click + + # Waits for the overview to fully load + find("div##{room.name.downcase}") + + frame.servers.each do |server| + expect(page).to have_content(server.name) + end + + # 2. Change view to 'back' + switch_view_btn = find("span.pull-right > a.btn.btn-success") + switch_view_btn.click + + # Since the overview container is already loaded, we cannot use find() to wait for loading + sleep 1 + + # On the back view, we should see some server cards (only the 2nd server has cards) + frame.servers.second.cards.pluck(:name).each do |card_name| + expect(page).to have_content(card_name) + end + + # Modele background color + overview_frame_title = find("div.title > a[data-frame-id=#{frame.slug}]") + overview_frame_title.click + + sleep 1 + + # For background color set to 'modele', we check for a cyan/white background-color + colored_lines = all("ul.servers > li.server.mystring") + + colored_lines.each do |line| + expect(line.style("background-color")["background-color"]).to eq("rgb(183, 247, 255)").or eq("rgb(255, 255, 255)") + end + + # 3. Change background color to 'gestionnaire' + bg_dropdown_button = first("span.pull-right > * > .btn-default.dropdown-toggle") + bg_dropdown_button.click + + bg_dropdown_gestionnaire = all(".dropdown-menu > li")[1] + bg_dropdown_gestionnaire.click + + sleep 1 + + # For background color set to 'gestionnaire', we check for a green/white background-color + colored_lines = all("ul.servers > li.server.mystring") + + colored_lines.each do |line| + expect(line.style("background-color")["background-color"]).to eq("rgb(118, 255, 160)").or eq("rgb(255, 255, 255)") + end + end +end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb new file mode 100644 index 000000000..55aaa05c7 --- /dev/null +++ b/spec/support/capybara.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require "capybara/cuprite" + +Capybara.register_driver(:cuprite) do |app| + options = { + window_size: [1920, 1080], + browser_options: {}, + inspector: ENV.fetch("CUPRITE_INSPECTOR", nil), + js_errors: true, + } + + options[:headless] = ENV.fetch("CUPRITE_HEADLESS", nil) != "false" + options[:browser_options][:"no-sandbox"] = nil if ENV["CI"] + + Capybara::Cuprite::Driver.new(app, options) +end + +# NOTE: Wait for AJAX response since turbo make SHR requests. +Capybara.default_max_wait_time = 5 +Capybara.javascript_driver = :cuprite +Capybara.server = :puma, { Silent: true } diff --git a/spec/support/features.rb b/spec/support/features.rb new file mode 100644 index 000000000..3577acc64 --- /dev/null +++ b/spec/support/features.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +Dir[Rails.root.join("spec/support/features/**/*.rb")].each { |f| require f } diff --git a/spec/support/features/formulaic.rb b/spec/support/features/formulaic.rb new file mode 100644 index 000000000..3eb3cac05 --- /dev/null +++ b/spec/support/features/formulaic.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +RSpec.configure do |config| + config.include Formulaic::Dsl, type: :feature +end + +# NOTE: Wait for AJAX response since turbo make SHR requests. +# See: https://github.com/thoughtbot/formulaic/blob/6f80b41773aa17f73847598abbd1e2b220b09715/README.md#assumptions +Formulaic.default_wait_time = 5 diff --git a/test/controllers/frames_controller_test.rb b/test/controllers/frames_controller_test.rb index 6da92d78c..b69871f19 100644 --- a/test/controllers/frames_controller_test.rb +++ b/test/controllers/frames_controller_test.rb @@ -21,7 +21,7 @@ class FramesControllerTest < ActionController::TestCase test "should create frame" do assert_difference('Frame.count') do - post :create, params: { frame: { name: @frame.name, bay_id: 1 } } + post :create, params: { frame: { name: "MyFrame4", bay_id: 1 } } end assert_redirected_to frames_path diff --git a/test/fixtures/frames.yml b/test/fixtures/frames.yml index 84c6bed56..dae16713b 100644 --- a/test/fixtures/frames.yml +++ b/test/fixtures/frames.yml @@ -3,6 +3,7 @@ one: id: 1 name: MyFrame1 + slug: myframe1 u: 48 bay_id: 1 position: 1 @@ -10,6 +11,7 @@ one: two: id: 2 name: MyFrame2 + slug: myframe2 u: 48 bay_id: 1 position: 2 @@ -17,6 +19,7 @@ two: three: id: 3 name: MyFrame3 + slug: myframe3 u: 24 bay_id: 1 position: 3