Sha256: 681e5eb3403b80306cf04fded8c308685d3300e3de9ea8c1e8a5fe2d585f9b57

Contents?: true

Size: 935 Bytes

Versions: 6

Compression:

Stored size: 935 Bytes

Contents

require 'test_helper'

class ConditionalityTest < ActiveSupport::TestCase

  def empty_title_context
    ctx = Object.new
    ctx.instance_variable_set(:@title, '')
    ctx
  end

  def present_title_context
    ctx = Object.new
    ctx.instance_variable_set(:@title, 'Something')
    ctx
  end

  class ConditionalRenderer < ExpressTemplates::Components::Base
    include ExpressTemplates::Components::Capabilities::Conditionality

      emits {
        h1 "{{@title}}"
      }

      only_if -> { !@title.empty? }
  end

  test "when supplied condition is false, renders empty string" do
    compiled_src = ConditionalRenderer.new.compile
    assert_equal '', empty_title_context.instance_eval(compiled_src)
  end

  test "when supplied condition is true, renders the component" do
    compiled_src = ConditionalRenderer.new.compile
    assert_equal '<h1>Something</h1>', present_title_context.instance_eval(compiled_src)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
express_templates-0.2.7 test/components/conditionality_test.rb
express_templates-0.2.6 test/components/conditionality_test.rb
express_templates-0.2.5 test/components/conditionality_test.rb
express_templates-0.2.4 test/components/conditionality_test.rb
express_templates-0.2.3 test/components/conditionality_test.rb
express_templates-0.2.2 test/components/conditionality_test.rb