Skip to content

Commit

Permalink
Comment component specs
Browse files Browse the repository at this point in the history
  • Loading branch information
danidoni committed Mar 17, 2022
1 parent 9744099 commit 919c849
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/api/app/components/comment_component_preview.rb
@@ -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
59 changes: 59 additions & 0 deletions src/api/spec/components/comment_component_spec.rb
@@ -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

0 comments on commit 919c849

Please sign in to comment.