Skip to content

Commit

Permalink
Merge branch 'master' into preprod
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Sep 5, 2024
2 parents fa62004 + 57809a4 commit 7b62d3a
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

env:
RAILS_MASTER_KEY: "acf7c0d9c0f69afd05048c8a58b2e9ee"
FERRUM_PROCESS_TIMEOUT: 25
FERRUM_DEFAULT_TIMEOUT: 15

services:
postgres:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
18 changes: 16 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -584,6 +596,7 @@ DEPENDENCIES
byebug
capybara (>= 2.15)
csv
cuprite
dalli
dartsass-sprockets
datagrid
Expand All @@ -595,6 +608,7 @@ DEPENDENCIES
diffy (~> 3.4)
exception_notification
faraday
formulaic
friendly_id (~> 5.2)
geocoder
high_voltage
Expand Down
73 changes: 73 additions & 0 deletions spec/features/rooms/browse_room_spec.rb
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -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 }
3 changes: 3 additions & 0 deletions spec/support/features.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

Dir[Rails.root.join("spec/support/features/**/*.rb")].each { |f| require f }
9 changes: 9 additions & 0 deletions spec/support/features/formulaic.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/controllers/frames_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/frames.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
one:
id: 1
name: MyFrame1
slug: myframe1
u: 48
bay_id: 1
position: 1

two:
id: 2
name: MyFrame2
slug: myframe2
u: 48
bay_id: 1
position: 2

three:
id: 3
name: MyFrame3
slug: myframe3
u: 24
bay_id: 1
position: 3

0 comments on commit 7b62d3a

Please sign in to comment.