haya_select_helpers 0.0.5 → 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: bf6acdffd9a4d2e98a8745622eb27cb59fad687a26314dfd08527df0de461af2
4
- data.tar.gz: 4f29d9bb7ac705fa10ab7a6f101c3b056037cc0c1e2fe98ec0b89d850d87180e
3
+ metadata.gz: dbaaa5e08a996a87dec3749a5a97c9739c82d1716a4d27c23687dfb75b96e7fb
4
+ data.tar.gz: 03af520fb89abed66159cb794dd3fd67df9bc7c80e80e8d0083a87aaee5811cb
5
5
  SHA512:
6
- metadata.gz: a3ca2d3a43fa0657ed05729f478af7389509c1169e9cbdf062bec578ee0da78a69cf0287f748b55b4e6fe1633d2d640a424459bc54b6bf8c2d7d4000835f3c33
7
- data.tar.gz: d27f8fe5d9b66fcd54539b069caceee820b58760e93b044a8605cfe8013c3f1bb370b980a7128a316ab764fbf574f18022b2f64c5888747afddfad9ddd25138f
6
+ metadata.gz: d95b215ea2ccf03ec06d15aca0465cbd252b3ef90367048dcec5026930923bfd3a18c8fca617ba238c7e362dd69b9954ac8bd4489b303c9e4cfac09919ded09d
7
+ data.tar.gz: 6d71dc0c7031495a27021530c9e35743592b7db7fbfb5c763f2cbeebc4bbccfd08e50e1761bb92ce450543e01b470484153c215848fe80f2102bb88c97238811
data/lib/haya_select.rb CHANGED
@@ -1,24 +1,40 @@
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
- @base_selector = ".haya-select[data-id='#{id}']"
8
- @not_opened_current_selected_selector = "#{base_selector}[data-opened='false'] .haya-select-current-selected"
9
- @opened_current_selected_selector = "#{base_selector}[data-opened='true'] .haya-select-current-selected"
10
- @options_selector = ".haya-select-options-container[data-id='#{id}']"
23
+ @base_selector = "[data-component='haya-select'][data-id='#{id}']"
24
+ @not_opened_current_selected_selector = "#{base_selector}[data-opened='false'] [data-class='current-selected']"
25
+ @opened_current_selected_selector = "#{base_selector}[data-opened='true'] [data-class='current-selected']"
26
+ @options_selector = "[data-class='options-container'][data-id='#{id}']"
11
27
  @scope = scope
12
28
  end
13
29
 
14
30
  def label
15
- wait_for_and_find("#{base_selector} .haya-select-current-selected .current-option").text
31
+ wait_for_and_find("#{base_selector} [data-class='current-selected'] [data-class='current-option']").text
16
32
  rescue Selenium::WebDriver::Error::StaleElementReferenceError
17
33
  retry
18
34
  end
19
35
 
20
36
  def open
21
- wait_for_and_find("#{base_selector}[data-opened='false'] .haya-select-current-selected").click
37
+ wait_for_and_find("#{base_selector}[data-opened='false'] [data-class='current-selected']").click
22
38
  wait_for_selector opened_current_selected_selector
23
39
  wait_for_selector options_selector
24
40
  self
@@ -26,13 +42,19 @@ class HayaSelect
26
42
  retry
27
43
  end
28
44
 
45
+ def close
46
+ wait_for_selector opened_current_selected_selector
47
+ wait_for_and_find("[data-class='search-text-input']").click
48
+ wait_for_no_selector opened_current_selected_selector
49
+ end
50
+
29
51
  def options
30
- wait_for_selector "#{options_selector} .haya-select-option"
31
- option_elements = all("#{options_selector} .haya-select-option")
52
+ wait_for_selector "#{options_selector} [data-class='select-option']"
53
+ option_elements = all("#{options_selector} [data-class='select-option']")
32
54
  option_elements.map do |option_element|
33
55
  {
34
56
  label: option_element.text,
35
- value: option_element["data-value"]
57
+ value: option_element['data-value']
36
58
  }
