formatic 1.0.2 → 1.0.4

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: b1f958296d240381290011236ccff9c70dafe0d2b965cc0199f76ded99ae09c1
4
- data.tar.gz: 70e142426fc515e4d4f375824da349e1f0c8917809b6a5cfbbbb9c5923d502bf
3
+ metadata.gz: 7af22aa2b9a0b0f1c08544a87127b14dfc941adc37394091ddf8af2e776b66ec
4
+ data.tar.gz: 6e06db902597c3ba6ad82977a02f8991d90cc2412250f70d7fb7d07e1fe590f0
5
5
  SHA512:
6
- metadata.gz: 15b70366584a928835d9e29ed854f1037e5f0a703dcebb0298b5d558bb74a214c4fffae7f432db8ff5fc1f00293b445a6097de236428f73e5eead6f1feebf923
7
- data.tar.gz: fa7ed00c5bf20432715f24c4f77fcc8bc8fdb5c109f1b6a27e1daaecd967209f88cce16ff716adb4da615494c317eb525d2fdabe047cd1d65fc41848507327f2
6
+ metadata.gz: f4a0615255123699957ce1b08a0e65349ad276c1d5ebd1aaf10b641ee9fc996b57b147acf4730e985b8d9e4f51d308e77c54dcfc2bf06352cce6d03a76f2e5be
7
+ data.tar.gz: b7473fd62e049f5e5e22a656bdade50c135c41f84eebba1d63c689f29064f3ce7108cfd4e61b4c6d3745850122f344c1aac2f9a1e1bff14d958d66ee990a6434
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.0.4] - 2026-11-12
2
+
3
+ - Rack test `search` helper clears the `Formatic::Search` field on a blank query (`search '', from: 'Customer'`)
4
+
5
+ ## [1.0.3] - 2026-11-11
6
+
7
+ - Rack test `search` helper chooses the matching quick-pick radio directly when the query matches, falling back to the endpoint search otherwise
8
+
1
9
  ## [1.0.2] - 2026-11-11
2
10
 
3
11
  - Search quick-pick and tab IDs carry a per-instance token, so multiple `Formatic::Search` inputs on one page no longer hijack each other's clicks
@@ -6,6 +6,7 @@ require 'calls'
6
6
  module Formatic
7
7
  module Testing
8
8
  # Selects a Formatic search result in a Rack test.
9
+ # A blank query clears the selection instead.
9
10
  class Search
10
11
  include Calls
11
12
 
@@ -19,12 +20,10 @@ module Formatic
19
20
  ensure_rack_test_driver!
20
21
  query_field = find_query_field(page, from)
21
22
  component = search_component(query_field)
22
- record = matching_record(search_records(component), query)
23
23
 
24
- raise SelectionError, "No result matching #{query.inspect} from #{from.inspect}" unless record
24
+ return clear_selection(component, query_field) if query.nil? || query == ''
25
25
 
26
- apply_selection(component, query_field, record)
27
- record
26
+ select_record(component, query_field)
28
27
  end
29
28
 
30
29
  private
@@ -52,6 +51,19 @@ module Formatic
52
51
  query_field.find(:xpath, 'ancestor::div[contains(@class, "js-formatic-search")][1]')
53
52
  end
54
53
 
54
+ def select_record(component, query_field)
55
+ if (record = matching_pick(component, query))
56
+ return record
57
+ end
58
+
59
+ record = matching_record(search_records(component), query)
60
+
61
+ raise SelectionError, "No result matching #{query.inspect} from #{from.inspect}" unless record
62
+
63
+ apply_selection(component, query_field, record)
64
+ record
65
+ end
66
+
55
67
  def search_records(component)
56
68
  response = search_request(configured_value(component, 'url'), search_params(component))
57
69
 
@@ -87,6 +99,20 @@ module Formatic
87
99
  end
88
100
  end
89
101
 
102
+ # The autocomplete search needs JavaScript, which Rack cannot execute.
103
+ # The component already renders favorites as quickpick radios in the HTML.
104
+ # When the wanted record is among the quickpicks, choose the matching radio directly.
105
+ # Otherwise the caller falls back to the endpoint search.
106
+ def matching_pick(component, query)
107
+ pick = component.all('label.js-formatic-search__pick-label', visible: :all)
108
+ .find { |label| label.text.downcase.include?(query.downcase) }
109
+ return if pick.nil?
110
+
111
+ radio = pick.find('input[type=radio]', visible: :all)
112
+ page.choose(radio[:id], visible: :all)
113
+ { 'id' => radio.value }
114
+ end
115
+
90
116
  def apply_selection(component, query_field, record)
91
117
  component.find('.js-formatic-search__value', visible: :all).set(record.fetch('id').to_s)
92
118
  selected = component.find('.js-formatic-search__selected', visible: :all)
@@ -94,6 +120,25 @@ module Formatic
94
120
  component.find('.js-formatic-search__results', visible: :all).native.inner_html = ''
95
121
  query_field.set('')
96
122
  end
123
+
124
+ # A blank query removes the current selection.
125
+ # The hidden value is blanked and re-enabled for submission.
126
+ # Checked quickpick radios are unchecked.
127
+ # The selected card and the results are emptied.
128
+ # The query input is blanked last.
129
+ def clear_selection(component, query_field)
130
+ value_input = component.find('.js-formatic-search__value', visible: :all)
131
+ value_input.native.remove_attribute('disabled')
132
+ value_input.set('')
133
+
134
+ component.all('input.js-formatic-search__pick', visible: :all).each do |radio|
135
+ radio.native.remove_attribute('checked')
136
+ end
137
+
138
+ component.find('.js-formatic-search__selected', visible: :all).native.inner_html = ''
139
+ component.find('.js-formatic-search__results', visible: :all).native.inner_html = ''
140
+ query_field.set('')
141
+ end
97
142
  end
98
143
  end
99
144
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Formatic
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - halo