diff --git a/app/javascript/components/Comments/Comment.tsx b/app/javascript/components/Comments/Comment.tsx index 4f05be55..2540a9a2 100644 --- a/app/javascript/components/Comments/Comment.tsx +++ b/app/javascript/components/Comments/Comment.tsx @@ -39,7 +39,7 @@ const Comment = ({
{body}
{ diff --git a/app/javascript/components/Comments/NewComment.tsx b/app/javascript/components/Comments/NewComment.tsx index c68a4167..c0b03b1d 100644 --- a/app/javascript/components/Comments/NewComment.tsx +++ b/app/javascript/components/Comments/NewComment.tsx @@ -20,6 +20,7 @@ const NewComment = ({ diff --git a/spec/factories/comments.rb b/spec/factories/comments.rb index bcbcfcaa..58909ffd 100644 --- a/spec/factories/comments.rb +++ b/spec/factories/comments.rb @@ -1,6 +1,6 @@ FactoryBot.define do factory :comment do - body { "MyText" } + sequence(:body) { |n| "Comment #{n}" } user post parent { nil } diff --git a/spec/system/comments_spec.rb b/spec/system/comments_spec.rb new file mode 100644 index 00000000..f814514e --- /dev/null +++ b/spec/system/comments_spec.rb @@ -0,0 +1,64 @@ +require 'rails_helper' + +feature 'comments', type: :system, js: true do + let(:post) { FactoryBot.create(:post) } + let(:comment1) { FactoryBot.create(:comment, post: post) } + let(:comment2) { FactoryBot.create(:comment, post: post) } + let(:comment3) { FactoryBot.create(:comment, post: post, parent: comment2) } + let(:user) { FactoryBot.create(:user) } + + let(:commentsSelector) { '.comments' } + let(:commentListSelector) { '.commentList' } + let(:commentSelector) { '.comment' } + let(:commentAuthorSelector) { '.commentAuthor' } + let(:commentReplyBtnSelector) { '.commentReplyButton' } + let(:newCommentFormSelector) { '.newCommentForm' } + let(:newCommentBodySelector) { '.newCommentBody' } + + def create_comments + comment1 + comment2 + comment3 + end + + before(:each) do + create_comments + visit post_path(post) + end + + it 'renders correctly' do + expect(page).to have_selector(commentsSelector, count: 1) + end + + it 'renders all comments of a post' do + within commentsSelector do + expect(page).to have_selector(commentSelector, count: 3) + expect(page).to have_content(/#{comment1.body}/i) + expect(page).to have_content(/#{comment2.body}/i) + expect(page).to have_content(/#{comment3.body}/i) + end + end + + it 'renders nested comments' do + within commentsSelector do + expect(page).to have_selector( + "#{commentListSelector} > #{commentListSelector}", + count: 1 + ) # 1 nested comment + end + end + + it 'renders the author full name for each comment' do + page.all(:css, commentSelector).each do |comment| + expect(comment).to have_selector(commentAuthorSelector) + expect(comment).to have_content(/#{post.user.full_name}/i) + end + end + + it 'renders a reply button for each comment' do + page.all(:css, commentSelector).each do |comment| + expect(comment).to have_selector(commentReplyBtnSelector) + expect(comment).to have_content(/#{'reply'}/i) + end + end +end \ No newline at end of file