# encoding: UTF-8 require 'test_helper' class SimpleFormTest < ActionView::TestCase include SimpleForm::ActionViewExtensions::FormHelper include UiBibz::Helpers::UtilsHelper setup do user = User.where(name_fr: 'test1', name_en: 'test1 en', active: true).first_or_create user.update_attribute(:created_at, "2017-04-26 14:48:43 UTC") user = User.where(name_fr: 'test2', name_en: 'test2 en', active: false).first_or_create user.update_attribute(:created_at, "2017-04-26 14:48:43 UTC") continent = Continent.where(name: 'Europe').first_or_create Country.where(name: 'France', continent_id: continent.id).first_or_create Country.where(name: 'Deutchland', continent_id: continent.id).first_or_create @continents = Continent.all @countries = Country.all @users = User.all @user = @users.first end test 'auto complete field input in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_auto_complete_field, collection: @users, label_method: :name_fr end expected = "
" assert_equal expected, actual end test 'date picker field input in simple form' do actual = simple_form_for @user do |f| f.input :created_at, as: :ui_date_picker_field end expected = "
" assert_equal expected, actual end test 'dropdown field select input in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_dropdown_select_field, collection: @users, label_method: :name_fr end expected = "
" assert_equal expected, actual end test 'dropdown field select input with grouped option in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_dropdown_select_field, collection: @continents, toto: 'lala', grouped: true, group_method: :countries end expected = "
" assert_equal expected, actual end test 'formula field input in simple form' do @user.price = 3.0 @user.price_formula = "1+2" actual = simple_form_for @user do |f| f.input :price, as: :ui_formula_field end expected = "
=
" assert_equal expected, actual end test 'mardown editor field input in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_markdown_editor_field end expected = "
" assert_equal expected, actual end test 'multi column field input in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_multi_column_field, collection: @users, label_method: :name_fr end expected = "
" assert_equal expected, actual end test 'multi select field input in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_multi_select_field, collection: @users, label_method: :name_fr end expected = "
" assert_equal expected, actual end test 'multi select input with grouped option in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_multi_select_field, collection: @continents, toto: 'lala', grouped: true, group_method: :countries end expected = "
" assert_equal expected, actual end test 'text field input in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_text_field end expected = "
" assert_equal expected, actual end test 'switch field input in simple form' do @user.active = true actual = simple_form_for @user do |f| f.input :active, as: :ui_switch_field, collection: @users, label_method: :name_fr end expected = "
" assert_equal expected, actual end test 'radio field input in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_radio_field, collection: @users, label_method: :name_fr end expected = "
" assert_equal expected, actual end test 'select field input in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_select_field, collection: @users, label_method: :name_fr end expected = "
" assert_equal expected, actual end test 'select field input with refresh button in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_select_field, refresh: { target: { data: [] }}, collection: @users, label_method: :name_fr end expected = "
" assert_equal expected, actual end test 'select input with grouped option in simple form' do actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_select_field, collection: @continents, toto: 'lala', grouped: true, group_method: :countries end expected = "
" assert_equal expected, actual end test 'test collection with selected option in select field into simple form' do @user.name_fr = 1 actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_select_field, collection: @countries end expected = "
" assert_equal expected, actual end test 'test collection with selected optiongroup in select field into simple form' do @user.name_fr = 1 actual = simple_form_for @user do |f| f.input :name_fr, as: :ui_select_field, collection: @continents, toto: 'lala', grouped: true, group_method: :countries end expected = "
" assert_equal expected, actual end # test 'test surround field into simple form' do # actual = ui_form_for @user do |f| # concat(f.ui_surround_field do |sf| # sf.input :name_en, as: :text_field # sf.addon("€") # end) # concat f.input(:name_fr, as: :ui_auto_complete_field, collection: @users, label_method: :name_fr) # end # # expected = "
#
" # # assert_equal expected, actual # end end