|
| 1 | +require 'test_helper' |
| 2 | + |
| 3 | +class EventsHelperTest < ActionView::TestCase |
| 4 | + |
| 5 | + test "neatly_printed_date_range" do |
| 6 | + assert_equal '15 April 2023', |
| 7 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 0)), |
| 8 | + 'Should display single date without time if time is midnight' |
| 9 | + |
| 10 | + assert_equal '15 April 2023', |
| 11 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 0), DateTime.new(2023, 4, 15, 0)), |
| 12 | + 'Should display single date without time if time is midnight' |
| 13 | + |
| 14 | + assert_equal '15 April 2023 @ 09:00', |
| 15 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 9)), |
| 16 | + 'Should display single date with single time if no finish date' |
| 17 | + |
| 18 | + assert_equal '15 April 2023 @ 09:00', |
| 19 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 9), DateTime.new(2023, 4, 15, 9)), |
| 20 | + 'Should display single date with single time if both start and finish are the same' |
| 21 | + |
| 22 | + assert_equal '15 April 2023 @ 09:00 - 17:00', |
| 23 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 9), DateTime.new(2023, 4, 15, 17)), |
| 24 | + 'Should display single date with time range' |
| 25 | + |
| 26 | + assert_equal '15 April 2023 @ 00:00 - 00:15', |
| 27 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 0, 0), DateTime.new(2023, 4, 15, 0, 15)), |
| 28 | + 'Should display single date with time range if at least one time is not midnight' |
| 29 | + |
| 30 | + assert_equal '15 April 2023 @ 09:15 - 09:16', |
| 31 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 9, 15), DateTime.new(2023, 4, 15, 9, 16)), |
| 32 | + 'Should display single date with time range' |
| 33 | + |
| 34 | + assert_equal '15 April 2023 @ 09:15 - 21:15', |
| 35 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 9, 15), DateTime.new(2023, 4, 15, 21, 15)), |
| 36 | + 'Should display single date with time range' |
| 37 | + |
| 38 | + assert_equal '15 - 16 April 2023', |
| 39 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 9), DateTime.new(2023, 4, 16, 17)), |
| 40 | + 'Should display date range without time' |
| 41 | + |
| 42 | + assert_equal '15 April - 16 May 2023', |
| 43 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 9), DateTime.new(2023, 5, 16, 17)), |
| 44 | + 'Should display date and month range without time' |
| 45 | + |
| 46 | + assert_equal '15 April 2023 - 16 May 2024', |
| 47 | + neatly_printed_date_range(DateTime.new(2023, 4, 15, 9), DateTime.new(2024, 5, 16, 17)), |
| 48 | + 'Should display date, month and year range without time' |
| 49 | + |
| 50 | + assert_equal '15 April 2023 - 16 May 2024', |
| 51 | + neatly_printed_date_range(DateTime.new(2023, 4, 15), DateTime.new(2024, 5, 16)), |
| 52 | + 'Should display date, month and year range without time' |
| 53 | + |
| 54 | + assert_equal 'No date given', neatly_printed_date_range('', '') |
| 55 | + assert_equal 'No date given', neatly_printed_date_range(nil, '') |
| 56 | + assert_equal 'No start date', neatly_printed_date_range(nil, DateTime.new(2024, 5, 16, 17)) |
| 57 | + end |
| 58 | +end |
0 commit comments