Sha256: 688cd385a8ef4651277a1743a5447443f63520ef9f7ab50911541d032461e86a

Contents?: true

Size: 1.83 KB

Versions: 11

Compression:

Stored size: 1.83 KB

Contents

require 'test_helper'

module ExpressAdmin

  class DefinitionListTest < ActiveSupport::TestCase

    def assigns
      {list_types: list_types}
    end

    def helpers
      mock_action_view
    end

    def list_types
      @list_types ||= OpenStruct.new(
        array: ["field1", "field2"],
        hash: {term1: "def1",
               term2: "def2",
               term3: "def3"},
        hash_with_in_words: { "Created At:" => :created_at_in_words })
    end

    def deflist(*args)
      arbre {
        definition_list(:deflist, *args)
      }.to_s
    end

    def deflist_with_resource(*args)
      arbre(widget: Widget.first) {
        definition_list(:widget, *args)
      }.to_s
    end

    test "accepts array as input" do
      assert deflist(list_types[:array])
    end

    test "accepts hash as input" do
      assert deflist(list_types[:hash])
    end

    test "uses keys as labels and values as definitions" do
      assert_match /<dt>Term1/, deflist(list_types[:hash])
    end

    DEFLIST_MARKUP_ARR = <<-HTML
<dl class="definition-list" id="deflist">
  <dt>Field1:</dt>
  <dd>{{resource.field1}}</dd>
  <dt>Field2:</dt>
  <dd>{{resource.field2}}</dd>
</dl>
HTML

    DEFLIST_MARKUP_HASH = <<-HTML
<dl class="definition-list" id="deflist">
  <dt>Term1:</dt>
  <dd>def1</dd>
  <dt>Term2:</dt>
  <dd>def2</dd>
  <dt>Term3:</dt>
  <dd>def3</dd>
</dl>
HTML

    test "definition_list renders correct markup with hash input" do
      assert_equal DEFLIST_MARKUP_HASH, deflist(list_types[:hash])
    end

    test "definition_list renders correct markup with array input" do
      assert_equal DEFLIST_MARKUP_ARR, deflist(list_types[:array])
    end

    test "definition_list renders attribute in words" do
      assert_match "<dt>Created At:</dt>\n  <dd>less than a minute ago</dd>", deflist_with_resource(list_types[:hash_with_in_words])
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
express_admin-2.0.0.b test/dummy/test/components/definition_list_test.rb
express_admin-2.0.0.a test/dummy/test/components/definition_list_test.rb
express_admin-1.8.1 test/dummy/test/components/definition_list_test.rb
express_admin-1.8.0 test/dummy/test/components/definition_list_test.rb
express_admin-1.7.32 test/dummy/test/components/definition_list_test.rb
express_admin-1.7.31 test/dummy/test/components/definition_list_test.rb
express_admin-1.7.30 test/dummy/test/components/definition_list_test.rb
express_admin-1.7.29 test/dummy/test/components/definition_list_test.rb
express_admin-1.7.28 test/dummy/test/components/definition_list_test.rb
express_admin-1.7.27 test/dummy/test/components/definition_list_test.rb
express_admin-1.7.26 test/dummy/test/components/definition_list_test.rb