Sha256: e4e1681c15a93e133dd199a21ab9ceb4ee92fd20c01e7f7384cf59ab6644d724

Contents?: true

Size: 1.63 KB

Versions: 6

Compression:

Stored size: 1.63 KB

Contents

require 'test_helper'
require 'minitest/mock'

class ContainerTest < ActiveSupport::TestCase

  ETC = ExpressTemplates::Components

  def any_container
    Class.new(ETC::Container)
  end

  test "a Container is a Component" do
    assert_kind_of ETC::Base, any_container.new
  end

  test "a container has children but initially has none" do
    assert any_container.new.respond_to?(:children)
    assert_equal [], any_container.new.children
  end

  def mock_children
    child1, child2 = Minitest::Mock.new, Minitest::Mock.new
    child1.expect(:compile, '"one"')
    child2.expect(:compile, '"two"')
    child1.expect(:kind_of?, false, [ExpressTemplates::Components::Capabilities::Adoptable])
    child2.expect(:kind_of?, false, [ExpressTemplates::Components::Capabilities::Adoptable])
    return child1, child2
  end

  class TestContainer < ETC::Container
    emits -> { p { _yield } }
  end

  test "Container#compile calls #compile on its children" do
    container = TestContainer.new
    child1, child2 = mock_children
    container.children = [child1, child2]
    container.compile
    child1.verify
    child2.verify
  end

  test "renders children in place of _yield" do
    container = TestContainer.new
    child1, child2 = mock_children
    container.children = [child1, child2]

    assert_equal "<p>onetwo</p>", eval(container.compile)
  end

  class Context
    def a_helper
      "foo"
    end
  end

  test "children with interpolations" do
    markup = ExpressTemplates.render(Context.new) do
      row {
        p %q(Should say: {{a_helper}}.)
      }
    end
    assert_equal "<div class=\"row\"><p>Should say: foo.</p></div>", markup
  end

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
express_admin-1.2.1 vendor/gems/express_templates/test/components/container_test.rb
express_admin-1.2.0 vendor/gems/express_templates/test/components/container_test.rb
express_templates-0.5.0 test/components/container_test.rb
express_templates-0.4.2 test/components/container_test.rb
express_templates-0.4.1 test/components/container_test.rb
express_templates-0.4.0 test/components/container_test.rb