form_configurable_agent_presenter_spec.rb 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. require 'rails_helper'
  2. describe FormConfigurableAgentPresenter do
  3. include RSpecHtmlMatchers
  4. class FormConfigurableAgentPresenterAgent < Agent
  5. include FormConfigurable
  6. form_configurable :string, roles: :validatable
  7. form_configurable :text, type: :text, roles: :completable
  8. form_configurable :boolean, type: :boolean
  9. form_configurable :array, type: :array, values: [1, 2, 3]
  10. end
  11. before(:all) do
  12. @presenter = FormConfigurableAgentPresenter.new(FormConfigurableAgentPresenterAgent.new, ActionController::Base.new.view_context)
  13. end
  14. it "works for the type :string" do
  15. expect(@presenter.option_field_for(:string)).to(
  16. have_tag('input', with: {:'data-attribute' => 'string', role: 'validatable form-configurable', type: 'text', name: 'agent[options][string]'})
  17. )
  18. end
  19. it "works for the type :text" do
  20. expect(@presenter.option_field_for(:text)).to(
  21. have_tag('textarea', with: {:'data-attribute' => 'text', role: 'completable form-configurable', name: 'agent[options][text]'})
  22. )
  23. end
  24. it "works for the type :boolean" do
  25. expect(@presenter.option_field_for(:boolean)).to(
  26. have_tag('input', with: {:'data-attribute' => 'boolean', role: 'form-configurable', name: 'agent[options][boolean_radio]', type: 'radio'})
  27. )
  28. end
  29. it "works for the type :array" do
  30. expect(@presenter.option_field_for(:array)).to(
  31. have_tag('input', with: {:'data-attribute' => 'array', role: 'completable form-configurable', type: 'text', name: 'agent[options][array]'})
  32. )
  33. end
  34. end