Skip to content

Commit

Permalink
Simplify administrators comments tests
Browse files Browse the repository at this point in the history
  • Loading branch information
taitus committed Mar 25, 2024
1 parent 79d00e7 commit 5780574
Showing 1 changed file with 34 additions and 40 deletions.
74 changes: 34 additions & 40 deletions spec/system/comments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -448,57 +448,51 @@
end

describe "Administrators" do
context "comment as administrator" do
scenario "can create comment" do
admin = create(:administrator)
scenario "can create comment" do
admin = create(:administrator)

login_as(admin.user)
visit polymorphic_path(resource)

fill_in fill_text, with: "I am your Admin!"
check "Comment as admin"
click_button button_text
login_as(admin.user)
visit polymorphic_path(resource)

within "#comments" do
expect(page).to have_content "I am your Admin!"
expect(page).to have_content "Administrator ##{admin.id}"
expect(page).to have_css "div.is-admin"
expect(page).to have_css "img.admin-avatar"
end
end
expect(page).not_to have_content "Comment as moderator"

scenario "can create reply as an administrator" do
admin = create(:administrator)
comment = create(:comment, commentable: resource)
fill_in fill_text, with: "I am your Admin!"
check "Comment as admin"
click_button button_text

login_as(admin.user)
visit polymorphic_path(resource)
within "#comments" do
expect(page).to have_content "I am your Admin!"
expect(page).to have_content "Administrator ##{admin.id}"
expect(page).to have_css "div.is-admin"
expect(page).to have_css "img.admin-avatar"
end
end

within "#comment_#{comment.id}" do
click_link "Reply"
end
scenario "can create reply as an administrator" do
admin = create(:administrator)
comment = create(:comment, commentable: resource)

within "#js-comment-form-comment_#{comment.id}" do
fill_in fill_text, with: "Top of the world!"
check "Comment as admin"
click_button "Publish reply"
end
login_as(admin.user)
visit polymorphic_path(resource)

within "#comment_#{comment.id}" do
expect(page).to have_content "Top of the world!"
expect(page).to have_content "Administrator ##{admin.id}"
expect(page).to have_css "div.is-admin"
expect(page).to have_css "img.admin-avatar"
end
within "#comment_#{comment.id}" do
click_link "Reply"
end

expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
within "#js-comment-form-comment_#{comment.id}" do
fill_in fill_text, with: "Top of the world!"
check "Comment as admin"
click_button "Publish reply"
end
end

scenario "can not comment as a moderator", :admin do
visit polymorphic_path(resource)
within "#comment_#{comment.id}" do
expect(page).to have_content "Top of the world!"
expect(page).to have_content "Administrator ##{admin.id}"
expect(page).to have_css "div.is-admin"
expect(page).to have_css "img.admin-avatar"
end

expect(page).not_to have_content "Comment as moderator"
expect(page).not_to have_css "#js-comment-form-comment_#{comment.id}"
end
end

Expand Down

0 comments on commit 5780574

Please sign in to comment.