Skip to content

Commit 1b3052f

Browse files
authored
Add test coverage for custom preview paths (#2294)
* Add test case for rendering preview from lib * add integration test
1 parent e4f0d30 commit 1b3052f

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

test/sandbox/config/application.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Application < Rails::Application
4343
# Prepare test_set_no_duplicate_autoload_paths
4444
config.autoload_paths.push("#{config.root}/my/components/previews")
4545
config.view_component.preview_paths << "#{config.root}/my/components/previews"
46+
config.view_component.preview_paths << "#{Rails.root}/lib/component_previews"
4647
end
4748
end
4849

test/sandbox/config/environments/test.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
config.view_component.show_previews = true
3434

35-
config.view_component.preview_paths << "#{Rails.root}/lib/component_previews"
3635
config.view_component.render_monkey_patch_enabled = true
3736
config.view_component.show_previews_source = true
3837
config.view_component.test_controller = "IntegrationExamplesController"

test/sandbox/test/components/render_preview_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,10 @@ def test_render_preview_unsuffixed
2424

2525
assert_selector("div", text: "subclass")
2626
end
27+
28+
def test_render_preview_custom_path
29+
render_preview(:default, from: MyComponentLibPreview)
30+
31+
assert_selector("div", text: "hello,world!")
32+
end
2733
end

test/sandbox/test/integration_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,4 +787,10 @@ def test_renders_multiple_format_component_as_css
787787

788788
assert_includes response.body, "Hello, CSS!"
789789
end
790+
791+
def test_renders_preview_from_custom_preview_path
792+
get "/rails/view_components/my_component_lib/default"
793+
794+
assert_select "div", "hello,world!"
795+
end
790796
end

0 commit comments

Comments
 (0)