haya_select_helpers 0.0.6 → 0.0.8

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: 0a2a0808c53f9adebdb42fa32100fbb8152a3b701fbca486cb3d116849306f1e
4
- data.tar.gz: 2e0cd08fc49c9105a0c84d8469e6dd1f5eea928261b3bed299d8bb3848f6d70b
3
+ metadata.gz: dbaaa5e08a996a87dec3749a5a97c9739c82d1716a4d27c23687dfb75b96e7fb
4
+ data.tar.gz: 03af520fb89abed66159cb794dd3fd67df9bc7c80e80e8d0083a87aaee5811cb
5
5
  SHA512:
6
- metadata.gz: '08e3d969f7b4a1c460c43c152a9d28f9457bc494cae12d6a966dfe6a36db48494f5b3315d1fb2b39d2fcbb37b2b68163c5cb1d9d7ae50efdaca06a061d4f24a8'
7
- data.tar.gz: 5350a18c9c7eeb346ef151f2002583be8ce5f680b76b0c11854398bce565995886f73b8f573622d9bb16c88895cda5538cbfd34607800344d32fe4e971058fcc
6
+ metadata.gz: d95b215ea2ccf03ec06d15aca0465cbd252b3ef90367048dcec5026930923bfd3a18c8fca617ba238c7e362dd69b9954ac8bd4489b303c9e4cfac09919ded09d
7
+ data.tar.gz: 6d71dc0c7031495a27021530c9e35743592b7db7fbfb5c763f2cbeebc4bbccfd08e50e1761bb92ce450543e01b470484153c215848fe80f2102bb88c97238811
data/lib/haya_select.rb CHANGED
@@ -1,7 +1,23 @@
1
- class HayaSelect
2
- attr_reader :base_selector, :not_opened_current_selected_selector, :opened_current_selected_selector, :options_selector, :scope
1
+ # frozen_string_literal: true
3
2
 
4
- delegate :all, :expect, :eq, :pretty_html, :wait_for_and_find, :wait_for_expect, :wait_for_no_selector, :wait_for_selector, to: :scope
3
+ # rubocop:disable Metrics/ClassLength, Style/Documentation
4
+ class HayaSelect
5
+ attr_reader :base_selector,
6
+ :not_opened_current_selected_selector,
7
+ :opened_current_selected_selector,
8
+ :options_selector,
9
+ :scope
10
+
11
+ delegate :all,
12
+ :expect,
13
+ :eq,
14
+ :pretty_html,
15
+ :wait_for_and_find,
16
+ :wait_for_browser,
17
+ :wait_for_expect,
18
+ :wait_for_no_selector,
19
+ :wait_for_selector,
20
+ to: :scope
5
21
 
6
22
  def initialize(id:, scope:)
7
23
  @base_selector = "[data-component='haya-select'][data-id='#{id}']"
@@ -38,7 +54,7 @@ class HayaSelect
38
54
  option_elements.map do |option_element|
39
55
  {
40
56
  label: option_element.text,
41
- value: option_element["data-value"]
57
+ value: option_element['data-value']
42
58
  }
43
59
  end
44
60
  rescue Selenium::WebDriver::Error::StaleElementReferenceError
@@ -70,13 +86,11 @@ class HayaSelect
70
86
  def select_option(label: nil, value: nil)
71
87
  raise "No 'label' or 'value' given" if label.nil? && value.nil?
72
88
 
73
- selector = "#{options_selector} [data-testid='option-presentation']"
74
- selector << "[data-text='#{label}']" unless label.nil?
75
- selector << "[data-value='#{value}']" unless value.nil?
76
-
89
+ selector = select_option_selector(label: label, value: value)
90
+ wait_for_option(selector, label)
77
91
  option = wait_for_and_find(selector)
78
92
 
79
- raise "The '#{label}'-option is disabled" if option["data-disabled"] == "true"
93
+ raise "The '#{label}'-option is disabled" if option['data-disabled'] == 'true'
80
94
 
81
95
  option.click
82
96
  self
@@ -91,16 +105,19 @@ class HayaSelect
91
105
  end
92
106
 
93
107
  def wait_for_label(expected_label)
94
- wait_for_selector "#{base_selector} [data-class='current-selected'] [data-class='current-option']", exact_text: expected_label
108
+ wait_for_selector(
109
+ "#{base_selector} [data-class='current-selected'] [data-class='current-option']",
110
+ exact_text: expected_label
111
+ )
95
112
  self
96
113
  end
97
114
 
98
115
  def toggles
99
116
  all("#{base_selector} [data-testid='option-presentation']").map do |element|
100
117
  {
101
- toggle_icon: element["data-toggle-icon"],
102
- toggle_value: element["data-toggle-value"],
103
- value: element["data-value"]
118
+ toggle_icon: element['data-toggle-icon'],
119
+ toggle_value: element['data-toggle-value'],
120
+ value: element['data-value']
104
121
  }
105
122
  end
106
123
  rescue Selenium::WebDriver::Error::StaleElementReferenceError
@@ -108,7 +125,9 @@ class HayaSelect
108
125
  end
109
126
 
110
127
  def selected_option_values
111
- all("[data-class='select-option'][data-selected='true']").map { |select_option_element| select_option_element["data-value"] }
128
+ all("[data-class='select-option'][data-selected='true']").map do |select_option_element|
129
+ select_option_element['data-value']
130
+ end
112
131
  end
113
132
 
114
133
  def wait_for_selected_option_values(values)
@@ -125,7 +144,34 @@ class HayaSelect
125
144
  end
126
145
 
127
146
  def wait_for_value(expected_value)
128
- wait_for_selector "#{base_selector} [data-class='current-selected'] input[type='hidden'][value='#{expected_value}']", visible: false
147
+ wait_for_selector(
148
+ "#{base_selector} [data-class='current-selected'] input[type='hidden'][value='#{expected_value}']",
149
+ visible: false
150
+ )
129
151
  self
130
152
  end
153
+
154
+ private
155
+
156
+ def select_option_selector(label:, value:)
157
+ selector = "#{options_selector} [data-testid='option-presentation']"
158
+ selector << "[data-text='#{label}']" unless label.nil?
159
+ selector << "[data-value='#{value}']" unless value.nil?
160
+ selector
161
+ end
162
+
163
+ def wait_for_option(selector, label)
164
+ wait_for_browser do
165
+ scope.page.has_selector?(selector)
166
+ end
167
+ rescue WaitUtil::TimeoutError
168
+ raise unless label
169
+
170
+ search(label)
171
+ wait_for_browser do
172
+ scope.page.has_selector?(selector)
173
+ end
174
+ end
175
+
176
+ # rubocop:enable Metrics/ClassLength, Style/Documentation
131
177
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HayaSelectHelpers
2
- VERSION = "0.0.6"
4
+ VERSION = '0.0.8'
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haya_select_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-01 00:00:00.000000000 Z
11
+ date: 2026-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -26,7 +26,7 @@ dependencies:
26
26
  version: 7.0.3
27
27
  description: RSpec helpers for HayaSelect.
28
28
  email:
29
- - k@spernj.org
29
+ - kasper@diestoeckels.de
30
30
  executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []