module Briar::Picker::DateSteps

Public Instance Methods

change_minute_interval_on_picker(target_interval, picker_id=nil) click to toggle source
# File lib/briar/picker/date_picker.rb, line 47
def change_minute_interval_on_picker (target_interval, picker_id=nil)
  query_str = should_see_date_picker picker_id
  res = query(query_str, [{:setMinuteInterval => target_interval.to_i}])
  if res.empty?
    screenshot_and_raise "could not change the minute interval with query '#{query_str}'"
  end
  step_pause
  @picker_minute_interval = target_interval.to_i
end
change_time_on_picker_to_minutes_before_now(target_minutes, options={:picker_id => nil, :convert_time_to_utc => false}) click to toggle source
# File lib/briar/picker/date_picker.rb, line 133
def change_time_on_picker_to_minutes_before_now (target_minutes, options={:picker_id => nil,
                                                                          :convert_time_to_utc => false})

  picker_id = options != nil ? options[:picker_id] : nil
  convert = options != nil ? options[:convert_time_to_utc] : false

  if convert
    past = Time.now.gmtime + Time.now.gmtoff - (target_minutes.to_i * 60)
  else
    past = Time.now - (60 * target_minutes.to_i)
  end

  opts = {:picker_id => picker_id,
          :convert_time_to_utc => convert}

  change_time_on_picker_with_time past, opts
end
change_time_on_picker_to_minutes_from_now(target_minutes, options={:picker_id => nil, :convert_time_to_utc => false}) click to toggle source
# File lib/briar/picker/date_picker.rb, line 115
def change_time_on_picker_to_minutes_from_now (target_minutes, options={:picker_id => nil,
                                                                        :convert_time_to_utc => false})

  picker_id = picker_id_from_options options
  convert = convert_to_utc_from_options options

  if convert
    future = Time.now.gmtime + Time.now.gmtoff + (target_minutes.to_i * 60)
  else
    future = Time.new + (60 * target_minutes.to_i)
  end

  opts = {:picker_id => picker_id,
          :convert_time_to_utc => convert}

  change_time_on_picker_with_time future, opts
end
should_see_label_has_time_i_just_entered(label_id) click to toggle source
# File lib/briar/picker/date_picker.rb, line 26
def should_see_label_has_time_i_just_entered (label_id)
  should_see_label label_id
  query_str = "label marked:'#{label_id}'"
  actual_text = query(query_str, :text).first
  unless (actual_text.eql? @date_picker_time_12h) or (actual_text.eql? @date_picker_time_24h)
    screenshot_and_raise "expected to see '#{@date_picker_time_12h}' or '#{@date_picker_time_24h}' in '#{label_id}' but found '#{actual_text}'"
  end
end
should_see_row_has_label_with_time_on_picker(row_id, label_id, options={:picker_id => nil, :table_id => nil}) click to toggle source

does not require a time or date change. picker needs to be visible

# File lib/briar/picker/date_picker.rb, line 58
def should_see_row_has_label_with_time_on_picker(row_id, label_id, options={:picker_id => nil,
                                                                            :table_id => nil})
  picker_id = options != nil ? options[:picker_id] : nil
  should_see_date_picker picker_id
  table_id = options != nil ? options[:table_id] : nil
  query_str = query_str_for_row_content row_id, table_id
  arr = query("#{query_str} label marked:'#{label_id}'", :text)

  if arr.empty?
    screenshot_and_raise "could not find '#{label_id}' in the '#{row_id}'"
  end

  hash = picker_time_strs_hash picker_id
  time_str_12h = hash[:h12]
  time_str_24h = hash[:h24]
  actual_text = arr.first
  unless (actual_text.eql? time_str_12h) or (actual_text.eql? time_str_24h)
    screenshot_and_raise "expected to see '#{time_str_12h}' or '#{time_str_24h}' in '#{label_id}' but found '#{actual_text}'"
  end
end
should_see_row_has_time_i_just_entered(row_id, label_id, table_id=nil) click to toggle source

requires a time or date change. picker does not need to be visible

# File lib/briar/picker/date_picker.rb, line 36
def should_see_row_has_time_i_just_entered (row_id, label_id, table_id=nil)
  query_str = query_str_for_row row_id, table_id
  arr = query("#{query_str} descendant label marked:'#{label_id}'", :text)
  screenshot_and_raise "could not find '#{label_id}' in the '#{row_id}' row" if arr.empty?
  actual_text = arr.first

  unless (actual_text.eql? @date_picker_time_12h) or (actual_text.eql? @date_picker_time_24h)
    screenshot_and_raise "expected to see '#{@date_picker_time_12h}' or '#{@date_picker_time_24h}' in '#{label_id}' but found '#{actual_text}'"
  end
end
should_see_time_on_picker_is_now(options = {:picker_id => nil, :convert_time_to_utc => false}) click to toggle source
requires picker is visible

noinspection SpellCheckingInspection

# File lib/briar/picker/date_picker.rb, line 81
def should_see_time_on_picker_is_now (options = {:picker_id => nil,
                                                 :convert_time_to_utc => false})
  picker_time = ruby_time_from_picker options
  now_time = Time.now

  convert = convert_to_utc_from_options options
  if convert
    now_time = Time.now.utc + now_time.gmt_offset
  end

  # normalize
  picker_time = picker_time - picker_time.sec


  now_time = now_time - now_time.sec

  picker_id = picker_id_from_options options
  minute_interval = picker_minute_interval picker_id

  if minute_interval == 1 and not (picker_time == now_time)
    screenshot_and_raise "should see picker with time '#{now_time}' but found '#{picker_time}'"
  end

  max_time = now_time + (minute_interval * 60)
  min_time = now_time - (minute_interval * 60)

  unless picker_time >= min_time && picker_time <= max_time
    p "   min: '#{min_time}'"
    p "target: '#{picker_time}'"
    p "   max: '#{max_time}'"
    screenshot_and_raise "should see picker with time between '#{min_time}' and '#{max_time}' but found '#{picker_time}'"
  end
end