Skip to content

Commit

Permalink
Merge pull request #13913 from saraycp/bs_request_comment_component
Browse files Browse the repository at this point in the history
Add specs for BsRequestCommentComponent
  • Loading branch information
saraycp committed Mar 1, 2023
2 parents 9e0cf4d + 1a35279 commit 7d31abc
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 10 deletions.
77 changes: 67 additions & 10 deletions src/api/spec/components/bs_request_comment_component_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,77 @@
require 'rails_helper'

RSpec.describe BsRequestCommentComponent, type: :component do
context 'when we have a comment' do
context 'when we have a commentable' do
context 'when rendering the first level of a comment thread' do
it 'renders the comment'
it 'renders the child comments underneath'
end
let(:commentable) { create(:bs_request_with_submit_action) }
let(:comment_a) { create(:comment_request, commentable: commentable, body: 'Comment A') }

subject { render_inline(described_class.new(comment: comment_a, commentable: commentable, level: 1)) }

context 'when the user is not logged in' do
it 'is not possible to reply a comment' do
expect(subject).not_to have_text('Reply')
end
end

context 'when the user is logged in and is the author of the comment' do
before do
User.session = comment_a.user
end

it 'is possible to reply to the comment' do
expect(subject).to have_text('Reply')
end

it 'is possible to edit the comment' do
expect(subject).to have_selector('.dropdown-menu', text: 'Edit')
end

it 'is possible to remove the comment' do
expect(subject).to have_selector('.dropdown-menu', text: 'Delete')
end
end

context 'when the user is logged in but is not the author of the comment' do
before do
User.session = build(:confirmed_user)
end

it 'is possible to reply to the comment' do
expect(subject).to have_text('Reply')
end

context 'when we do not have a commetable' do
it 'flashes an error'
it 'is not possible to edit the comment' do
expect(subject).not_to have_selector('.dropdown-menu', text: 'Edit')
end

it 'is not possible to remove the comment' do
expect(subject).not_to have_selector('.dropdown-menu', text: 'Delete')
end
end

context 'when we do not have a comment' do
it 'renders nothing'
context 'when rendering a comment thread' do
let(:comment_b) { create(:comment_request, commentable: commentable, body: 'Comment B', parent: comment_a) }
let!(:comment_c) { create(:comment_request, commentable: commentable, body: 'Comment C', parent: comment_b) }
let(:comment_d) { create(:comment_request, commentable: commentable, body: 'Comment D', parent: comment_c) }
let!(:comment_e) { create(:comment_request, commentable: commentable, body: 'Comment E', parent: comment_d) }

it 'displays the parent comment' do
expect(subject).to have_text("(#{comment_a.user.login})\nwrote")
expect(subject).to have_text('Comment A')
end

it 'displays the comments on level 2 in the 2nd level' do
expect(subject).to have_selector('.timeline-item-comment > .timeline-item-comment', text: "(#{comment_c.user.login})\nwrote")
expect(subject).to have_selector('.timeline-item-comment > .timeline-item-comment > .timeline-item-comment', text: 'Comment C')
end

it 'does not display the comments on level 4 in the 4th one' do
expect(subject).not_to have_selector((['.timeline-item-comment'] * 4).join(' > '), text: "(#{comment_e.user.login})\nwrote")
expect(subject).not_to have_selector((['.timeline-item-comment'] * 5).join(' > '), text: "(#{comment_e.user.login})\nwrote")
end

it 'displays the comments on level 4 in the 3rd level' do
expect(subject).to have_selector((['.timeline-item-comment'] * 3).join(' > '), text: "(#{comment_e.user.login})\nwrote")
expect(subject).to have_selector((['.timeline-item-comment'] * 4).join(' > '), text: 'Comment E')
end
end
end
1 change: 1 addition & 0 deletions src/api/spec/factories/comments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
factory :comment do
body { Faker::Lorem.paragraph }
user
parent { nil }

factory :comment_package do
commentable { create(:package) }
Expand Down

0 comments on commit 7d31abc

Please sign in to comment.