@@ -131,6 +131,64 @@ defmodule NervesHubWeb.Live.Devices.IndexTest do
131131 refute change =~ device3 . identifier
132132 end
133133
134+ test "filters devices with alarms" , % { conn: conn , fixture: fixture } do
135+ % { device: device , firmware: firmware , org: org , product: product } = fixture
136+
137+ device2 = Fixtures . device_fixture ( org , product , firmware )
138+
139+ { :ok , view , html } = live ( conn , device_index_path ( fixture ) )
140+ assert html =~ device . identifier
141+ assert html =~ device2 . identifier
142+ assert html =~ "2 devices found"
143+
144+ device_health = % { "device_id" => device . id , "data" => % { "alarms" => % { "SomeAlarm" => [ ] } } }
145+ assert { :ok , _ } = NervesHub.Devices . save_device_health ( device_health )
146+
147+ change = render_change ( view , "update-filters" , % { "alarm_status" => "with" } )
148+ assert change =~ device . identifier
149+ refute change =~ device2 . identifier
150+ assert change =~ "1 devices found"
151+ end
152+
153+ test "filters devices without alarms" , % { conn: conn , fixture: fixture } do
154+ % { device: device , firmware: firmware , org: org , product: product } = fixture
155+
156+ device2 = Fixtures . device_fixture ( org , product , firmware )
157+
158+ { :ok , view , html } = live ( conn , device_index_path ( fixture ) )
159+ assert html =~ device . identifier
160+ assert html =~ device2 . identifier
161+ assert html =~ "2 devices found"
162+
163+ device_health = % { "device_id" => device . id , "data" => % { "alarms" => % { "SomeAlarm" => [ ] } } }
164+ assert { :ok , _ } = NervesHub.Devices . save_device_health ( device_health )
165+
166+ change = render_change ( view , "update-filters" , % { "alarm_status" => "without" } )
167+ refute change =~ device . identifier
168+ assert change =~ device2 . identifier
169+ assert change =~ "1 devices found"
170+ end
171+
172+ test "filters devices with specific alarm" , % { conn: conn , fixture: fixture } do
173+ % { device: device , firmware: firmware , org: org , product: product } = fixture
174+
175+ device2 = Fixtures . device_fixture ( org , product , firmware )
176+
177+ { :ok , view , html } = live ( conn , device_index_path ( fixture ) )
178+ assert html =~ device . identifier
179+ assert html =~ device2 . identifier
180+ assert html =~ "2 devices found"
181+
182+ alarm = "SomeAlarm"
183+ device_health = % { "device_id" => device . id , "data" => % { "alarms" => % { alarm => [ ] } } }
184+ assert { :ok , _ } = NervesHub.Devices . save_device_health ( device_health )
185+
186+ change = render_change ( view , "update-filters" , % { "alarm" => alarm } )
187+ assert change =~ device . identifier
188+ refute change =~ device2 . identifier
189+ assert change =~ "1 devices found"
190+ end
191+
134192 test "select device" , % { conn: conn , fixture: fixture } do
135193 % { device: _device , firmware: firmware , org: org , product: product } = fixture
136194
0 commit comments