Module: DateTimeHelpers

Defined in:
decidim-dev/lib/decidim/dev/test/rspec_support/datetime_helpers.rb

Overview

Helpers that get automatically included in system specs.

Instance Method Summary collapse

Instance Method Details

#fill_in_datetime(field_id, value) ⇒ Object

Note that the Decidim datetime selector UI only supports minutes intervals of 5 but when using the programming API exposed by foundation-datepicker, it can be set to any date.


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'decidim-dev/lib/decidim/dev/test/rspec_support/datetime_helpers.rb', line 8

def fill_in_datetime(field_id, value)
  # The value needs to be passed without the timezone to the view for it to
  # work properly. Otherwise it is selecting the GMT time and the specs won't
  # work if the browser environment is running in some other timezone.
  formatted_value = value.strftime("%Y-%m-%dT%H:%M")
  page.execute_script(
    <<~JS
      // Uses the foundation-datepicker API to set the date/time.
      // This also supports times that Decidim does not allow the user to
      // pick from the UI.
      var datepicker = $("##{field_id}").data("datepicker");
      datepicker.setDate(new Date("#{formatted_value}"));
    JS
  )
end