forked from heartcombo/simple_form
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadonly_test.rb
102 lines (83 loc) · 3.96 KB
/
readonly_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# frozen_string_literal: true
require 'test_helper'
class ReadonlyTest < ActionView::TestCase
test 'string input generates readonly elements when readonly option is true' do
with_input_for @user, :name, :string, readonly: true
assert_select 'input.string.readonly[readonly]'
end
test 'text input generates readonly elements when readonly option is true' do
with_input_for @user, :description, :text, readonly: true
assert_select 'textarea.text.readonly[readonly]'
end
test 'numeric input generates readonly elements when readonly option is true' do
with_input_for @user, :age, :integer, readonly: true
assert_select 'input.integer.readonly[readonly]'
end
test 'date input generates readonly elements when readonly option is true' do
with_input_for @user, :born_at, :date, readonly: true
assert_select 'select.date.readonly[readonly]'
end
test 'datetime input generates readonly elements when readonly option is true' do
with_input_for @user, :created_at, :datetime, readonly: true
assert_select 'select.datetime.readonly[readonly]'
end
test 'string input generates readonly elements when readonly option is false' do
with_input_for @user, :name, :string, readonly: false
assert_no_select 'input.string.readonly[readonly]'
end
test 'text input generates readonly elements when readonly option is false' do
with_input_for @user, :description, :text, readonly: false
assert_no_select 'textarea.text.readonly[readonly]'
end
test 'numeric input generates readonly elements when readonly option is false' do
with_input_for @user, :age, :integer, readonly: false
assert_no_select 'input.integer.readonly[readonly]'
end
test 'date input generates readonly elements when readonly option is false' do
with_input_for @user, :born_at, :date, readonly: false
assert_no_select 'select.date.readonly[readonly]'
end
test 'datetime input generates readonly elements when readonly option is false' do
with_input_for @user, :created_at, :datetime, readonly: false
assert_no_select 'select.datetime.readonly[readonly]'
end
test 'string input generates readonly elements when readonly option is not present' do
with_input_for @user, :name, :string
assert_no_select 'input.string.readonly[readonly]'
end
test 'text input generates readonly elements when readonly option is not present' do
with_input_for @user, :description, :text
assert_no_select 'textarea.text.readonly[readonly]'
end
test 'numeric input generates readonly elements when readonly option is not present' do
with_input_for @user, :age, :integer
assert_no_select 'input.integer.readonly[readonly]'
end
test 'date input generates readonly elements when readonly option is not present' do
with_input_for @user, :born_at, :date
assert_no_select 'select.date.readonly[readonly]'
end
test 'datetime input generates readonly elements when readonly option is not present' do
with_input_for @user, :created_at, :datetime
assert_no_select 'select.datetime.readonly[readonly]'
end
test 'input generates readonly attribute when the field is readonly and the object is persisted' do
with_input_for @user, :credit_card, :string, readonly: :lookup
assert_select 'input.string.readonly[readonly]'
end
test 'input does not generate readonly attribute when the field is readonly and the object is not persisted' do
@user.new_record!
with_input_for @user, :credit_card, :string, readonly: :lookup
assert_no_select 'input.string.readonly[readonly]'
end
test 'input does not generate readonly attribute when the field is not readonly and the object is persisted' do
with_input_for @user, :name, :string
assert_no_select 'input.string.readonly[readonly]'
end
test 'input does not generate readonly attribute when the component is not used' do
swap_wrapper do
with_input_for @user, :credit_card, :string
assert_no_select 'input.string.readonly[readonly]'
end
end
end