-
I have a component that uses slots, which I managed to figure out how to render in a preview. I know that in a test environment, it's possible to use The context here is that I am using previews to do some system testing on an isolated basis (inspired by this post: https://wrapbook.engineering/system-testing-view-components.html) of a cart system. The reason is that I am looking to do some in-browser testing. The cart belongs to our main resource, and has some subresources (cart items) that we manipulate. The Cart component contains a I'd love to be able to preview this component so I can do some in-browser testing. Any leads would be appreciated. I've cross posted this to SO as well: https://stackoverflow.com/questions/76773097/rails-url-generation-in-viewcomponent-previews # spec/components/previews/cart_component_preview.rb
class CartComponentPreview < ViewComponent::Preview
def default
user = FactoryBot.create(:user, :with_organizations, org_count: 1)
@resource = FactoryBot.create(:resource, user:)
FactoryBot.create(:cart, resource: @resource)
render(Cart::MainComponent.new(resource: @resource)) do |component|
component.with_subcomponent do
Cart::SubComponent.new(resource: @resource).render_in(component)
end
component.with_info do
Cart::InfoComponent.new(resource: @resource).render_in(component)
end
end
end
end |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
One solution I thought of was instead of using the Rails path helper inside the component, to just string interpolate the path given the information in the component, but that seems like a bad solution. As I think through this more, it does feel like I should just opt to go with a focused system test of the component, rather than try to leverage the preview in the first place. |
Beta Was this translation helpful? Give feedback.
One solution I thought of was instead of using the Rails path helper inside the component, to just string interpolate the path given the information in the component, but that seems like a bad solution.
As I think through this more, it does feel like I should just opt to go with a focused system test of the component, rather than try to leverage the preview in the first place.