docbrown/spec/system/comments/user_views_article_comments_spec.rb
Mac Siri fc39f24ee3 Migrate feature test to system test (#2301)
* Move all features to system

* Remove database_cleaner & apply use_transactional_fixtures

* Move rspec-retry to :test

* Update Capybara config

* Update rails_helper

* Fix user_visits_a_comments_page_spec.rb

* Fix lint
2019-04-04 12:15:10 -04:00

48 lines
1.7 KiB
Ruby

require "rails_helper"
RSpec.describe "Visiting article comments", type: :system, js: true do
let(:user) { create(:user) }
let(:article) { create(:article, user_id: user.id, show_comments: true) }
let!(:comment) { create(:comment, commentable: article, user: user) }
let!(:child_comment) { create(:comment, commentable: article, parent: comment) }
let!(:grandchild_comment) { create(:comment, commentable: article, parent: child_comment) }
before do
create(:comment, commentable: article, parent: comment)
comments = create_list(:comment, 3, commentable: article)
create(:comment, commentable: article, parent: comments.sample)
sign_in user
end
context "when all comments" do
before { visit "#{article.path}/comments" }
it "displays comments" do
expect(page).to have_selector(".single-comment-node", visible: true, count: 8)
end
it "displays child comments" do
expect(page).to have_selector(".comment-deep-1", visible: true, count: 3)
end
it "displays grandchild comments" do
expect(page).to have_selector("#comment-node-#{grandchild_comment.id}.comment-deep-2", visible: true, count: 1)
end
end
context "when root is specified" do
before { visit "#{article.path}/comments/#{comment.id.to_s(26)}" }
it "displays related comments" do
expect(page).to have_selector(".single-comment-node", visible: true, count: 4)
end
it "displays child comments" do
expect(page).to have_selector(".comment-deep-1", visible: true, count: 2)
end
it "displays grandchild comments" do
expect(page).to have_selector("#comment-node-#{grandchild_comment.id}.comment-deep-2", visible: true, count: 1)
end
end
end