shoelace-rails 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -2
- data/app/helpers/shoelace/components/error_wrappable.rb +21 -0
- data/app/helpers/shoelace/components/sl_checkbox.rb +40 -0
- data/app/helpers/shoelace/components/sl_collection_radio_buttons.rb +47 -0
- data/app/helpers/shoelace/components/sl_color_picker.rb +30 -0
- data/app/helpers/shoelace/components/sl_input.rb +33 -0
- data/app/helpers/shoelace/components/sl_radio_button.rb +20 -0
- data/app/helpers/shoelace/components/sl_range.rb +22 -0
- data/app/helpers/shoelace/components/sl_select.rb +77 -0
- data/app/helpers/shoelace/components/sl_switch.rb +23 -0
- data/app/helpers/shoelace/components/sl_textarea.rb +20 -0
- data/app/helpers/shoelace/form_builder.rb +8 -0
- data/app/helpers/shoelace/sl_form_builder.rb +111 -0
- data/app/helpers/shoelace/sl_form_helper.rb +139 -0
- data/lib/shoelace/rails/version.rb +1 -1
- data/lib/shoelace/railtie.rb +2 -4
- data/test/helpers/form_builder/sl_checkbox_test.rb +45 -0
- data/test/helpers/form_builder/sl_color_picker_test.rb +26 -0
- data/test/helpers/form_builder/sl_input_test.rb +126 -0
- data/test/helpers/form_builder/sl_radio_group_test.rb +63 -0
- data/test/helpers/form_builder/sl_range_test.rb +34 -0
- data/test/helpers/form_builder/sl_select_test.rb +320 -0
- data/test/helpers/form_builder/sl_switch_test.rb +26 -0
- data/test/helpers/form_builder/sl_textarea_test.rb +72 -0
- data/test/helpers/form_builder_test.rb +16 -0
- data/test/helpers/form_helper_test.rb +3 -442
- data/test/helpers/translation_test.rb +12 -4
- data/test/test_helper.rb +22 -0
- metadata +25 -4
- data/app/helpers/shoelace/form_helper.rb +0 -408
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
require_relative '../../../app/helpers/shoelace/sl_form_helper'
|
5
|
+
|
6
|
+
class FormBuilderSlCheckboxTest < ActionView::TestCase
|
7
|
+
include Shoelace::SlFormHelper
|
8
|
+
|
9
|
+
test "#check_box" do
|
10
|
+
sl_form_for(User.new, url: "/") do |form|
|
11
|
+
assert_dom_equal <<~HTML, form.check_box(:name)
|
12
|
+
<input name="user[name]" type="hidden" value="0" #{AUTOCOMPLETE_ATTRIBUTE} />
|
13
|
+
<sl-checkbox value="1" name="user[name]" id="user_name">Name</sl-checkbox>
|
14
|
+
HTML
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
test "#check_box with an invalid value" do
|
19
|
+
yuki = User.new.tap(&:validate)
|
20
|
+
|
21
|
+
sl_form_for(yuki, url: "/") do |form|
|
22
|
+
assert_dom_equal <<~HTML, form.check_box(:name)
|
23
|
+
<input name="user[name]" type="hidden" value="0" #{AUTOCOMPLETE_ATTRIBUTE} />
|
24
|
+
<sl-checkbox value="1" name="user[name]" id="user_name" data-invalid="" invalid="">Name</sl-checkbox>
|
25
|
+
HTML
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test "#check_box with a block" do
|
30
|
+
sl_form_for(User.new, url: "/") do |form|
|
31
|
+
assert_dom_equal <<~HTML, form.check_box(:name) { "Maintainer Name" }
|
32
|
+
<input name="user[name]" type="hidden" value="0" #{AUTOCOMPLETE_ATTRIBUTE} />
|
33
|
+
<sl-checkbox value="1" name="user[name]" id="user_name">Maintainer Name</sl-checkbox>
|
34
|
+
HTML
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
test "#check_box without a hidden input" do
|
39
|
+
sl_form_for(User.new, url: "/") do |form|
|
40
|
+
assert_dom_equal <<~HTML, form.check_box(:name, include_hidden: false) { "Maintainer Name" }
|
41
|
+
<sl-checkbox value="1" name="user[name]" id="user_name">Maintainer Name</sl-checkbox>
|
42
|
+
HTML
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
require_relative '../../../app/helpers/shoelace/sl_form_helper'
|
5
|
+
|
6
|
+
class FormBuilderSlColorPickerTest < ActionView::TestCase
|
7
|
+
include Shoelace::SlFormHelper
|
8
|
+
|
9
|
+
test "#color_field" do
|
10
|
+
sl_form_for(User.new, url: "/") do |form|
|
11
|
+
assert_dom_equal <<~HTML, form.color_field(:name)
|
12
|
+
<sl-color-picker name="user[name]" id="user_name" label="Name"></sl-color-picker>
|
13
|
+
HTML
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test "#color_field with an invalid value" do
|
18
|
+
yuki = User.new.tap(&:validate)
|
19
|
+
|
20
|
+
sl_form_for(yuki, url: "/") do |form|
|
21
|
+
assert_dom_equal <<~HTML, form.color_field(:name)
|
22
|
+
<sl-color-picker name="user[name]" id="user_name" label="Name" data-invalid="" invalid=""></sl-color-picker>
|
23
|
+
HTML
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
require_relative '../../../app/helpers/shoelace/sl_form_helper'
|
5
|
+
|
6
|
+
class FormBuilderSlInputTest < ActionView::TestCase
|
7
|
+
include Shoelace::SlFormHelper
|
8
|
+
|
9
|
+
test "#text_field" do
|
10
|
+
sl_form_for(User.new, url: "/") do |form|
|
11
|
+
assert_dom_equal <<~HTML, form.text_field(:name)
|
12
|
+
<sl-input label="Name" type="text" name="user[name]" id="user_name"></sl-input>
|
13
|
+
HTML
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test "#text_field with a default value" do
|
18
|
+
sl_form_for(User.new(name: "Yuki"), url: "/") do |form|
|
19
|
+
assert_dom_equal <<~HTML, form.text_field(:name)
|
20
|
+
<sl-input label="Name" type="text" name="user[name]" id="user_name" value="Yuki"></sl-input>
|
21
|
+
HTML
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
test "#text_field with an invalid value" do
|
26
|
+
yuki = User.new.tap(&:validate)
|
27
|
+
|
28
|
+
sl_form_for(yuki, url: "/") do |form|
|
29
|
+
assert_dom_equal <<~HTML, form.text_field(:name)
|
30
|
+
<sl-input label="Name" type="text" name="user[name]" id="user_name" data-invalid="" invalid=""></sl-input>
|
31
|
+
HTML
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
test "#date_field" do
|
36
|
+
sl_form_for(User.new, url: "/") do |form|
|
37
|
+
assert_dom_equal <<~HTML, form.date_field(:name)
|
38
|
+
<sl-input label="Name" type="date" name="user[name]" id="user_name"></sl-input>
|
39
|
+
HTML
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
test "#email_field" do
|
44
|
+
sl_form_for(User.new, url: "/") do |form|
|
45
|
+
assert_dom_equal <<~HTML, form.email_field(:name)
|
46
|
+
<sl-input label="Name" type="email" name="user[name]" id="user_name"></sl-input>
|
47
|
+
HTML
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
test "#number_field" do
|
52
|
+
sl_form_for(User.new, url: "/") do |form|
|
53
|
+
assert_dom_equal <<~HTML, form.number_field(:name)
|
54
|
+
<sl-input label="Name" type="number" name="user[name]" id="user_name"></sl-input>
|
55
|
+
HTML
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test "#password_field" do
|
60
|
+
sl_form_for(User.new, url: "/") do |form|
|
61
|
+
assert_dom_equal <<~HTML, form.password_field(:name)
|
62
|
+
<sl-input label="Name" type="password" name="user[name]" id="user_name"></sl-input>
|
63
|
+
HTML
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
test "#search_field" do
|
68
|
+
sl_form_for(User.new, url: "/") do |form|
|
69
|
+
assert_dom_equal <<~HTML, form.search_field(:name)
|
70
|
+
<sl-input label="Name" type="search" name="user[name]" id="user_name"></sl-input>
|
71
|
+
HTML
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
test "#telephone_field" do
|
76
|
+
sl_form_for(User.new, url: "/") do |form|
|
77
|
+
assert_dom_equal <<~HTML, form.telephone_field(:name)
|
78
|
+
<sl-input label="Name" type="tel" name="user[name]" id="user_name"></sl-input>
|
79
|
+
HTML
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
test "#phone_field" do
|
84
|
+
sl_form_for(User.new, url: "/") do |form|
|
85
|
+
assert_dom_equal <<~HTML, form.phone_field(:name)
|
86
|
+
<sl-input label="Name" type="tel" name="user[name]" id="user_name"></sl-input>
|
87
|
+
HTML
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
test "#text_field with a block" do
|
92
|
+
sl_form_for(User.new(name: "Yuki"), url: "/") do |form|
|
93
|
+
assert_dom_equal <<~HTML, form.text_field(:name) { 'slot' }
|
94
|
+
<sl-input label="Name" type="text" name="user[name]" id="user_name" value="Yuki">slot</sl-input>
|
95
|
+
HTML
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
test "#text_field with a default help text block" do
|
100
|
+
with_default_input_slot_method do
|
101
|
+
sl_form_for(User.new(name: "Yuki"), url: "/") do |form|
|
102
|
+
assert_dom_equal <<~HTML, form.text_field(:name)
|
103
|
+
<sl-input label="Name" type="text" name="user[name]" id="user_name" value="Yuki">
|
104
|
+
<div slot="help-text">Help text for name Yuki</div>
|
105
|
+
</sl-input>
|
106
|
+
HTML
|
107
|
+
end
|
108
|
+
|
109
|
+
sl_form_for(User.new(name: "Yuki"), url: "/") do |form|
|
110
|
+
assert_dom_equal <<~HTML, form.text_field(:name) { "slot" }
|
111
|
+
<sl-input label="Name" type="text" name="user[name]" id="user_name" value="Yuki">
|
112
|
+
slot
|
113
|
+
</sl-input>
|
114
|
+
HTML
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
test "#url_field" do
|
120
|
+
sl_form_for(User.new, url: "/") do |form|
|
121
|
+
assert_dom_equal <<~HTML, form.url_field(:name)
|
122
|
+
<sl-input label="Name" type="url" name="user[name]" id="user_name"></sl-input>
|
123
|
+
HTML
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
require_relative '../../../app/helpers/shoelace/sl_form_helper'
|
5
|
+
|
6
|
+
class FormBuilderSlRadioGroupTest < ActionView::TestCase
|
7
|
+
include Shoelace::SlFormHelper
|
8
|
+
|
9
|
+
test "#collection_radio_buttons" do
|
10
|
+
users = {
|
11
|
+
1 => "Yuki Nishijima",
|
12
|
+
2 => "Matz",
|
13
|
+
3 => "Koichi Sasada",
|
14
|
+
}
|
15
|
+
|
16
|
+
sl_form_for(User.new, url: "/") do |form|
|
17
|
+
assert_dom_equal <<~HTML, form.collection_radio_buttons(:name, users, :first, :last)
|
18
|
+
<sl-radio-group label="Name" name="user[name]" id="user_name">
|
19
|
+
<sl-radio value="1" id="user_name_1">Yuki Nishijima</sl-radio>
|
20
|
+
<sl-radio value="2" id="user_name_2">Matz</sl-radio>
|
21
|
+
<sl-radio value="3" id="user_name_3">Koichi Sasada</sl-radio>
|
22
|
+
</sl-radio-group>
|
23
|
+
HTML
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test "#collection_radio_buttons with an invalid value" do
|
28
|
+
yuki = User.new.tap(&:validate)
|
29
|
+
users = {
|
30
|
+
1 => "Yuki Nishijima",
|
31
|
+
2 => "Matz",
|
32
|
+
3 => "Koichi Sasada",
|
33
|
+
}
|
34
|
+
|
35
|
+
sl_form_for(yuki, url: "/") do |form|
|
36
|
+
assert_dom_equal <<~HTML, form.collection_radio_buttons(:name, users, :first, :last)
|
37
|
+
<sl-radio-group label="Name" name="user[name]" id="user_name" data-invalid="" invalid="">
|
38
|
+
<sl-radio value="1" id="user_name_1">Yuki Nishijima</sl-radio>
|
39
|
+
<sl-radio value="2" id="user_name_2">Matz</sl-radio>
|
40
|
+
<sl-radio value="3" id="user_name_3">Koichi Sasada</sl-radio>
|
41
|
+
</sl-radio-group>
|
42
|
+
HTML
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
test "#collection_radio_buttons with a default value" do
|
47
|
+
users = {
|
48
|
+
1 => "Yuki Nishijima",
|
49
|
+
2 => "Matz",
|
50
|
+
3 => "Koichi Sasada",
|
51
|
+
}
|
52
|
+
|
53
|
+
sl_form_for(User.new(name: 1), url: "/") do |form|
|
54
|
+
assert_dom_equal <<~HTML, form.collection_radio_buttons(:name, users, :first, :last)
|
55
|
+
<sl-radio-group label="Name" name="user[name]" value="1" id="user_name">
|
56
|
+
<sl-radio value="1" id="user_name_1">Yuki Nishijima</sl-radio>
|
57
|
+
<sl-radio value="2" id="user_name_2">Matz</sl-radio>
|
58
|
+
<sl-radio value="3" id="user_name_3">Koichi Sasada</sl-radio>
|
59
|
+
</sl-radio-group>
|
60
|
+
HTML
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
require_relative '../../../app/helpers/shoelace/sl_form_helper'
|
5
|
+
|
6
|
+
class FormBuilderSlRangeTest < ActionView::TestCase
|
7
|
+
include Shoelace::SlFormHelper
|
8
|
+
|
9
|
+
test "#range_field" do
|
10
|
+
sl_form_for(User.new, url: "/") do |form|
|
11
|
+
assert_dom_equal <<~HTML, form.range_field(:name)
|
12
|
+
<sl-range label="Name" name="user[name]" id="user_name"></sl-range>
|
13
|
+
HTML
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test "#range_field with an invalid value" do
|
18
|
+
yuki = User.new.tap(&:validate)
|
19
|
+
|
20
|
+
sl_form_for(yuki, url: "/") do |form|
|
21
|
+
assert_dom_equal <<~HTML, form.range_field(:name)
|
22
|
+
<sl-range label="Name" name="user[name]" id="user_name" data-invalid="" invalid=""></sl-range>
|
23
|
+
HTML
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test "#range_field without a label" do
|
28
|
+
sl_form_for(User.new, url: "/") do |form|
|
29
|
+
assert_dom_equal <<~HTML, form.range_field(:name, label: nil)
|
30
|
+
<sl-range name="user[name]" id="user_name"></sl-range>
|
31
|
+
HTML
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,320 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
require_relative '../../../app/helpers/shoelace/sl_form_helper'
|
5
|
+
|
6
|
+
class FormBuilderSlSelectTest < ActionView::TestCase
|
7
|
+
include Shoelace::SlFormHelper
|
8
|
+
|
9
|
+
test "#select" do
|
10
|
+
users = {
|
11
|
+
"Yuki Nishijima" => 1,
|
12
|
+
"Matz" => 2,
|
13
|
+
"Koichi Sasada" => 3
|
14
|
+
}
|
15
|
+
|
16
|
+
sl_form_for(User.new, url: "/") do |form|
|
17
|
+
assert_dom_equal <<~HTML, form.select(:name, users)
|
18
|
+
<sl-select label="Name" name="user[name]" id="user_name">
|
19
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
20
|
+
<sl-option value="2">Matz</sl-option>
|
21
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
22
|
+
</sl-select>
|
23
|
+
HTML
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test "#select with an invalid value" do
|
28
|
+
yuki = User.new.tap(&:validate)
|
29
|
+
users = {
|
30
|
+
"Yuki Nishijima" => 1,
|
31
|
+
"Matz" => 2,
|
32
|
+
"Koichi Sasada" => 3
|
33
|
+
}
|
34
|
+
|
35
|
+
sl_form_for(yuki, url: "/") do |form|
|
36
|
+
assert_dom_equal <<~HTML, form.select(:name, users)
|
37
|
+
<sl-select label="Name" name="user[name]" id="user_name" data-invalid="" invalid="">
|
38
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
39
|
+
<sl-option value="2">Matz</sl-option>
|
40
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
41
|
+
</sl-select>
|
42
|
+
HTML
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
test "#select with a default help text block" do
|
47
|
+
with_default_input_slot_method do
|
48
|
+
sl_form_for(User.new, url: "/") do |form|
|
49
|
+
assert_dom_equal <<~HTML, form.select(:name, "Yuki Nishijima" => 1)
|
50
|
+
<sl-select label="Name" name="user[name]" id="user_name">
|
51
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
52
|
+
<div slot="help-text">Help text for name</div>
|
53
|
+
</sl-select>
|
54
|
+
HTML
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
test "#select with a block that does not return anything" do
|
60
|
+
sl_form_for(User.new, url: "/") do |form|
|
61
|
+
assert_dom_equal <<~HTML, form.select(:name, "Yuki Nishijima" => 1) { }
|
62
|
+
<sl-select label="Name" name="user[name]" id="user_name">
|
63
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
64
|
+
</sl-select>
|
65
|
+
HTML
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
test "#select with a custom value" do
|
70
|
+
users = {
|
71
|
+
"Yuki Nishijima" => 1,
|
72
|
+
"Matz" => 2,
|
73
|
+
"Koichi Sasada" => 3
|
74
|
+
}
|
75
|
+
|
76
|
+
sl_form_for(User.new, url: "/") do |form|
|
77
|
+
assert_dom_equal <<~HTML, form.select(:name, users, {}, { value: 3 })
|
78
|
+
<sl-select label="Name" value="3" name="user[name]" id="user_name">
|
79
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
80
|
+
<sl-option value="2">Matz</sl-option>
|
81
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
82
|
+
</sl-select>
|
83
|
+
HTML
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
test "#select with custom selected and disabled values" do
|
88
|
+
users = {
|
89
|
+
"Yuki Nishijima" => 1,
|
90
|
+
"Matz" => 2,
|
91
|
+
"Koichi Sasada" => 3
|
92
|
+
}
|
93
|
+
|
94
|
+
sl_form_for(User.new, url: "/") do |form|
|
95
|
+
assert_dom_equal <<~HTML, form.select(:name, users, selected: 3, disabled: 1)
|
96
|
+
<sl-select label="Name" name="user[name]" id="user_name">
|
97
|
+
<sl-option value="1" disabled="disabled">Yuki Nishijima</sl-option>
|
98
|
+
<sl-option value="2">Matz</sl-option>
|
99
|
+
<sl-option value="3" checked="checked">Koichi Sasada</sl-option>
|
100
|
+
</sl-select>
|
101
|
+
HTML
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
test "#select with multiple" do
|
106
|
+
users = {
|
107
|
+
"Yuki Nishijima" => 1,
|
108
|
+
"Matz" => 2,
|
109
|
+
"Koichi Sasada" => 3
|
110
|
+
}
|
111
|
+
|
112
|
+
sl_form_for(User.new, url: "/") do |form|
|
113
|
+
assert_dom_equal <<~HTML, form.select(:name, users, {}, { multiple: true })
|
114
|
+
<sl-select label="Name" name="user[name][]" id="user_name" multiple="multiple">
|
115
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
116
|
+
<sl-option value="2">Matz</sl-option>
|
117
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
118
|
+
</sl-select>
|
119
|
+
HTML
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
test "#select with grouped options" do
|
124
|
+
users = {
|
125
|
+
"Main maintainers" => [
|
126
|
+
["Matz", 2],
|
127
|
+
["Koichi Sasada", 3]
|
128
|
+
],
|
129
|
+
"Default gem maintainers" => [
|
130
|
+
["Yuki Nishijima", 1],
|
131
|
+
]
|
132
|
+
}
|
133
|
+
|
134
|
+
sl_form_for(User.new, url: "/") do |form|
|
135
|
+
assert_dom_equal <<~HTML, form.select(:name, users)
|
136
|
+
<sl-select label="Name" name="user[name]" id="user_name">
|
137
|
+
<small>Main maintainers</small>
|
138
|
+
<sl-option value="2">Matz</sl-option>
|
139
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
140
|
+
<sl-divider></sl-divider>
|
141
|
+
<small>Default gem maintainers</small>
|
142
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
143
|
+
</sl-select>
|
144
|
+
HTML
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
test "#select with grouped options with a default value" do
|
149
|
+
users = {
|
150
|
+
"Main maintainers" => [
|
151
|
+
["Matz", 2],
|
152
|
+
["Koichi Sasada", 3]
|
153
|
+
],
|
154
|
+
"Default gem maintainers" => [
|
155
|
+
["Yuki Nishijima", 1],
|
156
|
+
]
|
157
|
+
}
|
158
|
+
|
159
|
+
sl_form_for(User.new(name: 2), url: "/") do |form|
|
160
|
+
assert_dom_equal <<~HTML, form.select(:name, users)
|
161
|
+
<sl-select label="Name" name="user[name]" id="user_name" value="2">
|
162
|
+
<small>Main maintainers</small>
|
163
|
+
<sl-option value="2" checked="checked">Matz</sl-option>
|
164
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
165
|
+
<sl-divider></sl-divider>
|
166
|
+
<small>Default gem maintainers</small>
|
167
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
168
|
+
</sl-select>
|
169
|
+
HTML
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
test "#collection_select" do
|
174
|
+
users = {
|
175
|
+
1 => "Yuki Nishijima",
|
176
|
+
2 => "Matz",
|
177
|
+
3 => "Koichi Sasada",
|
178
|
+
}
|
179
|
+
|
180
|
+
sl_form_for(User.new, url: "/") do |form|
|
181
|
+
assert_dom_equal <<~HTML, form.collection_select(:name, users, :first, :last)
|
182
|
+
<sl-select label="Name" name="user[name]" id="user_name">
|
183
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
184
|
+
<sl-option value="2">Matz</sl-option>
|
185
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
186
|
+
</sl-select>
|
187
|
+
HTML
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
test "#collection_select with a default help text block" do
|
192
|
+
with_default_input_slot_method do
|
193
|
+
sl_form_for(User.new, url: "/") do |form|
|
194
|
+
assert_dom_equal <<~HTML, form.collection_select(:name, { 1 => "Yuki Nishijima" }, :first, :last)
|
195
|
+
<sl-select label="Name" name="user[name]" id="user_name">
|
196
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
197
|
+
<div slot="help-text">Help text for name </div>
|
198
|
+
</sl-select>
|
199
|
+
HTML
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
test "#collection_select with an invalid value" do
|
205
|
+
yuki = User.new.tap(&:validate)
|
206
|
+
users = {
|
207
|
+
1 => "Yuki Nishijima",
|
208
|
+
2 => "Matz",
|
209
|
+
3 => "Koichi Sasada",
|
210
|
+
}
|
211
|
+
|
212
|
+
sl_form_for(yuki, url: "/") do |form|
|
213
|
+
assert_dom_equal <<~HTML, form.collection_select(:name, users, :first, :last)
|
214
|
+
<sl-select label="Name" name="user[name]" id="user_name" data-invalid="" invalid="">
|
215
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
216
|
+
<sl-option value="2">Matz</sl-option>
|
217
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
218
|
+
</sl-select>
|
219
|
+
HTML
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
test "#collection_select with a default value" do
|
224
|
+
users = {
|
225
|
+
1 => "Yuki Nishijima",
|
226
|
+
2 => "Matz",
|
227
|
+
3 => "Koichi Sasada",
|
228
|
+
}
|
229
|
+
|
230
|
+
sl_form_for(User.new(name: "2"), url: "/") do |form|
|
231
|
+
assert_dom_equal <<~HTML, form.collection_select(:name, users, :first, :last)
|
232
|
+
<sl-select label="Name" name="user[name]" id="user_name" value="2">
|
233
|
+
<sl-option value="1">Yuki Nishijima</sl-option>
|
234
|
+
<sl-option value="2" checked="checked">Matz</sl-option>
|
235
|
+
<sl-option value="3">Koichi Sasada</sl-option>
|
236
|
+
</sl-select>
|
237
|
+
HTML
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
test "#grouped_collection_select" do
|
242
|
+
users = [
|
243
|
+
OpenStruct.new(
|
244
|
+
group_name: "Main maintainers",
|
245
|
+
members: [
|
246
|
+
OpenStruct.new(id: 1, name: "Matz"),
|
247
|
+
OpenStruct.new(id: 2, name: "Koichi Sasada"),
|
248
|
+
]
|
249
|
+
),
|
250
|
+
OpenStruct.new(
|
251
|
+
group_name: "Default gem maintainers",
|
252
|
+
members: [OpenStruct.new(id: 3, name: "Yuki Nishijima")]
|
253
|
+
),
|
254
|
+
]
|
255
|
+
|
256
|
+
sl_form_for(User.new(name: "2"), url: "/") do |form|
|
257
|
+
assert_dom_equal <<~HTML, form.grouped_collection_select(:name, users, :members, :group_name, :id, :name)
|
258
|
+
<sl-select label="Name" name="user[name]" id="user_name" value="2">
|
259
|
+
<small>Main maintainers</small>
|
260
|
+
<sl-option value="1">Matz</sl-option>
|
261
|
+
<sl-option value="2" checked="checked">Koichi Sasada</sl-option>
|
262
|
+
<sl-divider></sl-divider>
|
263
|
+
<small>Default gem maintainers</small>
|
264
|
+
<sl-option value="3">Yuki Nishijima</sl-option>
|
265
|
+
</sl-select>
|
266
|
+
HTML
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
test "#grouped_collection_select with a default help text block" do
|
271
|
+
users = [
|
272
|
+
OpenStruct.new(
|
273
|
+
group_name: "Default gem maintainers",
|
274
|
+
members: [OpenStruct.new(id: 3, name: "Yuki Nishijima")]
|
275
|
+
),
|
276
|
+
]
|
277
|
+
|
278
|
+
with_default_input_slot_method do
|
279
|
+
sl_form_for(User.new(name: "2"), url: "/") do |form|
|
280
|
+
assert_dom_equal <<~HTML, form.grouped_collection_select(:name, users, :members, :group_name, :id, :name)
|
281
|
+
<sl-select label="Name" name="user[name]" id="user_name" value="2">
|
282
|
+
<small>Default gem maintainers</small>
|
283
|
+
<sl-option value="3">Yuki Nishijima</sl-option>
|
284
|
+
<div slot="help-text">Help text for name 2</div>
|
285
|
+
</sl-select>
|
286
|
+
HTML
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
test "#grouped_collection_select with an invalid value" do
|
292
|
+
yuki = User.new.tap(&:validate)
|
293
|
+
users = [
|
294
|
+
OpenStruct.new(
|
295
|
+
group_name: "Main maintainers",
|
296
|
+
members: [
|
297
|
+
OpenStruct.new(id: 1, name: "Matz"),
|
298
|
+
OpenStruct.new(id: 2, name: "Koichi Sasada"),
|
299
|
+
]
|
300
|
+
),
|
301
|
+
OpenStruct.new(
|
302
|
+
group_name: "Default gem maintainers",
|
303
|
+
members: [OpenStruct.new(id: 3, name: "Yuki Nishijima")]
|
304
|
+
),
|
305
|
+
]
|
306
|
+
|
307
|
+
sl_form_for(yuki, url: "/") do |form|
|
308
|
+
assert_dom_equal <<~HTML, form.grouped_collection_select(:name, users, :members, :group_name, :id, :name)
|
309
|
+
<sl-select label="Name" name="user[name]" id="user_name" data-invalid="" invalid="">
|
310
|
+
<small>Main maintainers</small>
|
311
|
+
<sl-option value="1">Matz</sl-option>
|
312
|
+
<sl-option value="2">Koichi Sasada</sl-option>
|
313
|
+
<sl-divider></sl-divider>
|
314
|
+
<small>Default gem maintainers</small>
|
315
|
+
<sl-option value="3">Yuki Nishijima</sl-option>
|
316
|
+
</sl-select>
|
317
|
+
HTML
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
require_relative '../../../app/helpers/shoelace/sl_form_helper'
|
5
|
+
|
6
|
+
class FormBuilderSlRangeTest < ActionView::TestCase
|
7
|
+
include Shoelace::SlFormHelper
|
8
|
+
|
9
|
+
test "#switch_field" do
|
10
|
+
sl_form_for(User.new, url: "/") do |form|
|
11
|
+
assert_dom_equal <<~HTML, form.switch_field(:name)
|
12
|
+
<sl-switch name="user[name]" id="user_name">Name</sl-switch>
|
13
|
+
HTML
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test "#switch_field with an invalid value" do
|
18
|
+
yuki = User.new.tap(&:validate)
|
19
|
+
|
20
|
+
sl_form_for(yuki, url: "/") do |form|
|
21
|
+
assert_dom_equal <<~HTML, form.switch_field(:name)
|
22
|
+
<sl-switch name="user[name]" id="user_name" data-invalid="" invalid="">Name</sl-switch>
|
23
|
+
HTML
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|