formatic 1.0.3 → 1.0.5
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/CHANGELOG.md +9 -0
- data/README.md +10 -1
- data/lib/formatic/testing/browser_search.rb +72 -0
- data/lib/formatic/testing/capybara.rb +19 -2
- data/lib/formatic/testing/search.rb +35 -9
- data/lib/formatic/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9ebc8a341c13d0d87f570879e2f682d2d466f369e949f1cb0da3b7c99596e349
|
|
4
|
+
data.tar.gz: 4c2972b02d90b378587198ed7dbf62e49d1abe1a86400000819d7a83b785ef36
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a279429254cf00d2f40e116121e716a3159fab1806535589e5d4ab33dfcfdc520523d6cb43d2b6dbbb01b6682717d3feb71930d4be4810fba73718e08f62c901
|
|
7
|
+
data.tar.gz: fd00964936b499875f92d0684f5ff81a5619a7a5386398e53c80f0b3f0c2efd70ba813375568374f6a8e27300d63293597915fa23bb25239201e6520d531af7e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [1.0.5] - 2026-11-12
|
|
2
|
+
|
|
3
|
+
- Rack test `search` helper with a blank query clears the selection (`search '', from: 'Customer'`)
|
|
4
|
+
- `search` helper works in browser tests: clicks the server-rendered quickpick when it matches, so no search request hits the wire; otherwise types the query and clicks the async choice
|
|
5
|
+
|
|
6
|
+
## [1.0.4] - 2026-11-12
|
|
7
|
+
|
|
8
|
+
- Rack test `search` helper clears the `Formatic::Search` field on a blank query (`search '', from: 'Customer'`)
|
|
9
|
+
|
|
1
10
|
## [1.0.3] - 2026-11-11
|
|
2
11
|
|
|
3
12
|
- Rack test `search` helper chooses the matching quick-pick radio directly when the query matches, falling back to the endpoint search otherwise
|
data/README.md
CHANGED
|
@@ -66,7 +66,7 @@ render Formatic::Search.new(f:, attribute_name: :commander_id,
|
|
|
66
66
|
url: admin_commanders_path(format: :json), frontend:)
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
Capybara
|
|
69
|
+
Capybara test classes can include the `search` helper instead:
|
|
70
70
|
|
|
71
71
|
```ruby
|
|
72
72
|
require 'formatic/testing/capybara'
|
|
@@ -77,9 +77,18 @@ class CustomersTest < ActionDispatch::SystemTestCase
|
|
|
77
77
|
test 'select a customer' do
|
|
78
78
|
search 'Acme Corp', from: 'Customer'
|
|
79
79
|
end
|
|
80
|
+
|
|
81
|
+
test 'clear the selection' do
|
|
82
|
+
search '', from: 'Customer'
|
|
83
|
+
end
|
|
80
84
|
end
|
|
81
85
|
```
|
|
82
86
|
|
|
87
|
+
Rack tests manipulate the server-rendered markup directly. Browser tests
|
|
88
|
+
click the server-rendered quickpicks, so no search request hits the wire
|
|
89
|
+
when the wanted record is among them; otherwise the query is typed and
|
|
90
|
+
the async choice is clicked.
|
|
91
|
+
|
|
83
92
|
## Installation
|
|
84
93
|
|
|
85
94
|
Install the gem and add to the application's Gemfile by executing:
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'calls'
|
|
4
|
+
require_relative 'search'
|
|
5
|
+
|
|
6
|
+
module Formatic
|
|
7
|
+
module Testing
|
|
8
|
+
# Selects a Formatic search result in a real browser.
|
|
9
|
+
# A blank query clears the selection instead.
|
|
10
|
+
#
|
|
11
|
+
# Picks rendered on the server are clicked directly, so no search
|
|
12
|
+
# request hits the wire when the wanted record is among them.
|
|
13
|
+
# Otherwise the query is typed and the async choice is clicked.
|
|
14
|
+
class BrowserSearch
|
|
15
|
+
include Calls
|
|
16
|
+
|
|
17
|
+
option :page
|
|
18
|
+
option :query
|
|
19
|
+
option :from
|
|
20
|
+
|
|
21
|
+
def call
|
|
22
|
+
query_field = find_query_field(page, from)
|
|
23
|
+
component = search_component(query_field)
|
|
24
|
+
return clear_selection(component) if query.nil? || query == ''
|
|
25
|
+
|
|
26
|
+
query_field.click
|
|
27
|
+
pick = matching_pick(component)
|
|
28
|
+
return pick.click if pick
|
|
29
|
+
|
|
30
|
+
choose_result(component)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
# The wrapper label points at the search query input, so `find_field`
|
|
36
|
+
# usually returns it directly. Otherwise locate it inside the component.
|
|
37
|
+
def find_query_field(page, from)
|
|
38
|
+
field = page.find_field(from)
|
|
39
|
+
return field if field[:class]&.include?('js-formatic-search__query-input')
|
|
40
|
+
|
|
41
|
+
field.find(:xpath, 'ancestor::div[contains(@class, "js-formatic-search")][1]')
|
|
42
|
+
.find('.js-formatic-search__query-input', visible: :all)
|
|
43
|
+
rescue ::Capybara::ElementNotFound
|
|
44
|
+
page.find_field(from)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def search_component(query_field)
|
|
48
|
+
query_field.find(:xpath, 'ancestor::div[contains(@class, "js-formatic-search")][1]')
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Pick labels show avatar chips with the name CSS-hidden,
|
|
52
|
+
# so match with visible: :all.
|
|
53
|
+
def matching_pick(component)
|
|
54
|
+
component.find('label.js-formatic-search__pick-label', text: query, visible: :all)
|
|
55
|
+
rescue ::Capybara::ElementNotFound
|
|
56
|
+
nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def choose_result(component)
|
|
60
|
+
page.fill_in(from, with: query)
|
|
61
|
+
component.find('.js-formatic-search__choice', text: query).click
|
|
62
|
+
rescue ::Capybara::ElementNotFound
|
|
63
|
+
message = "No quickpick or result matching #{query.inspect} from #{from.inspect}"
|
|
64
|
+
raise Search::SelectionError, message
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def clear_selection(component)
|
|
68
|
+
component.find('.js-formatic-search__clear').click
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require_relative 'search'
|
|
4
|
+
require_relative 'browser_search'
|
|
4
5
|
|
|
5
6
|
module Formatic
|
|
6
7
|
module Testing
|
|
7
8
|
module Capybara
|
|
8
|
-
# Include in a Capybara
|
|
9
|
+
# Include in a Capybara test class to select Formatic search results.
|
|
9
10
|
#
|
|
10
11
|
# include Formatic::Testing::Capybara::Search
|
|
11
12
|
#
|
|
12
13
|
# search 'Acme Corp', from: 'Customer'
|
|
14
|
+
# search '', from: 'Customer'
|
|
15
|
+
#
|
|
16
|
+
# Rack tests manipulate the server-rendered markup directly.
|
|
17
|
+
# Browser tests click the server-rendered quickpicks, so no search
|
|
18
|
+
# request hits the wire when the wanted record is among them.
|
|
13
19
|
module Search
|
|
14
20
|
def search(query, from:)
|
|
15
|
-
|
|
21
|
+
if rack_test_driver?
|
|
22
|
+
::Formatic::Testing::Search.call(page:, query:, from:)
|
|
23
|
+
else
|
|
24
|
+
::Formatic::Testing::BrowserSearch.call(page:, query:, from:)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def rack_test_driver?
|
|
31
|
+
defined?(::Capybara::RackTest::Driver) == 'constant' &&
|
|
32
|
+
page.driver.is_a?(::Capybara::RackTest::Driver)
|
|
16
33
|
end
|
|
17
34
|
end
|
|
18
35
|
end
|
|
@@ -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
|
|
|
@@ -20,16 +21,9 @@ module Formatic
|
|
|
20
21
|
query_field = find_query_field(page, from)
|
|
21
22
|
component = search_component(query_field)
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
return record
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
record = matching_record(search_records(component), query)
|
|
28
|
-
|
|
29
|
-
raise SelectionError, "No result matching #{query.inspect} from #{from.inspect}" unless record
|
|
24
|
+
return clear_selection(component, query_field) if query.nil? || query == ''
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
record
|
|
26
|
+
select_record(component, query_field)
|
|
33
27
|
end
|
|
34
28
|
|
|
35
29
|
private
|
|
@@ -57,6 +51,19 @@ module Formatic
|
|
|
57
51
|
query_field.find(:xpath, 'ancestor::div[contains(@class, "js-formatic-search")][1]')
|
|
58
52
|
end
|
|
59
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
|
+
|
|
60
67
|
def search_records(component)
|
|
61
68
|
response = search_request(configured_value(component, 'url'), search_params(component))
|
|
62
69
|
|
|
@@ -113,6 +120,25 @@ module Formatic
|
|
|
113
120
|
component.find('.js-formatic-search__results', visible: :all).native.inner_html = ''
|
|
114
121
|
query_field.set('')
|
|
115
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
|
|
116
142
|
end
|
|
117
143
|
end
|
|
118
144
|
end
|
data/lib/formatic/version.rb
CHANGED
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.
|
|
4
|
+
version: 1.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- halo
|
|
@@ -219,6 +219,7 @@ files:
|
|
|
219
219
|
- lib/formatic/templates/search.rb
|
|
220
220
|
- lib/formatic/templates/select.rb
|
|
221
221
|
- lib/formatic/templates/wrapper.rb
|
|
222
|
+
- lib/formatic/testing/browser_search.rb
|
|
222
223
|
- lib/formatic/testing/capybara.rb
|
|
223
224
|
- lib/formatic/testing/search.rb
|
|
224
225
|
- lib/formatic/version.rb
|