Skip to content

Commit

Permalink
Bring back template path test
Browse files Browse the repository at this point in the history
  • Loading branch information
BlakeWilliams committed Oct 16, 2020
1 parent 35b44b1 commit 27a0f87
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions test/view_component/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
require "test_helper"

class ViewComponent::Base::UnitTest < Minitest::Test
# TODO revisit
# def test_templates_parses_all_types_of_paths
# file_path = [
# "/Users/fake.user/path/to.templates/component/test_component.html+phone.erb",
# "/_underscore-dash./component/test_component.html+desktop.slim",
# "/tilda~/component/test_component.html.haml"
# ]
# expected = [
# {variant: :phone, handler: "erb"},
# {variant: :desktop, handler: "slim"},
# {variant: nil, handler: "haml"}
# ]
#
# ViewComponent::Base.stub(:matching_views_in_source_location, file_path) do
# templates = ViewComponent::Base.send(:templates)
#
# templates.each_with_index do |template, index|
# assert_equal(template[:path], file_path[index])
# assert_equal(template[:variant], expected[index][:variant])
# assert_equal(template[:handler], expected[index][:handler])
# end
# end
# end
def test_templates_parses_all_types_of_paths
file_path = [
"/Users/fake.user/path/to.templates/component/test_component.html+phone.erb",
"/_underscore-dash./component/test_component.html+desktop.slim",
"/tilda~/component/test_component.html.haml"
]
expected = [
{variant: :phone, handler: "erb"},
{variant: :desktop, handler: "slim"},
{variant: nil, handler: "haml"}
]

compiler = ViewComponent::Compiler.new(ViewComponent::Base)
compiler.stub(:matching_views_in_source_location, file_path) do
templates = compiler.send(:templates)

templates.each_with_index do |template, index|
assert_equal(template[:path], file_path[index])
assert_equal(template[:variant], expected[index][:variant])
assert_equal(template[:handler], expected[index][:handler])
end
end
end

def test_calling_helpers_outside_render_raises
component = ViewComponent::Base.new
Expand Down

0 comments on commit 27a0f87

Please sign in to comment.