Skip to content

Commit

Permalink
✅ implements system tests (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
karinevieira authored Jan 3, 2024
1 parent 5a1a9ce commit 4fc94ba
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ group :test do
gem "capybara", "3.39.2"
# Framework library to test our code [https://github.com/rspec/rspec-rails/]
gem "rspec-rails", "5.1.2"
# Limited DevTools interactions for Selenium WebDriver [https://rubygems.org/gems/selenium-devtools]
gem "selenium-devtools", "0.120.0"
# A browser automation framework and ecosystem [https://github.com/SeleniumHQ/selenium]
gem "selenium-webdriver", "4.16.0"
end
10 changes: 10 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ GEM
ruby-progressbar (1.13.0)
ruby-vips (2.2.0)
ffi (~> 1.12)
rubyzip (2.3.2)
selenium-devtools (0.120.0)
selenium-webdriver (~> 4.2)
selenium-webdriver (4.16.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
service_actor (3.2.0)
shoulda-matchers (6.0.0)
activesupport (>= 5.2.0)
Expand Down Expand Up @@ -332,6 +339,7 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
websocket (1.2.10)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down Expand Up @@ -366,6 +374,8 @@ DEPENDENCIES
rubocop-performance (= 1.20.1)
rubocop-rails (= 2.23.1)
rubocop-rspec (= 2.25.0)
selenium-devtools (= 0.120.0)
selenium-webdriver (= 4.16.0)
service_actor (= 3.2.0)
shoulda-matchers (= 6.0.0)
sprockets-rails (= 3.4.2)
Expand Down
18 changes: 18 additions & 0 deletions spec/support/capybara.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require "capybara/rails"
require "capybara/rspec"

RSpec.configure do |config|
%i[component page].each do |type|
config.include Capybara::RSpecMatchers, type: type
end

config.before(:each, type: :system) do
driven_by(:selenium, using: :headless_chrome, screen_size: [1920, 1080]) do |options|
# Enable this if you want to see browser console logs
# Then you can run add `puts page.driver.browser.logs.get(:browser)` to your tests`
# options.add_option "goog:loggingPrefs", { browser: "ALL" }
end
end
end
19 changes: 19 additions & 0 deletions spec/support/devise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Devise
module CustomSignInHelpers
# This method requires `factory_bot` gem installed and a `:user` factory registered
# It creates a new user if no parameter is given, and returns the signed in user
def sign_in(user = create(:user))
super(user)
user
end
end
end

RSpec.configure do |config|
%i[request system].each do |type|
config.include Devise::Test::IntegrationHelpers, type: type
config.include Devise::CustomSignInHelpers, type: type
end
end
28 changes: 28 additions & 0 deletions spec/system/posts/create_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "Create post" do
context "with valid form" do
it "creates a new post" do
sign_in

visit root_path

click_link(I18n.t("application.navbar_component.new"))
attach_file("post_image", Rails.root.join("spec/fixtures/files/image.png"), make_visible: true)
fill_in I18n.t("posts.new_page.subtitle"), with: "test subtitle"
click_button(I18n.t("posts.new_page.create_post"))

expect(page).to have_text("test subtitle")
.and have_css("img[src*='image.png']")
.and have_text("Publicação criada com sucesso")
end
end

context "with invalid form" do
it "re-renders form with error" do
skip "it needs to be implemented"
end
end
end
26 changes: 26 additions & 0 deletions spec/system/posts/update_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "Update post" do
context "with valid form" do
it "updates the post" do
user = sign_in
create(:post, user: user)

visit root_path

click_link(I18n.t("structure.card_component.edit"))
fill_in "Your subtitle", with: "test subtitle"
click_button("Edit post")

expect(page).to have_text("test subtitle")
end
end

context "with invalid form" do
it "re-renders form with error" do
skip "it needs to be implemented"
end
end
end

0 comments on commit 4fc94ba

Please sign in to comment.