get phlex component tests working

This commit is contained in:
James Smith committed 2025-05-07 15:55:03 +01:00
1 parent f3b936b35c
commit d33da62fbb
2 files changed
+23 -4

No files matched your search

+4 -4
View File
@@ -14,7 +14,7 @@ RSpec.describe Components::FollowButton, type: :component do
context "when the follower is not following the target" do
let(:button) {
allow(follower).to receive(:following?).with(target).and_return false
render_inline(described_class.new(follower: follower, target: target)).to_html
render described_class.new(follower: follower, target: target)
}
it "creates a button" do
@@ -27,14 +27,14 @@ RSpec.describe Components::FollowButton, type: :component do
it "links to the create path for the target's follows resource" do # rubocop:todo RSpec/MultipleExpectations
expect(button).to include "method=\"post\""
expect(button).to include "action=\"/creators/#{target.to_param}/follows\""
expect(button).to include "action=\"http://test.host/creators/#{target.to_param}/follows\""
end
end
context "when the follower is already following the target" do
let(:button) {
allow(follower).to receive(:following?).with(target).and_return :accepted
render_inline(described_class.new(follower: follower, target: target)).to_html
render described_class.new(follower: follower, target: target)
}
it "creates a button" do
@@ -47,7 +47,7 @@ RSpec.describe Components::FollowButton, type: :component do
it "links to the delete path for the target's follows resource" do # rubocop:todo RSpec/MultipleExpectations
expect(button).to include "name=\"_method\" value=\"delete\""
expect(button).to include "action=\"/creators/#{target.to_param}/follows\""
expect(button).to include "action=\"http://test.host/creators/#{target.to_param}/follows\""
end
end
end
+19
View File
@@ -0,0 +1,19 @@
module PhlexTestHelpers
def render(...)
view_context.render(...)
end
delegate :view_context, to: :controller
def controller
@controller ||= ActionView::TestCase::TestController.new
end
def sign_in(user)
allow(controller).to receive(:current_user).and_return(user)
end
end
RSpec.configure do |config|
config.include PhlexTestHelpers, type: :component
end