mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 11:17:49 +01:00
Add system tests for likes
This commit is contained in:
@@ -95,16 +95,17 @@ feature 'comments', type: :system, js: true do
|
||||
end
|
||||
end
|
||||
|
||||
# it 'enables users to comment' do
|
||||
# log_in_as user
|
||||
# visit post_path(post)
|
||||
it 'enables users to comment' do
|
||||
log_in_as user
|
||||
visit post_path(post)
|
||||
|
||||
# comments_count = Comment.where(post_id: post.id).count
|
||||
# comment_body = 'this is a comment!'
|
||||
comments_count = Comment.where(post_id: post.id).count
|
||||
comment_body = 'this is a comment!'
|
||||
|
||||
# find(newCommentBodySelector).fill_in with: comment_body
|
||||
# click_button 'Submit'
|
||||
find(newCommentBodySelector).fill_in with: comment_body
|
||||
click_button 'Submit'
|
||||
visit post_path(post)
|
||||
|
||||
# expect(Comment.where(post_id: post.id).count).to eq(comments_count + 1)
|
||||
# end
|
||||
expect(Comment.where(post_id: post.id).count).to eq(comments_count + 1)
|
||||
end
|
||||
end
|
||||
62
spec/system/likes_spec.rb
Normal file
62
spec/system/likes_spec.rb
Normal file
@@ -0,0 +1,62 @@
|
||||
require 'rails_helper'
|
||||
|
||||
feature 'likes', type: :system, js: true do
|
||||
let(:board) { FactoryBot.create(:board) }
|
||||
let(:post1) { FactoryBot.create(:post, board: board) }
|
||||
let(:post2) { FactoryBot.create(:post, board: board) }
|
||||
let(:user) { FactoryBot.create(:user) }
|
||||
|
||||
let(:board_container) { '.boardContainer' }
|
||||
let(:like_button_container_selector) { '.likeButtonContainer' }
|
||||
let(:like_button_selector) { '.likeButton' }
|
||||
let(:likes_count_label_selector) { '.likesCountLabel' }
|
||||
|
||||
before(:each) do
|
||||
board
|
||||
post1
|
||||
post2
|
||||
end
|
||||
|
||||
context 'in post list of Board component' do
|
||||
it 'renders correctly for each post' do
|
||||
visit board_path(board)
|
||||
|
||||
within board_container do
|
||||
expect(page).to have_selector(like_button_container_selector, count: 2)
|
||||
expect(page).to have_selector(like_button_selector, count: 2)
|
||||
expect(page).to have_selector(likes_count_label_selector, count: 2)
|
||||
end
|
||||
end
|
||||
|
||||
it 'redirects when user not logged in' do
|
||||
visit board_path(board)
|
||||
|
||||
within board_container do
|
||||
find(like_button_selector, match: :first).click
|
||||
expect(page.current_path).to eq(new_user_session_path)
|
||||
end
|
||||
end
|
||||
|
||||
it 'likes and unlikes' do
|
||||
user.confirm
|
||||
sign_in user
|
||||
visit board_path(board)
|
||||
|
||||
within board_container do
|
||||
first_like_button = find(like_button_selector, match: :first)
|
||||
like_container = find(like_button_container_selector, match: :first)
|
||||
|
||||
# starts at zero likes
|
||||
expect(like_container).to have_content(0)
|
||||
|
||||
# like
|
||||
first_like_button.click
|
||||
expect(like_container).to have_content(1)
|
||||
|
||||
# unlike
|
||||
first_like_button.click
|
||||
expect(like_container).to have_content(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user