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
Showing
2 changed files
with
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class CommentComponentPreview < ViewComponent::Preview | ||
def with_default_content | ||
render(CommentComponent.new(comment: create(:comment), obj_is_user: create(:confirmed_user))) | ||
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,59 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe CommentComponent, type: :component do | ||
let(:builder) { Builder::XmlMarkup.new } | ||
|
||
before do | ||
render_inline(described_class.new(comment: comment, obj_is_user: true, builder: builder)) | ||
end | ||
|
||
shared_examples 'rendering the body, who, when and the id' do | ||
it "renders the comment's body" do | ||
expect(builder).to have_text(comment.body) | ||
end | ||
|
||
it "renders who commented as an attribute of the comment's tag" do | ||
expect(builder).to have_xpath("//comment_[contains(@who, '#{comment.user.login}')]") | ||
end | ||
|
||
it "renders when the comment was commented as an attribute of the comment's tag" do | ||
expect(builder).to have_xpath("//comment_[contains(@when, '#{comment.created_at}')]") | ||
end | ||
|
||
it 'renders the id of the comment' do | ||
expect(builder).to have_xpath("//comment_[contains(@id, '#{comment.id}')]") | ||
end | ||
end | ||
|
||
context 'when the comment has a user, the comment creation date' do | ||
context 'and the commentable is a Project' do | ||
let(:comment) { create(:comment_project) } | ||
|
||
it_behaves_like 'rendering the body, who, when and the id' | ||
|
||
it 'renders the project of the comment' do | ||
expect(builder).to have_xpath("//comment_[contains(@project, '#{comment.commentable.name}')]") | ||
end | ||
end | ||
|
||
context 'and the commentable is a Package' do | ||
let(:comment) { create(:comment_package) } | ||
|
||
it_behaves_like 'rendering the body, who, when and the id' | ||
|
||
it 'renders the package name of the commenter' do | ||
expect(builder).to have_xpath("//comment_[contains(@package, '#{comment.commentable.name}')]") | ||
end | ||
end | ||
|
||
context 'and the commentable is Request' do | ||
let(:comment) { create(:comment_request) } | ||
|
||
it_behaves_like 'rendering the body, who, when and the id' | ||
|
||
it 'renders the request number of the commenter' do | ||
expect(builder).to have_xpath("//comment_[contains(@bsrequest, '#{comment.commentable.number}')]") | ||
end | ||
end | ||
end | ||
end |