-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13913 from saraycp/bs_request_comment_component
Add specs for BsRequestCommentComponent
- Loading branch information
Showing
2 changed files
with
68 additions
and
10 deletions.
There are no files selected for viewing
77 changes: 67 additions & 10 deletions
77
src/api/spec/components/bs_request_comment_component_spec.rb
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 |
---|---|---|
@@ -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 |
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