37
59
  end
38
60
  rescue Selenium::WebDriver::Error::StaleElementReferenceError
@@ -43,26 +65,32 @@ class HayaSelect
43
65
  wait_for_expect do
44
66
  expect(options).to eq expected_options
45
67
  end
68
+ self
46
69
  end
47
70
 
48
71
  def search(value)
49
- wait_for_and_find("#{base_selector} .haya-select-search-text-input").set(value)
72
+ wait_for_and_find("#{base_selector} [data-class='search-text-input']").set(value)
73
+ self
50
74
  rescue Selenium::WebDriver::Error::StaleElementReferenceError
51
75
  retry
52
76
  end
53
77
 
54
- def select(label)
78
+ def select(label = nil, value: nil)
55
79
  open
56
- select_option(label: label)
80
+ select_option(label:, value:)
57
81
  wait_for_selector not_opened_current_selected_selector
58
82
  wait_for_no_selector options_selector
59
83
  self
60
84
  end
61
85
 
62
- def select_option(label:)
63
- option = wait_for_and_find("#{options_selector} .haya-select-option", exact_text: label)
86
+ def select_option(label: nil, value: nil)
87
+ raise "No 'label' or 'value' given" if label.nil? && value.nil?
64
88
 
65
- raise "The '#{label}'-option is disabled" if option["data-disabled"] == "true"
89
+ selector = select_option_selector(label: label, value: value)
90
+ wait_for_option(selector, label)
91
+ option = wait_for_and_find(selector)
92
+
93
+ raise "The '#{label}'-option is disabled" if option['data-disabled'] == 'true'
66
94
 
67
95
  option.click
68
96
  self
@@ -71,36 +99,79 @@ class HayaSelect
71
99
  end
72
100
 
73
101
  def value
74
- wait_for_and_find("#{base_selector} .haya-select-current-selected input[type='hidden']", visible: false)[:value]
102
+ wait_for_and_find("#{base_selector} [data-class='current-selected'] input[type='hidden']", visible: false)[:value]
75
103
  rescue Selenium::WebDriver::Error::StaleElementReferenceError
76
104
  retry
77
105
  end
78
106
 
79
107
  def wait_for_label(expected_label)
80
- wait_for_selector "#{base_selector} .haya-select-current-selected .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
+ )
81
112
  self
82
113
  end
83
114
 
84
115
  def toggles
85
- all("#{base_selector} .haya-select-option-presentation").map do |element|
116
+ all("#{base_selector} [data-testid='option-presentation']").map do |element|
86
117
  {
87
- toggle_icon: element["data-toggle-icon"],
88
- toggle_value: element["data-toggle-value"],
89
- value: element["data-value"]
118
+ toggle_icon: element['data-toggle-icon'],
119
+ toggle_value: element['data-toggle-value'],
120
+ value: element['data-value']
90
121
  }
91
122
  end
92
123
  rescue Selenium::WebDriver::Error::StaleElementReferenceError
93
124
  retry
94
125
  end
95
126
 
127
+ def selected_option_values
128
+ all("[data-class='select-option'][data-selected='true']").map do |select_option_element|
129
+ select_option_element['data-value']
130
+ end
131
+ end
132
+
133
+ def wait_for_selected_option_values(values)
134
+ wait_for_expect do
135
+ expect(selected_option_values).to eq values
136
+ end
137
+ end
138
+
96
139
  def wait_for_toggles(expected_toggles)
97
140
  wait_for_expect do
98
141
  expect(toggles).to eq expected_toggles
99
142
  end
143
+ self
100
144
  end
101
145
 
102
146
  def wait_for_value(expected_value)
103
- wait_for_selector "#{base_selector} .haya-select-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
+ )
104
151
  self
105
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
106
177
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HayaSelectHelpers
2
- VERSION = "0.0.5"
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.5
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: 2024-04-15 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: []
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.4.10
70
+ rubygems_version: 3.3.7
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: RSpec helpers for HayaSelect.