Allow undo votes in comments votes component

This commit is contained in:
taitus
2023-09-20 16:10:36 +02:00
parent f87a332c3e
commit 718fcba6d8
16 changed files with 101 additions and 36 deletions

View File

@@ -5,8 +5,8 @@ describe Comments::VotesComponent do
let(:comment) { create(:comment, user: user) }
let(:component) { Comments::VotesComponent.new(comment) }
describe "aria-pressed attribute" do
it "is true when the in-favor button is pressed" do
describe "aria-pressed and method attributes" do
it "have expected values when the in-favor button is pressed" do
comment.vote_by(voter: user, vote: "yes")
sign_in(user)
@@ -14,14 +14,18 @@ describe Comments::VotesComponent do
page.find(".in-favor") do |in_favor_block|
expect(in_favor_block).to have_css "button[aria-pressed='true']"
expect(in_favor_block).to have_css "form[action*='votes'][method='post']"
expect(in_favor_block).to have_css "input[name='_method'][value='delete']", visible: :hidden
end
page.find(".against") do |against_block|
expect(against_block).to have_css "button[aria-pressed='false']"
expect(against_block).to have_css "form[action*='votes'][method='post']"
expect(against_block).not_to have_css "input[name='_method']", visible: :all
end
end
it "is true when the against button is pressed" do
it "have expected values when the against button is pressed" do
comment.vote_by(voter: user, vote: "no")
sign_in(user)
@@ -29,24 +33,32 @@ describe Comments::VotesComponent do
page.find(".in-favor") do |in_favor_block|
expect(in_favor_block).to have_css "button[aria-pressed='false']"
expect(in_favor_block).to have_css "form[action*='votes'][method='post']"
expect(in_favor_block).not_to have_css "input[name='_method']", visible: :all
end
page.find(".against") do |against_block|
expect(against_block).to have_css "button[aria-pressed='true']"
expect(against_block).to have_css "form[action*='votes'][method='post']"
expect(against_block).to have_css "input[name='_method'][value='delete']", visible: :hidden
end
end
it "is false when neither the 'in-favor' button nor the 'against' button are pressed" do
it "have expected values when neither the 'in-favor' button nor the 'against' button are pressed" do
sign_in(user)
render_inline component
page.find(".in-favor") do |in_favor_block|
expect(in_favor_block).to have_css "button[aria-pressed='false']"
expect(in_favor_block).to have_css "form[action*='votes'][method='post']"
expect(in_favor_block).not_to have_css "input[name='_method']", visible: :all
end
page.find(".against") do |against_block|
expect(against_block).to have_css "button[aria-pressed='false']"
expect(against_block).to have_css "form[action*='votes'][method='post']"
expect(against_block).not_to have_css "input[name='_method']", visible: :all
end
end
end