-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a1a9ce
commit 4fc94ba
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |