Browse Source

Maintenance: Stabilise relative date on leap year test

Mantas 1 year ago
parent
commit
6ba710e740
2 changed files with 8 additions and 2 deletions
  1. 4 1
      spec/support/time_helper.rb
  2. 4 1
      spec/system/ticket/create_spec.rb

+ 4 - 1
spec/support/time_helper.rb

@@ -21,7 +21,7 @@ module TimeHelperCache
 
   # Reimplementation of `setMonth(month[, date])` from the ECMAScript specification.
   #   https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date.prototype.setmonth
-  def frontend_relative_month(obj, month, date = nil)
+  def frontend_relative_month(obj, month, date = nil, year: nil)
     # 1. Let t be ? thisTimeValue(this value).
     t = obj
 
@@ -51,6 +51,9 @@ module TimeHelperCache
       new_year += 1
       new_month -= 12
     end
+
+    new_year += year if year
+
     Time.zone.local(new_year, new_month, dt, t.hour, t.min, t.sec)
 
     # Ignore the rest, as `Time#local` already handles it correctly:

+ 4 - 1
spec/system/ticket/create_spec.rb

@@ -1095,8 +1095,11 @@ RSpec.describe 'Ticket Create', type: :system do
           # Since front-end uses a JS-specific function to add a month value to the current date,
           #   calculating the value here with Ruby code may lead to unexpected values.
           #   Therefore, we use a reimplementation of the ECMAScript function instead.
-          if range == 'month'
+          case range
+          when 'month'
             frontend_relative_month(Time.current, value)
+          when 'year'
+            frontend_relative_month(Time.current, 0, year: value)
           else
             value.send(range).from_now
           end