@@ -157,6 +157,76 @@ class ItemStatusTest < ItemsHelperTest
157157 end
158158 end
159159
160+ class DaysUntilDueLabelTest < ItemsHelperTest
161+ def check_out ( item , due_at :)
162+ create ( :loan , :checked_out , :exclusive , item : item , due_at : due_at )
163+ item . reload
164+ end
165+
166+ setup do
167+ travel_to Time . zone . local ( 2026 , 8 , 16 , 10 , 0 , 0 )
168+ end
169+
170+ test "it counts the days until an item is due" do
171+ item = create ( :item )
172+ check_out ( item , due_at : 3 . days . from_now )
173+
174+ assert_dom_equal %(<span class="label item-days-until-due">Due in 3 days</span>) , days_until_due_label ( item )
175+ end
176+
177+ test "it says tomorrow for an item due in one day" do
178+ item = create ( :item )
179+ check_out ( item , due_at : 1 . day . from_now )
180+
181+ assert_dom_equal %(<span class="label item-days-until-due">Due tomorrow</span>) , days_until_due_label ( item )
182+ end
183+
184+ test "it says today for an item due today" do
185+ item = create ( :item )
186+ check_out ( item , due_at : Time . zone . now . end_of_day )
187+
188+ assert_dom_equal %(<span class="label item-days-until-due">Due today</span>) , days_until_due_label ( item )
189+ end
190+
191+ test "it is nothing for an item that isn't checked out" do
192+ assert_nil days_until_due_label ( create ( :item ) )
193+ end
194+
195+ test "it is nothing for an overdue item" do
196+ item = create ( :item )
197+ create ( :overdue_loan , item : item )
198+ item . reload
199+
200+ assert_nil days_until_due_label ( item )
201+ end
202+
203+ test "it is nothing for an item with an active hold" do
204+ item = create ( :item )
205+ check_out ( item , due_at : 3 . days . from_now )
206+ create ( :hold , :active , item : item )
207+ item . reload
208+
209+ assert_nil days_until_due_label ( item )
210+ end
211+
212+ test "it is nothing for an item that can't be held" do
213+ item = create ( :item , holds_enabled : false )
214+ check_out ( item , due_at : 3 . days . from_now )
215+
216+ assert_nil days_until_due_label ( item )
217+ end
218+
219+ [ :maintenance , :retired , :pending , :missing ] . each do |status |
220+ test "it is nothing for an item with status #{ status } " do
221+ item = create ( :item )
222+ check_out ( item , due_at : 3 . days . from_now )
223+ item . update_columns ( status : Item . statuses [ status ] )
224+
225+ assert_nil days_until_due_label ( item . reload )
226+ end
227+ end
228+ end
229+
160230 class ItemStatusOptionsTest < ItemsHelperTest
161231 test "it is all item statuses and descriptions" do
162232 assert_includes item_status_options , [ "Pending (just acquired; not ready to loan)" , "pending" ]
0 commit comments