Module: Briar::Picker::DateSteps

Defined in:
lib/briar/picker/date_picker.rb

Instance Method Summary collapse

Instance Method Details

#change_minute_interval_on_picker(target_interval, picker_id = nil) ⇒ Object



47
48
49
50
51
52
53
54
55
# 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}) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# 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}) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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) ⇒ Object



26
27
28
29
30
31
32
33
# 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}) ⇒ Object

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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 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) ⇒ Object

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



36
37
38
39
40
41
42
43
44
45
# 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}) ⇒ Object

requires picker is visible noinspection SpellCheckingInspection



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# 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