Sha256: efff8871d3b4d9470c3915b4720f6b4e63c908a0394cd83653e40fc6e07682e9

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

require 'test_helper'

class CheckboxTest < ActiveSupport::TestCase

  test "Checkbox requires a parent form" do
    fragment = -> {
      checkbox :permission_granted
    }
    assert_raises(RuntimeError) {
      ExpressTemplates.compile(&fragment)
    }
  end

  test "checkbox places the label before the input" do
    fragment = -> {
      express_form(:account) {
        checkbox :eula
      }
    }
    compiled = ExpressTemplates.compile(&fragment)
    label_helper = '#{label_tag("account_eula", "Eula")}'
    field_helper = '#{check_box(:account, :eula, {}, "1", "0")}'
    assert_match label_helper, compiled
    assert_match field_helper, compiled
    label_idx = compiled.index(label_helper)
    field_idx = compiled.index(field_helper)
    assert (field_idx > label_idx), "label must come first"
  end

  test "checkbox respects label_after: true " do
    fragment = -> {
      express_form(:account) {
        checkbox :eula, label_after: true
      }
    }
    compiled = ExpressTemplates.compile(&fragment)
    label_helper = '#{label_tag("account_eula", "Eula")}'
    field_helper = '#{check_box(:account, :eula, {}, "1", "0")}'
    label_idx = compiled.index(label_helper)
    field_idx = compiled.index(field_helper)
    assert (field_idx < label_idx), "label must come after when label_after: true"
  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/forms/checkbox_test.rb
express_admin-1.2.0 vendor/gems/express_templates/test/components/forms/checkbox_test.rb
express_templates-0.5.0 test/components/forms/checkbox_test.rb
express_templates-0.4.2 test/components/forms/checkbox_test.rb
express_templates-0.4.1 test/components/forms/checkbox_test.rb
express_templates-0.4.0 test/components/forms/checkbox_test.rb