@@ -127,5 +127,59 @@ defmodule PeekAppSDK.UI.OdysseyTest do
127127 # The Hours button should have the selected styling
128128 assert html =~ "bg-gray-50 text-blue-600"
129129 end
130+
131+ test "renders without fieldset when no label is provided" do
132+ html =
133+ render_component ( & PeekAppSDK.UI.Odyssey . odyssey_toggle_button / 1 , % {
134+ options: [ "Minutes" , "Hours" , "Days" ] ,
135+ selected: "Minutes" ,
136+ on_change: "change_time_unit"
137+ } )
138+
139+ refute html =~ "<fieldset"
140+ refute html =~ "class=\" fieldset mb-2\" "
141+ assert html =~ "class=\" inline-flex rounded-lg\" "
142+ end
143+
144+ test "renders with fieldset and label when label is provided" do
145+ html =
146+ render_component ( & PeekAppSDK.UI.Odyssey . odyssey_toggle_button / 1 , % {
147+ options: [ "Minutes" , "Hours" , "Days" ] ,
148+ selected: "Minutes" ,
149+ on_change: "change_time_unit" ,
150+ label: "Time Unit"
151+ } )
152+
153+ assert html =~ "<fieldset"
154+ assert html =~ "class=\" fieldset mb-2\" "
155+ assert html =~ "<label>"
156+ assert html =~ "<span class=\" label mb-1\" >Time Unit</span>"
157+ assert html =~ "class=\" inline-flex rounded-lg\" "
158+ end
159+
160+ test "form integration passes through label to toggle_button component" do
161+ form_data = % { "channel" => :email }
162+ form = to_form ( form_data , as: "form" )
163+
164+ html =
165+ render_component ( & PeekAppSDK.UI.Odyssey . odyssey_toggle_button / 1 , % {
166+ field: form [ :channel ] ,
167+ label: "Communication Channel" ,
168+ options: [
169+ % { label: "Email" , value: :email } ,
170+ % { label: "Text Message" , value: :sms }
171+ ]
172+ } )
173+
174+ assert html =~ "<fieldset"
175+ assert html =~ "class=\" fieldset mb-2\" "
176+ assert html =~ "<label>"
177+ assert html =~ "<span class=\" label mb-1\" >Communication Channel</span>"
178+ assert html =~ "Email"
179+ assert html =~ "Text Message"
180+ # Should have hidden input for form integration
181+ assert html =~ ~r/ type="hidden"/
182+ assert html =~ ~r/ name="form\[ channel\] "/
183+ end
130184 end
131185end
0 commit comments