Sha256: 8fb876d81f915496d932c973e2c13112c56355e80e8d243d246d8b0f2e0b8a74

Contents?: true

Size: 1.72 KB

Versions: 7

Compression:

Stored size: 1.72 KB

Contents

describe "FormController/TemplateRow" do
  tests Formotion::FormController

  # By default, `tests` uses @controller.init
  # this isn't ideal for our case, so override.
  def controller
    row_settings = {
      title: "Add element",
      key: :template,
      type: :template,
      value: ['Value'],
      template: {
        title: 'Element',
        type: :string,
        indented: true,
        deletable: true
      }
    }
    @form ||= Formotion::Form.new(
      sections: [{
        rows:[row_settings]
    }])

    @controller ||= Formotion::FormController.alloc.initWithForm(@form)
  end

  def new_row
    @form.sections.first.rows[-2]
  end

  after do
    @form = nil
    @controller = nil
  end

  it "should work with DSL" do
    @form = Formotion::Form.new

    @form.build_section do |section|
      section.build_row do |row|
        row.title = "Add element"
        row.type = :template
        row.key = :template
        row.value = ["Value 1", "Value 2"]
        row.template = {
          title: 'Element',
          type: :string,
          indented: true,
          deletable: true
        }
      end
    end

    @controller ||= Formotion::FormController.alloc.initWithForm(@form)
    @form.render[:template].should == ['Value 1', 'Value 2']
  end

  it "should insert row" do
    tap("Add element")
    @form.sections.first.rows.size.should == 3
  end

  it "should remove row" do
    tap("Add element")
    new_row.object.on_delete(nil, nil)
    @form.sections.first.rows.size.should == 2
  end

  it "should render values as array" do

    tap("Add element")
    new_row.value = 'Value 2'

    tap("Add element")
    new_row.value = 'Value 3'

    @form.render[:template].should == ['Value', 'Value 2', 'Value 3']
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
formotion-1.8 spec/functional/template_row_spec.rb
formotion-1.7 spec/functional/template_row_spec.rb
formotion-1.6 spec/functional/template_row_spec.rb
formotion-1.5.1 spec/functional/template_row_spec.rb
formotion-1.5.0 spec/functional/template_row_spec.rb
formotion-1.4.0 spec/functional/template_row_spec.rb
formotion-1.3.1 spec/functional/template_row_spec.rb