haya_select_helpers 0.0.6 → 0.0.9
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 +4 -4
- data/lib/haya_select.rb +146 -16
- data/lib/haya_select_helpers/version.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94027197c1829e876fbe519781f094cfcb7db0db47d8eba3c4f851adf1f66017
|
|
4
|
+
data.tar.gz: 211c7411bd07813f3ca1d0cac83f5c3ed1e42c367ec6e1560223b36153ebd783
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 38030c78ac06ea02e773157fefe7f379b780bd20bc471f7fc425a956d8f0a2a8fd8ee981c2637b3824e05979db3279d3f146a47747cefbf36c6b3f9243415268
|
|
7
|
+
data.tar.gz: aa42a5467142a1cd4f893ce1d5f3498240f8082c576fb045e928fc00e9734cd3528894bf4d8734e349416682fc62088867c944a76b5b8eadce1ab371ee116b6e
|
data/lib/haya_select.rb
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# rubocop:disable Metrics/ClassLength, Style/Documentation
|
|
1
4
|
class HayaSelect
|
|
2
|
-
attr_reader :base_selector,
|
|
5
|
+
attr_reader :base_selector,
|
|
6
|
+
:not_opened_current_selected_selector,
|
|
7
|
+
:opened_current_selected_selector,
|
|
8
|
+
:options_selector,
|
|
9
|
+
:scope
|
|
3
10
|
|
|
4
|
-
delegate :all,
|
|
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[
|
|
57
|
+
value: option_element['data-value']
|
|
42
58
|
}
|
|
43
59
|
end
|
|
44
60
|
rescue Selenium::WebDriver::Error::StaleElementReferenceError
|
|
@@ -62,21 +78,19 @@ class HayaSelect
|
|
|
62
78
|
def select(label = nil, value: nil)
|
|
63
79
|
open
|
|
64
80
|
select_option(label:, value:)
|
|
65
|
-
|
|
66
|
-
|
|
81
|
+
wait_for_selected_value_or_label(label, value)
|
|
82
|
+
close_if_open
|
|
67
83
|
self
|
|
68
84
|
end
|
|
69
85
|
|
|
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 =
|
|
74
|
-
selector
|
|
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[
|
|
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
|
|
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[
|
|
102
|
-
toggle_value: element[
|
|
103
|
-
value: element[
|
|
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
|
|
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,118 @@ class HayaSelect
|
|
|
125
144
|
end
|
|
126
145
|
|
|
127
146
|
def wait_for_value(expected_value)
|
|
128
|
-
wait_for_selector
|
|
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
|
+
return wait_for_browser { scope.page.has_selector?(selector) } unless label
|
|
165
|
+
|
|
166
|
+
option_found = false
|
|
167
|
+
|
|
168
|
+
search_terms_for(label).each do |search_term|
|
|
169
|
+
current_options_text = options_container_text
|
|
170
|
+
search_for_option(search_term)
|
|
171
|
+
|
|
172
|
+
wait_for_browser do
|
|
173
|
+
scope.page.has_selector?(selector) || options_container_updated?(search_term, current_options_text)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
if scope.page.has_selector?(selector)
|
|
177
|
+
option_found = true
|
|
178
|
+
break
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
return if option_found
|
|
183
|
+
|
|
184
|
+
wait_for_browser do
|
|
185
|
+
scope.page.has_selector?(selector)
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
def wait_for_selected_value_or_label(label, value)
|
|
190
|
+
if value
|
|
191
|
+
wait_for_value(value)
|
|
192
|
+
elsif label
|
|
193
|
+
wait_for_label(label)
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def search_for_option(label)
|
|
198
|
+
return unless scope.page.has_selector?(search_input_selector)
|
|
199
|
+
|
|
200
|
+
search(label)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def options_container_updated?(search_term, previous_text)
|
|
204
|
+
return false unless scope.page.has_selector?(no_options_selector)
|
|
205
|
+
return false unless search_input_value == search_term
|
|
206
|
+
return false if previous_text.nil?
|
|
207
|
+
|
|
208
|
+
options_container_text != previous_text
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def options_container_text
|
|
212
|
+
scope.page.find(options_selector).text
|
|
213
|
+
rescue Capybara::ElementNotFound
|
|
214
|
+
nil
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def search_input_value
|
|
218
|
+
scope.page.find(search_input_selector).value
|
|
219
|
+
rescue Capybara::ElementNotFound
|
|
220
|
+
nil
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def search_terms_for(label)
|
|
224
|
+
terms = [label]
|
|
225
|
+
terms << label.split(" (", 2).first if label.include?(" (")
|
|
226
|
+
terms.uniq
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def close_if_open
|
|
230
|
+
return if scope.page.has_no_selector?(options_selector)
|
|
231
|
+
|
|
232
|
+
close_attempts = 0
|
|
233
|
+
|
|
234
|
+
while scope.page.has_selector?(options_selector) && close_attempts < 3
|
|
235
|
+
if scope.page.has_selector?(select_container_selector)
|
|
236
|
+
wait_for_and_find(select_container_selector).click
|
|
237
|
+
else
|
|
238
|
+
wait_for_and_find("body").click
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
close_attempts += 1
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
wait_for_no_selector options_selector
|
|
245
|
+
wait_for_selector not_opened_current_selected_selector
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
def search_input_selector
|
|
249
|
+
"#{base_selector} [data-class='search-text-input']"
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
def no_options_selector
|
|
253
|
+
"#{options_selector} [data-class='no-options-container']"
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def select_container_selector
|
|
257
|
+
"#{base_selector} [data-class='select-container']"
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
# rubocop:enable Metrics/ClassLength, Style/Documentation
|
|
131
261
|
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.
|
|
4
|
+
version: 0.0.9
|
|
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-
|
|
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
|
-
-
|
|
29
|
+
- kasper@diestoeckels.de
|
|
30
30
|
executables: []
|
|
31
31
|
extensions: []
|
|
32
32
|
extra_rdoc_files: []
|