haya_select_helpers 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3a49ed55099b6d8c40a7cc79dd858ec70a5b62c52256f8651194eafff7ef777
4
- data.tar.gz: a32bfb12dc808215d3bbdcd09ee998ce9b84bdc13a1b351a15b2d73e9d4f837c
3
+ metadata.gz: 1859828251316a80407d354d1c30f56f865ea46c1358ca638c1f6da563164613
4
+ data.tar.gz: 2aa84183163ef3a14b9ea5ef6963a6ad157c19585f4a795be4cb342885e4a7de
5
5
  SHA512:
6
- metadata.gz: 3265b3febd190d12e916542f458cc536405b17a4375ddae0df083126caaf1077b4777db974be50a66181868d86541ed89b2409ab884c6677610972d47ca28c46
7
- data.tar.gz: 5e05c8c17dbb2840368de065731e6a164c2693c55d2daf1d92a0acd82147473ba974c3cd255f252f8f721087ac8fe0ef232d6e0748ff1e5b31bf55f6b90f6b59
6
+ metadata.gz: 95227a959dff150c9555ef3b295b9f6c0af6cc8bd82edf6f289cfeec22a8942c6239b24aa0b758be7c7a48c9be8484076f069cbb608bf3b8ec52da56026e4a30
7
+ data.tar.gz: 58ddc7034b2a459763d1d2483cdcf4db878e8b25faf3af3a46cfa7ae33a3fb85338be1f7d5fe7abf4aef89654c00c24e71375d68d4d9d3d5a1e40e5b4d9a2da2
data/lib/haya_select.rb CHANGED
@@ -93,17 +93,14 @@ class HayaSelect
93
93
  attempts = 0
94
94
 
95
95
  begin
96
+ log_select_start(label, value, allow_if_selected, attempts)
96
97
  guard_already_selected(label, value, allow_if_selected) if attempts.zero?
97
98
 
98
- previous_value = value
99
- open
100
- selected_value = select_option_value(label:, value:)
101
- selected_value = "" if selected_value.nil? && value.nil?
102
- allow_blank = previous_value == selected_value
103
- close_if_open
104
- wait_for_selected_value_or_label(label, value || selected_value, allow_blank:)
99
+ selected_value, allow_blank = select_value_and_close(label:, value:)
100
+ wait_for_selected_after_select(label, value, selected_value, allow_blank)
105
101
  self
106
102
  rescue WaitUtil::TimeoutError, Selenium::WebDriver::Error::StaleElementReferenceError
103
+ log_select_retry(attempts)
107
104
  attempts += 1
108
105
  retry if attempts < 3
109
106
  raise
@@ -180,8 +177,17 @@ class HayaSelect
180
177
  raise "No 'label' or 'value' given" if label.nil? && value.nil?
181
178
 
182
179
  selector = select_option_selector(label: label, value: value)
180
+ Rails.logger.debug do
181
+ "[haya_select] select_option_value selector=#{base_selector} option_selector=#{selector} label=#{label.inspect} value=#{value.inspect}"
182
+ end
183
183
  wait_for_option(selector)
184
184
  option = find_option_element(selector, label)
185
+ Rails.logger.debug do
186
+ "[haya_select] option_element selector=#{base_selector} " \
187
+ "data-value=#{option['data-value'].inspect} " \
188
+ "data-disabled=#{option['data-disabled'].inspect} " \
189
+ "data-selected=#{option['data-selected'].inspect}"
190
+ end
185
191
 
186
192
  raise "The '#{label}'-option is disabled" if option['data-disabled'] == 'true'
187
193
 
@@ -286,21 +292,18 @@ private
286
292
  end
287
293
 
288
294
  def wait_for_selected_value_or_label(label, value, allow_blank: false)
295
+ log_wait_for_selected_start(label, value, allow_blank)
296
+ value_input_selector = "#{base_selector} [data-class='current-selected'] input[type='hidden']"
297
+ log_wait_for_selected_initial_state(value_input_selector)
289
298
  wait_for_expect do
290
- value_input_selector = "#{base_selector} [data-class='current-selected'] input[type='hidden']"
291
- has_value_input = scope.page.has_selector?(value_input_selector, visible: false)
292
- label_matches = label && label_matches?(label)
293
- value_matches = value && scope.page.has_selector?(current_value_selector(value), visible: false)
294
- blank_matches = allow_blank && scope.page.has_selector?(current_value_selector(""), visible: false)
295
-
296
- matches =
297
- if has_value_input
298
- value_matches || blank_matches
299
- else
300
- label_matches || value_matches || blank_matches
301
- end
302
-
303
- expect(matches).to eq true
299
+ expect(
300
+ selected_value_or_label_matches?(
301
+ label:,
302
+ value:,
303
+ allow_blank:,
304
+ value_input_selector:
305
+ )
306
+ ).to eq true
304
307
  end
305
308
  end
306
309
 
@@ -539,6 +542,11 @@ private
539
542
  end
540
543
 
541
544
  def perform_option_selection(option, label, option_value)
545
+ Rails.logger.debug do
546
+ "[haya_select] perform_option_selection selector=#{base_selector} " \
547
+ "label=#{label.inspect} option_value=#{option_value.inspect} " \
548
+ "data-selected=#{option['data-selected'].inspect}"
549
+ end
542
550
  click_option_element(option)
543
551
  wait_for_selected_value_or_label(label, option_value)
544
552
  end
@@ -547,5 +555,82 @@ private
547
555
  "#{options_selector} [data-class='select-option']"
548
556
  end
549
557
 
558
+ def log_select_start(label, value, allow_if_selected, attempts)
559
+ Rails.logger.debug do
560
+ "[haya_select] select start selector=#{base_selector} " \
561
+ "label=#{label.inspect} value=#{value.inspect} " \
562
+ "allow_if_selected=#{allow_if_selected} attempts=#{attempts}"
563
+ end
564
+ end
565
+
566
+ def select_value_and_close(label:, value:)
567
+ previous_value = value
568
+ Rails.logger.debug { "[haya_select] open selector=#{base_selector}" }
569
+ open
570
+ Rails.logger.debug { "[haya_select] select_option_value selector=#{base_selector}" }
571
+ selected_value = select_option_value(label:, value:)
572
+ Rails.logger.debug do
573
+ "[haya_select] select_option_value selector=#{base_selector} selected_value=#{selected_value.inspect}"
574
+ end
575
+ selected_value = "" if selected_value.nil? && value.nil?
576
+ allow_blank = previous_value == selected_value
577
+ Rails.logger.debug { "[haya_select] close_if_open selector=#{base_selector}" }
578
+ close_if_open
579
+ [selected_value, allow_blank]
580
+ end
581
+
582
+ def wait_for_selected_after_select(label, value, selected_value, allow_blank)
583
+ expected_value = value || selected_value
584
+ Rails.logger.debug do
585
+ "[haya_select] wait_for_selected_value_or_label " \
586
+ "selector=#{base_selector} label=#{label.inspect} " \
587
+ "value=#{expected_value.inspect} allow_blank=#{allow_blank}"
588
+ end
589
+ wait_for_selected_value_or_label(label, expected_value, allow_blank:)
590
+ end
591
+
592
+ def log_select_retry(attempts)
593
+ Rails.logger.debug { "[haya_select] select retry selector=#{base_selector} attempts=#{attempts}" }
594
+ end
595
+
596
+ def log_wait_for_selected_start(label, value, allow_blank)
597
+ Rails.logger.debug do
598
+ "[haya_select] wait_for_selected_value_or_label start selector=#{base_selector} " \
599
+ "label=#{label.inspect} value=#{value.inspect} allow_blank=#{allow_blank}"
600
+ end
601
+ end
602
+
603
+ def log_wait_for_selected_initial_state(value_input_selector)
604
+ has_value_input_initial = scope.page.has_selector?(value_input_selector, visible: false, wait: 0)
605
+ current_value_initial = scope.page.first(value_input_selector, visible: false, wait: 0)&.[](:value)
606
+ current_option = scope.page.first(
607
+ "#{base_selector} [data-class='current-selected'] [data-class='current-option']",
608
+ minimum: 0,
609
+ wait: 0
610
+ )
611
+ current_label_initial =
612
+ if current_option
613
+ option_text = current_option.first("[data-testid='option-presentation-text']", minimum: 0)
614
+ option_text ? option_text.text : current_option.text
615
+ end
616
+
617
+ Rails.logger.debug do
618
+ "[haya_select] wait_for_selected_value_or_label initial " \
619
+ "selector=#{base_selector} has_value_input=#{has_value_input_initial} " \
620
+ "current_value=#{current_value_initial.inspect} " \
621
+ "current_label=#{current_label_initial.inspect}"
622
+ end
623
+ end
624
+
625
+ def selected_value_or_label_matches?(label:, value:, allow_blank:, value_input_selector:)
626
+ has_value_input = scope.page.has_selector?(value_input_selector, visible: false)
627
+ value_matches = value && scope.page.has_selector?(current_value_selector(value), visible: false)
628
+ blank_matches = allow_blank && scope.page.has_selector?(current_value_selector(""), visible: false)
629
+ return value_matches || blank_matches if has_value_input
630
+
631
+ label_matches = label && label_matches?(label)
632
+ label_matches || value_matches || blank_matches
633
+ end
634
+
550
635
  # rubocop:enable Metrics/ClassLength, Style/Documentation
551
636
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HayaSelectHelpers
4
- VERSION = "0.0.21"
4
+ VERSION = "0.0.22"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haya_select_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj