blacklight 9.0.0.beta1 → 9.0.0.beta2

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.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/.github/matrix.json +47 -0
  3. data/.github/workflows/build.yml +16 -0
  4. data/.github/workflows/lint.yml +25 -0
  5. data/.github/workflows/main.yml +22 -0
  6. data/.github/workflows/release_7_x_scheduled.yml +39 -0
  7. data/.github/workflows/release_8_x_scheduled.yml +39 -0
  8. data/.github/workflows/test.yml +53 -0
  9. data/.rubocop.yml +70 -2
  10. data/.rubocop_todo.yml +43 -67
  11. data/.solr_wrapper.yml +2 -0
  12. data/VERSION +1 -1
  13. data/app/assets/builds/blacklight.css +19 -15
  14. data/app/assets/javascripts/blacklight/blacklight.esm.js +31 -69
  15. data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
  16. data/app/assets/javascripts/blacklight/blacklight.js +31 -69
  17. data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
  18. data/app/assets/stylesheets/blacklight/_bootstrap_overrides.scss +4 -0
  19. data/app/assets/stylesheets/blacklight/_facets.scss +2 -2
  20. data/app/assets/stylesheets/blacklight/_header.scss +4 -0
  21. data/app/assets/stylesheets/blacklight/_modal.scss +9 -8
  22. data/app/assets/stylesheets/blacklight/_pagination.scss +1 -3
  23. data/app/assets/stylesheets/blacklight/_search_history.scss +0 -4
  24. data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +3 -0
  25. data/app/components/blacklight/advanced_search_form_component.rb +2 -2
  26. data/app/components/blacklight/constraints_component.rb +2 -2
  27. data/app/components/blacklight/document/action_component.rb +1 -3
  28. data/app/components/blacklight/document/bookmark_component.rb +2 -2
  29. data/app/components/blacklight/document/more_like_this_component.rb +2 -2
  30. data/app/components/blacklight/document/page_header_component.rb +2 -2
  31. data/app/components/blacklight/document/thumbnail_component.html.erb +3 -7
  32. data/app/components/blacklight/document/thumbnail_component.rb +7 -6
  33. data/app/components/blacklight/document_component.rb +3 -3
  34. data/app/components/blacklight/document_title_component.rb +3 -10
  35. data/app/components/blacklight/facet_field_checkboxes_component.rb +2 -20
  36. data/app/components/blacklight/facet_field_component.rb +2 -17
  37. data/app/components/blacklight/facet_field_filter_component.rb +2 -21
  38. data/app/components/blacklight/facet_field_inclusive_constraint_component.rb +4 -25
  39. data/app/components/blacklight/facet_field_list_component.rb +2 -32
  40. data/app/components/blacklight/facet_field_no_layout_component.rb +2 -10
  41. data/app/components/blacklight/facet_field_pagination_component.html.erb +2 -2
  42. data/app/components/blacklight/facet_item_component.rb +2 -74
  43. data/app/components/blacklight/facet_item_pivot_component.rb +1 -1
  44. data/app/components/blacklight/facets/checkboxes_component.rb +26 -0
  45. data/app/components/blacklight/facets/count_component.rb +23 -0
  46. data/app/components/blacklight/{facet_field_component.html.erb → facets/field_component.html.erb} +1 -1
  47. data/app/components/blacklight/facets/field_component.rb +23 -0
  48. data/app/components/blacklight/facets/filters_component.html.erb +4 -0
  49. data/app/components/blacklight/facets/filters_component.rb +27 -0
  50. data/app/components/blacklight/{facet_field_inclusive_constraint_component.html.erb → facets/inclusive_constraint_component.html.erb} +1 -1
  51. data/app/components/blacklight/facets/inclusive_constraint_component.rb +31 -0
  52. data/app/components/blacklight/{facet_field_filter_component.html.erb → facets/index_navigation_component.html.erb} +1 -1
  53. data/app/components/blacklight/facets/index_navigation_component.rb +32 -0
  54. data/app/components/blacklight/facets/item_component.rb +73 -0
  55. data/app/components/blacklight/facets/list_component.html.erb +11 -0
  56. data/app/components/blacklight/facets/list_component.rb +38 -0
  57. data/app/components/blacklight/facets/no_layout_component.rb +16 -0
  58. data/app/components/blacklight/facets/selected_value_component.rb +29 -0
  59. data/app/components/blacklight/facets/suggest_component.html.erb +12 -0
  60. data/app/components/blacklight/facets/suggest_component.rb +22 -0
  61. data/app/components/blacklight/metadata_field_plain_text_layout_component.rb +2 -2
  62. data/app/components/blacklight/response/facet_group_component.html.erb +1 -1
  63. data/app/components/blacklight/response/facet_group_component.rb +5 -1
  64. data/app/components/blacklight/system/dropdown_component.html.erb +1 -1
  65. data/app/components/blacklight/system/dropdown_component.rb +1 -1
  66. data/app/components/blacklight/top_navbar_component.html.erb +1 -1
  67. data/app/controllers/concerns/blacklight/bookmarks.rb +3 -3
  68. data/app/controllers/concerns/blacklight/catalog.rb +10 -25
  69. data/app/controllers/concerns/blacklight/controller.rb +1 -1
  70. data/app/controllers/concerns/blacklight/facetable.rb +34 -0
  71. data/app/controllers/concerns/blacklight/search_context.rb +1 -1
  72. data/app/controllers/concerns/blacklight/searchable.rb +1 -1
  73. data/app/helpers/blacklight/configuration_helper_behavior.rb +2 -2
  74. data/app/helpers/blacklight/document_helper_behavior.rb +3 -1
  75. data/app/helpers/blacklight/facets_helper_behavior.rb +9 -0
  76. data/app/helpers/blacklight/icon_helper_behavior.rb +2 -2
  77. data/app/javascript/blacklight-frontend/checkbox_submit.js +3 -0
  78. data/app/javascript/blacklight-frontend/debounce.js +1 -1
  79. data/app/javascript/blacklight-frontend/facet_suggest.js +23 -3
  80. data/app/javascript/blacklight-frontend/index.js +0 -2
  81. data/app/javascript/blacklight-frontend/modal.js +1 -4
  82. data/app/javascript/blacklight-frontend/search_context.js +3 -2
  83. data/app/models/facet_search_builder.rb +5 -0
  84. data/app/presenters/blacklight/facet_field_presenter.rb +1 -1
  85. data/app/presenters/blacklight/json_presenter.rb +1 -3
  86. data/app/presenters/blacklight/rendering/helper_method.rb +4 -4
  87. data/app/presenters/blacklight/rendering/join.rb +2 -2
  88. data/app/services/blacklight/facet_search_service.rb +44 -0
  89. data/app/services/blacklight/field_retriever.rb +1 -1
  90. data/app/services/blacklight/search_service.rb +6 -6
  91. data/app/values/blacklight/types.rb +2 -2
  92. data/app/views/catalog/_facet_pivot.html.erb +1 -1
  93. data/app/views/catalog/_home_text.html.erb +2 -2
  94. data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
  95. data/app/views/catalog/facet.html.erb +8 -10
  96. data/config/locales/blacklight.ar.yml +2 -2
  97. data/config/locales/blacklight.es.yml +2 -2
  98. data/config/locales/blacklight.fr.yml +2 -2
  99. data/config/locales/blacklight.hu.yml +2 -2
  100. data/config/locales/blacklight.it.yml +2 -2
  101. data/config/locales/blacklight.nl.yml +1 -1
  102. data/config/locales/blacklight.pt-BR.yml +2 -2
  103. data/config/locales/blacklight.sq.yml +2 -2
  104. data/config/locales/blacklight.zh.yml +2 -2
  105. data/lib/blacklight/abstract_repository.rb +2 -2
  106. data/lib/blacklight/abstract_search_builder.rb +154 -0
  107. data/lib/blacklight/configuration/context.rb +3 -3
  108. data/lib/blacklight/configuration/facet_field.rb +6 -6
  109. data/lib/blacklight/configuration/field.rb +4 -4
  110. data/lib/blacklight/configuration/fields.rb +0 -1
  111. data/lib/blacklight/configuration/search_field.rb +1 -1
  112. data/lib/blacklight/configuration/view_config.rb +2 -2
  113. data/lib/blacklight/configuration.rb +6 -7
  114. data/lib/blacklight/facet_search_builder.rb +18 -0
  115. data/lib/blacklight/nested_open_struct_with_hash_access.rb +1 -1
  116. data/lib/blacklight/open_struct_with_hash_access.rb +2 -2
  117. data/lib/blacklight/search_builder.rb +1 -159
  118. data/lib/blacklight/search_state/filter_field.rb +4 -4
  119. data/lib/blacklight/search_state/pivot_filter_field.rb +4 -4
  120. data/lib/blacklight/solr/abstract_filter_query_builder.rb +77 -0
  121. data/lib/blacklight/solr/default_filter_query_builder.rb +20 -0
  122. data/lib/blacklight/solr/facet_search_builder_behavior.rb +62 -0
  123. data/lib/blacklight/solr/repository.rb +8 -9
  124. data/lib/blacklight/solr/response/facets.rb +2 -2
  125. data/lib/blacklight/solr/response/params.rb +0 -4
  126. data/lib/blacklight/solr/response.rb +5 -1
  127. data/lib/blacklight/solr/search_builder_behavior.rb +17 -132
  128. data/lib/blacklight.rb +1 -1
  129. data/lib/generators/blacklight/assets/importmap_generator.rb +3 -5
  130. data/lib/generators/blacklight/assets_generator.rb +1 -1
  131. data/lib/generators/blacklight/search_builder_generator.rb +1 -1
  132. data/lib/generators/blacklight/templates/.solr_wrapper.yml +2 -0
  133. data/lib/generators/blacklight/templates/catalog_controller.rb +3 -1
  134. data/lib/generators/blacklight/templates/solr/conf/solrconfig.xml +0 -4
  135. data/package.json +3 -3
  136. data/spec/components/blacklight/advanced_search_form_component_spec.rb +18 -22
  137. data/spec/components/blacklight/constraint_layout_component_spec.rb +8 -8
  138. data/spec/components/blacklight/constraints_component_spec.rb +11 -11
  139. data/spec/components/blacklight/document/action_component_spec.rb +23 -15
  140. data/spec/components/blacklight/document/group_component_spec.rb +10 -15
  141. data/spec/components/blacklight/document/page_header_component_spec.rb +35 -28
  142. data/spec/components/blacklight/document/sidebar_component_spec.rb +5 -11
  143. data/spec/components/blacklight/document_component_spec.rb +98 -65
  144. data/spec/components/blacklight/facet_component_spec.rb +12 -8
  145. data/spec/components/blacklight/facet_item_pivot_component_spec.rb +12 -12
  146. data/spec/components/blacklight/{facet_field_checkboxes_component_spec.rb → facets/checkboxes_component_spec.rb} +13 -13
  147. data/spec/components/blacklight/facets/filters_component_spec.rb +36 -0
  148. data/spec/components/blacklight/facets/index_navigation_component_spec.rb +40 -0
  149. data/spec/components/blacklight/{facet_item_component_spec.rb → facets/item_component_spec.rb} +10 -10
  150. data/spec/components/blacklight/{facet_field_list_component_spec.rb → facets/list_component_spec.rb} +23 -23
  151. data/spec/components/blacklight/facets/suggest_component_spec.rb +68 -0
  152. data/spec/components/blacklight/header_component_spec.rb +2 -4
  153. data/spec/components/blacklight/hidden_search_state_component_spec.rb +7 -7
  154. data/spec/components/blacklight/metadata_field_component_spec.rb +17 -15
  155. data/spec/components/blacklight/response/facet_group_component_spec.rb +37 -0
  156. data/spec/components/blacklight/response/pagination_component_spec.rb +1 -1
  157. data/spec/components/blacklight/response/spellcheck_component_spec.rb +1 -1
  158. data/spec/components/blacklight/search_bar_component_spec.rb +4 -4
  159. data/spec/components/blacklight/search_context/server_applied_params_component_spec.rb +2 -2
  160. data/spec/components/blacklight/search_context/server_item_pagination_component_spec.rb +3 -5
  161. data/spec/components/blacklight/skip_link_component_spec.rb +8 -11
  162. data/spec/components/blacklight/start_over_button_component_spec.rb +4 -4
  163. data/spec/components/blacklight/system/dropdown_component_spec.rb +26 -0
  164. data/spec/components/blacklight/system/flash_message_component_spec.rb +7 -11
  165. data/spec/controllers/catalog_controller_spec.rb +12 -20
  166. data/spec/features/facets_spec.rb +70 -7
  167. data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +10 -0
  168. data/spec/lib/blacklight/configuration/facet_field_spec.rb +2 -2
  169. data/spec/lib/blacklight/parameters_spec.rb +12 -1
  170. data/spec/lib/blacklight/search_state/filter_field_spec.rb +18 -0
  171. data/spec/models/blacklight/configuration_spec.rb +32 -28
  172. data/spec/models/blacklight/facet_search_builder_spec.rb +19 -0
  173. data/spec/models/blacklight/search_builder_spec.rb +1 -11
  174. data/spec/models/blacklight/solr/default_filter_query_builder_spec.rb +72 -0
  175. data/spec/models/blacklight/solr/document_spec.rb +0 -4
  176. data/spec/models/blacklight/solr/facet_search_builder_behavior_spec.rb +929 -0
  177. data/spec/models/blacklight/solr/repository_spec.rb +31 -29
  178. data/spec/models/blacklight/solr/response/facets_spec.rb +86 -40
  179. data/spec/models/blacklight/solr/response/group_response_spec.rb +8 -5
  180. data/spec/models/blacklight/solr/response/group_spec.rb +9 -5
  181. data/spec/models/blacklight/solr/response_spec.rb +96 -64
  182. data/spec/models/blacklight/solr/search_builder_behavior_spec.rb +2 -227
  183. data/spec/models/solr_document_spec.rb +5 -1
  184. data/spec/services/blacklight/search_service_spec.rb +6 -27
  185. data/spec/spec_helper.rb +0 -1
  186. data/spec/support/view_component_test_helpers.rb +0 -18
  187. data/spec/views/catalog/facet.html.erb_spec.rb +10 -3
  188. data/spec/views/catalog/index.atom.builder_spec.rb +6 -3
  189. data/spec/views/catalog/index.html.erb_spec.rb +3 -1
  190. metadata +58 -29
  191. data/.github/workflows/ruby.yml +0 -98
  192. data/app/components/blacklight/facet_field_list_component.html.erb +0 -19
  193. data/app/components/blacklight/search/facet_suggest_input.html.erb +0 -9
  194. data/app/components/blacklight/search/facet_suggest_input.rb +0 -16
  195. data/app/javascript/blacklight-frontend/modalForm.js +0 -60
  196. data/app/views/catalog/_facet_index_navigation.html.erb +0 -1
  197. data/app/views/catalog/_facet_layout.html.erb +0 -8
  198. data/app/views/catalog/_facet_pagination.html.erb +0 -1
  199. data/spec/components/blacklight/document_metadata_component_spec.rb +0 -0
  200. data/spec/components/blacklight/search/facet_suggest_input_spec.rb +0 -33
  201. data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +0 -43
  202. data/spec/views/catalog/_facet_layout.html.erb_spec.rb +0 -41
  203. /data/app/components/blacklight/{facet_field_checkboxes_component.html.erb → facets/checkboxes_component.html.erb} +0 -0
@@ -6,14 +6,7 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
6
6
  subject(:component) { described_class.new(document: document, **attr) }
7
7
 
8
8
  let(:attr) { {} }
9
- let(:view_context) { controller.view_context }
10
- let(:render) do
11
- component.render_in(view_context)
12
- end
13
-
14
- let(:rendered) do
15
- Capybara::Node::Simple.new(render)
16
- end
9
+ let(:view_context) { vc_test_controller.view_context }
17
10
 
18
11
  let(:document) { view_context.document_presenter(presented_document) }
19
12
 
@@ -36,7 +29,7 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
36
29
 
37
30
  before do
38
31
  # Every call to view_context returns a different object. This ensures it stays stable.
39
- allow(controller).to receive_messages(view_context: view_context, current_or_guest_user: User.new, blacklight_config: blacklight_config)
32
+ allow(vc_test_controller).to receive_messages(view_context: view_context, current_or_guest_user: User.new, blacklight_config: blacklight_config)
40
33
  allow(view_context).to receive_messages(search_session: {}, current_search_session: nil, current_bookmarks: [])
41
34
  end
42
35
 
@@ -46,78 +39,92 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
46
39
  component.set_slot(:metadata, nil, 'Metadata')
47
40
  component.set_slot(:thumbnail, nil, 'Thumbnail')
48
41
  component.set_slot(:actions) { 'Actions' }
42
+ render_inline component
49
43
 
50
- expect(rendered).to have_content 'Title'
51
- expect(rendered).to have_content 'Embed'
52
- expect(rendered).to have_content 'Metadata'
53
- expect(rendered).to have_content 'Thumbnail'
54
- expect(rendered).to have_content 'Actions'
44
+ expect(page).to have_content 'Title'
45
+ expect(page).to have_content 'Embed'
46
+ expect(page).to have_content 'Metadata'
47
+ expect(page).to have_content 'Thumbnail'
48
+ expect(page).to have_content 'Actions'
55
49
  end
56
50
 
57
51
  it 'has schema.org properties' do
58
52
  component.set_slot(:body) { '-' }
53
+ render_inline component
59
54
 
60
- expect(rendered).to have_css 'article[@itemtype="http://schema.org/Thing"]'
61
- expect(rendered).to have_css 'article[@itemscope]'
55
+ expect(page).to have_css 'article[@itemtype="http://schema.org/Thing"]'
56
+ expect(page).to have_css 'article[@itemscope]'
62
57
  end
63
58
 
64
59
  context 'with a provided body' do
65
60
  it 'opts-out of normal component content' do
66
61
  component.set_slot(:body) { 'Body content' }
62
+ render_inline component
67
63
 
68
- expect(rendered).to have_content 'Body content'
69
- expect(rendered).to have_no_css 'header'
70
- expect(rendered).to have_no_css 'dl'
64
+ expect(page).to have_content 'Body content'
65
+ expect(page).to have_no_css 'header'
66
+ expect(page).to have_no_css 'dl'
71
67
  end
72
68
  end
73
69
 
74
70
  context 'index view' do
75
71
  before do
76
- controller.action_name = "index"
72
+ vc_test_controller.action_name = "index"
77
73
  end
78
74
 
79
75
  let(:attr) { { counter: 5 } }
80
76
 
81
77
  it 'has data properties' do
82
78
  component.set_slot(:body) { '-' }
79
+ render_inline component
83
80
 
84
- expect(rendered).to have_css 'article[@data-document-id="x"]'
85
- expect(rendered).to have_css 'article[@data-document-counter="5"]'
81
+ expect(page).to have_css 'article[@data-document-id="x"]'
82
+ expect(page).to have_css 'article[@data-document-counter="5"]'
86
83
  end
87
84
 
88
85
  it 'renders a linked title' do
89
- expect(rendered).to have_link 'Title', href: '/catalog/x'
86
+ render_inline component
87
+
88
+ expect(page).to have_link 'Title', href: '/catalog/x'
90
89
  end
91
90
 
92
91
  it 'renders a counter with the title' do
93
- expect(rendered).to have_css 'header', text: '5. Title'
92
+ render_inline component
93
+
94
+ expect(page).to have_css 'header', text: '5. Title'
94
95
  end
95
96
 
96
97
  context 'with a document rendered as part of a collection' do
97
- # ViewComponent 3 changes iteration counters to begin at 0 rather than 1
98
- let(:document_counter) { ViewComponent::VERSION::MAJOR < 3 ? 11 : 10 }
98
+ let(:document_counter) { 10 }
99
99
  let(:attr) { { document_counter: document_counter, counter_offset: 100 } }
100
100
 
101
101
  it 'renders a counter with the title' do
102
- # after ViewComponent 2.5, collection counter params are 1-indexed
103
- expect(rendered).to have_css 'header', text: '111. Title'
102
+ render_inline component
103
+
104
+ expect(page).to have_css 'header', text: '111. Title'
104
105
  end
105
106
  end
106
107
 
107
108
  it 'renders actions' do
108
- expect(rendered).to have_css '.index-document-functions'
109
+ render_inline component
110
+
111
+ expect(page).to have_css '.index-document-functions'
109
112
  end
110
113
 
111
114
  it 'renders a thumbnail' do
112
- expect(rendered).to have_css 'a[href="/catalog/x"] img[src="http://example.com/image.jpg"]'
115
+ render_inline component
116
+
117
+ expect(page).to have_css 'a[href="/catalog/x"] img[src="http://example.com/image.jpg"]'
113
118
  end
114
119
 
115
120
  context 'with default metadata component' do
116
121
  it 'renders metadata' do
117
- expect(rendered).to have_css 'dl.document-metadata'
118
- expect(rendered).to have_css 'dt', text: 'Title:'
119
- expect(rendered).to have_css 'dd', text: 'Title'
120
- expect(rendered).to have_no_css 'dt', text: 'ISBN:'
122
+ render_inline component
123
+
124
+ expect(page).to have_css 'dl.document-metadata'
125
+ expect(page).to have_css 'dt', text: 'Title:'
126
+ expect(page).to have_css 'dd', text: 'Title'
127
+ expect(page).to have_no_css 'dt', text: 'ISBN:'
121
128
  end
122
129
  end
123
130
  end
@@ -126,44 +133,58 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
126
133
  let(:attr) { { title_component: :h1, show: true } }
127
134
 
128
135
  before do
129
- controller.action_name = "show"
136
+ vc_test_controller.action_name = "show"
130
137
  end
131
138
 
132
139
  it 'renders with an id' do
133
140
  component.set_slot(:body) { '-' }
141
+ render_inline component
134
142
 
135
- expect(rendered).to have_css 'article#document'
143
+ expect(page).to have_css 'article#document'
136
144
  end
137
145
 
138
146
  it 'renders a title' do
139
- expect(rendered).to have_css 'h1', text: 'Title'
147
+ render_inline component
148
+
149
+ expect(page).to have_css 'h1', text: 'Title'
140
150
  end
141
151
 
142
152
  it 'renders with show-specific metadata' do
143
- expect(rendered).to have_css 'dl.document-metadata'
144
- expect(rendered).to have_css 'dt', text: 'ISBN:'
145
- expect(rendered).to have_css 'dd', text: 'Value'
153
+ render_inline component
154
+
155
+ expect(page).to have_css 'dl.document-metadata'
156
+ expect(page).to have_css 'dt', text: 'ISBN:'
157
+ expect(page).to have_css 'dd', text: 'Value'
146
158
  end
147
159
 
148
- it 'renders an embed' do
149
- stub_const('StubComponent', Class.new(ViewComponent::Base) do
150
- def initialize(**); end
160
+ context 'with an embed component' do
161
+ before do
162
+ vc_test_controller.action_name = "show"
151
163
 
152
- def call
153
- 'embed'.html_safe
154
- end
155
- end)
164
+ stub_const('StubComponent', Class.new(ViewComponent::Base) do
165
+ def initialize(**); end
156
166
 
157
- blacklight_config.show.embed_component = StubComponent
158
- expect(rendered).to have_content 'embed'
167
+ def call
168
+ 'embed'.html_safe
169
+ end
170
+ end)
171
+
172
+ blacklight_config.show.embed_component = StubComponent
173
+ render_inline component
174
+ end
175
+
176
+ it 'renders an embed' do
177
+ expect(page).to have_content 'embed'
178
+ end
159
179
  end
160
180
 
161
181
  context 'show view with custom translation' do
162
182
  let!(:original_translations) { I18n.backend.send(:translations).deep_dup }
163
183
 
164
184
  before do
165
- controller.action_name = "show"
185
+ vc_test_controller.action_name = "show"
166
186
  I18n.backend.store_translations(:en, blacklight: { search: { show: { label: "testing:%{label}" } } })
187
+ render_inline component
167
188
  end
168
189
 
169
190
  after do
@@ -172,9 +193,9 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
172
193
  end
173
194
 
174
195
  it 'renders with show-specific metadata with correct translation' do
175
- expect(rendered).to have_css 'dl.document-metadata'
176
- expect(rendered).to have_css 'dt', text: 'testing:ISBN'
177
- expect(rendered).to have_css 'dd', text: 'Value'
196
+ expect(page).to have_css 'dl.document-metadata'
197
+ expect(page).to have_css 'dt', text: 'testing:ISBN'
198
+ expect(page).to have_css 'dd', text: 'Value'
178
199
  end
179
200
  end
180
201
 
@@ -191,10 +212,11 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
191
212
  before do
192
213
  stub_const('MyMetadataComponent', custom_component_class)
193
214
  blacklight_config.show.metadata_component = MyMetadataComponent
215
+ render_inline component
194
216
  end
195
217
 
196
218
  it 'renders custom component' do
197
- expect(rendered).to have_text 'blah'
219
+ expect(page).to have_text 'blah'
198
220
  end
199
221
  end
200
222
 
@@ -211,36 +233,47 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
211
233
  before do
212
234
  stub_const('MyTitleComponent', custom_component_class)
213
235
  blacklight_config.show.title_component = MyTitleComponent
236
+ render_inline component
214
237
  end
215
238
 
216
239
  it 'renders custom component' do
217
- expect(rendered).to have_text 'Titleriffic'
240
+ expect(page).to have_text 'Titleriffic'
218
241
  end
219
242
  end
220
243
  end
221
244
 
222
- it 'renders partials' do
223
- component.with_partial { 'Partials' }
224
- expect(rendered).to have_content 'Partials'
245
+ context 'with partials' do
246
+ before do
247
+ component.with_partial { 'Partials' }
248
+ render_inline component
249
+ end
250
+
251
+ it 'renders partials' do
252
+ expect(page).to have_content 'Partials'
253
+ end
225
254
  end
226
255
 
227
- it 'has no partials by default' do
228
- component.render_in(view_context)
256
+ context 'with no partials (default behavior)' do
257
+ before do
258
+ render_inline component
259
+ end
229
260
 
230
- expect(component.partials?).to be false
261
+ it 'has no partials by default' do
262
+ expect(component.partials?).to be false
263
+ end
231
264
  end
232
265
 
233
266
  context 'with before_titles' do
234
- let(:render) do
235
- component.render_in(view_context) do
236
- component.with_title do |c|
267
+ before do
268
+ render_inline(component) do |inner_c|
269
+ inner_c.with_title do |c|
237
270
  c.with_before_title { 'Prefix!' }
238
271
  end
239
272
  end
240
273
  end
241
274
 
242
275
  it 'shows the prefix' do
243
- expect(rendered).to have_content "Prefix!"
276
+ expect(page).to have_content "Prefix!"
244
277
  end
245
278
  end
246
279
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe Blacklight::FacetComponent, type: :component do
6
6
  subject(:rendered) do
7
- render_inline_to_capybara_node(component)
7
+ render_inline(component)
8
8
  end
9
9
 
10
10
  let(:component) { described_class.new(**component_kwargs) }
@@ -18,13 +18,14 @@ RSpec.describe Blacklight::FacetComponent, type: :component do
18
18
  let(:facet_config) { Blacklight::Configuration::FacetField.new(key: 'field').normalize! }
19
19
 
20
20
  it 'delegates to the configured component to render something' do
21
- expect(rendered).to have_css 'ul.facet-values'
21
+ rendered
22
+ expect(page).to have_css 'ul.facet-values'
22
23
  end
23
24
 
24
25
  context 'with a provided component' do
25
26
  let(:component_kwargs) { { field_config: facet_config, display_facet: display_facet, component: component_class } }
26
27
  let(:component_class) do
27
- Class.new(Blacklight::FacetFieldListComponent) do
28
+ Class.new(Blacklight::Facets::ListComponent) do
28
29
  def self.name
29
30
  'CustomFacetComponent'
30
31
  end
@@ -35,8 +36,10 @@ RSpec.describe Blacklight::FacetComponent, type: :component do
35
36
  end
36
37
  end
37
38
 
39
+ before { rendered }
40
+
38
41
  it 'renders the provided component' do
39
- expect(rendered).to have_content 'Custom facet rendering'
42
+ expect(page).to have_content 'Custom facet rendering'
40
43
  end
41
44
  end
42
45
 
@@ -53,14 +56,15 @@ RSpec.describe Blacklight::FacetComponent, type: :component do
53
56
  replace_hash = { 'catalog/_facet_partial.html.erb' => 'facet partial' }
54
57
 
55
58
  if Rails.version.to_f >= 7.1
56
- controller.prepend_view_path(RSpec::Rails::ViewExampleGroup::StubResolverCache.resolver_for(replace_hash))
59
+ vc_test_controller.prepend_view_path(RSpec::Rails::ViewExampleGroup::StubResolverCache.resolver_for(replace_hash))
57
60
  else
58
- controller.view_context.view_paths.unshift(RSpec::Rails::ViewExampleGroup::StubResolverCache.resolver_for(replace_hash))
61
+ vc_test_controller.view_context.view_paths.unshift(RSpec::Rails::ViewExampleGroup::StubResolverCache.resolver_for(replace_hash))
59
62
  end
63
+ rendered
60
64
  end
61
65
 
62
66
  it 'renders the partial' do
63
- expect(rendered).to have_content 'facet partial'
67
+ expect(page).to have_content 'facet partial'
64
68
  end
65
69
  end
66
70
 
@@ -113,7 +117,7 @@ RSpec.describe Blacklight::FacetComponent, type: :component do
113
117
  { display_facet_or_field_config: presenter }
114
118
  end
115
119
 
116
- let(:presenter) { Blacklight::FacetFieldPresenter.new(facet_config, display_facet, controller.view_context) }
120
+ let(:presenter) { Blacklight::FacetFieldPresenter.new(facet_config, display_facet, vc_test_controller.view_context) }
117
121
 
118
122
  it 'renders the component with the provided presenter' do
119
123
  allow(facet_config.component).to receive(:new).and_call_original
@@ -3,8 +3,8 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Blacklight::FacetItemPivotComponent, type: :component do
6
- subject(:rendered) do
7
- render_inline_to_capybara_node(described_class.new(facet_item: facet_item))
6
+ before do
7
+ render_inline(described_class.new(facet_item: facet_item))
8
8
  end
9
9
 
10
10
  let(:blacklight_config) do
@@ -31,17 +31,17 @@ RSpec.describe Blacklight::FacetItemPivotComponent, type: :component do
31
31
  )
32
32
  end
33
33
 
34
- let(:facet_config) { Blacklight::Configuration::NullField.new(key: 'z', item_component: Blacklight::FacetItemComponent, item_presenter: Blacklight::FacetItemPivotPresenter) }
34
+ let(:facet_config) { Blacklight::Configuration::NullField.new(key: 'z', item_component: Blacklight::Facets::ItemComponent, item_presenter: Blacklight::FacetItemPivotPresenter) }
35
35
 
36
36
  it 'links to the facet and shows the number of hits' do
37
- expect(rendered).to have_css 'li'
38
- expect(rendered).to have_link 'x', href: nokogiri_mediated_href(facet_item.href)
39
- expect(rendered).to have_css '.facet-count', text: '10'
37
+ expect(page).to have_css 'li'
38
+ expect(page).to have_link 'x', href: nokogiri_mediated_href(facet_item.href)
39
+ expect(page).to have_css '.facet-count', text: '10'
40
40
  end
41
41
 
42
42
  it 'has the facet hierarchy' do
43
- expect(rendered).to have_css 'li ul.pivot-facet'
44
- expect(rendered).to have_link 'x:1', href: nokogiri_mediated_href(facet_item.facet_item_presenters.first.href)
43
+ expect(page).to have_css 'li ul.pivot-facet'
44
+ expect(page).to have_link 'x:1', href: nokogiri_mediated_href(facet_item.facet_item_presenters.first.href)
45
45
  end
46
46
 
47
47
  context 'with a selected facet' do
@@ -60,10 +60,10 @@ RSpec.describe Blacklight::FacetItemPivotComponent, type: :component do
60
60
  end
61
61
 
62
62
  it 'links to the facet and shows the number of hits' do
63
- expect(rendered).to have_css 'li'
64
- expect(rendered).to have_css '.selected', text: 'x'
65
- expect(rendered).to have_link '[remove]', href: '/catalog'
66
- expect(rendered).to have_css '.selected.facet-count', text: '10'
63
+ expect(page).to have_css 'li'
64
+ expect(page).to have_css '.selected', text: 'x'
65
+ expect(page).to have_link '[remove]', href: '/catalog'
66
+ expect(page).to have_css '.selected.facet-count', text: '10'
67
67
  end
68
68
  end
69
69
  end
@@ -2,15 +2,15 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Blacklight::FacetFieldCheckboxesComponent, type: :component do
6
- subject(:rendered) do
7
- render_inline_to_capybara_node(described_class.new(facet_field: facet_field))
5
+ RSpec.describe Blacklight::Facets::CheckboxesComponent, type: :component do
6
+ before do
7
+ render_inline(described_class.new(facet_field: facet_field))
8
8
  end
9
9
 
10
10
  let(:facet_field) do
11
11
  instance_double(
12
12
  Blacklight::FacetFieldPresenter,
13
- facet_field: Blacklight::Configuration::NullField.new(key: 'field', item_component: Blacklight::FacetItemComponent, item_presenter: Blacklight::FacetItemPresenter),
13
+ facet_field: Blacklight::Configuration::NullField.new(key: 'field', item_component: Blacklight::Facets::ItemComponent, item_presenter: Blacklight::FacetItemPresenter),
14
14
  paginator: paginator,
15
15
  key: 'field',
16
16
  label: 'Field',
@@ -33,18 +33,18 @@ RSpec.describe Blacklight::FacetFieldCheckboxesComponent, type: :component do
33
33
  let(:params) { { f: { field: ['a'] } } }
34
34
 
35
35
  it 'renders an accordion item' do
36
- expect(rendered).to have_css '.accordion-item'
37
- expect(rendered).to have_button 'Field'
38
- expect(rendered).to have_css 'button[data-bs-target="#facet-field"]'
39
- expect(rendered).to have_css '#facet-field.collapse.show'
36
+ expect(page).to have_css '.accordion-item'
37
+ expect(page).to have_button 'Field'
38
+ expect(page).to have_css 'button[data-bs-target="#facet-field"]'
39
+ expect(page).to have_css '#facet-field.collapse.show'
40
40
  end
41
41
 
42
42
  it 'renders the facet items' do
43
- expect(rendered).to have_css 'ul.facet-values'
44
- expect(rendered).to have_css 'li', count: 3
43
+ expect(page).to have_css 'ul.facet-values'
44
+ expect(page).to have_css 'li', count: 3
45
45
 
46
- expect(rendered).to have_field 'f_inclusive[field][]', with: 'a'
47
- expect(rendered).to have_field 'f_inclusive[field][]', with: 'b'
48
- expect(rendered).to have_field 'f_inclusive[field][]', with: 'c'
46
+ expect(page).to have_field 'f_inclusive[field][]', with: 'a'
47
+ expect(page).to have_field 'f_inclusive[field][]', with: 'b'
48
+ expect(page).to have_field 'f_inclusive[field][]', with: 'c'
49
49
  end
50
50
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Blacklight::Facets::FiltersComponent, type: :component do
6
+ let(:facet_field) { Blacklight::Configuration::FacetField.new key: 'language_facet', suggest: true }
7
+ let(:presenter) do
8
+ instance_double(Blacklight::FacetFieldPresenter, facet_field: facet_field, label: 'Lang',
9
+ view_context: view_context, suggest: true, key: 'lang')
10
+ end
11
+ let(:view_context) { vc_test_controller.view_context }
12
+
13
+ before do
14
+ allow(view_context).to receive(:search_facet_path).and_return('/catalog/facet/language_facet')
15
+
16
+ with_request_url '/catalog?q=foo' do
17
+ render_inline(component)
18
+ end
19
+ end
20
+
21
+ context 'with default classes' do
22
+ let(:component) { described_class.new(presenter: presenter) }
23
+
24
+ it 'draws default classes' do
25
+ expect(page).to have_css(".facet-filters.card.card-body.bg-light.p-3.mb-3.border-0")
26
+ end
27
+ end
28
+
29
+ context 'with custom classes' do
30
+ let(:component) { described_class.new(presenter: presenter, classes: 'foo') }
31
+
32
+ it 'draws default classes' do
33
+ expect(page).to have_css(".foo")
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Blacklight::Facets::IndexNavigationComponent, type: :component do
4
+ let(:pagination) { Blacklight::Solr::FacetPaginator.new([]) }
5
+ let(:facet) { Blacklight::Configuration::FacetField.new(index_range: '0'..'9', presenter: Blacklight::FacetFieldPresenter) }
6
+ let(:display_facet) { instance_double(Blacklight::Solr::Response::Facets::FacetField, items: [], offset: 0, prefix: '', sort: 'index', index?: true) }
7
+ let(:blacklight_config) { Blacklight::Configuration.new }
8
+
9
+ let(:presenter) { facet.presenter.new(facet, display_facet, vc_test_controller.view_context) }
10
+
11
+ before do
12
+ with_request_url "/catalog/facet/language" do
13
+ render_inline(described_class.new(presenter: presenter))
14
+ end
15
+ end
16
+
17
+ it 'renders the facet index navigation range' do
18
+ expect(page).to have_css '.pagination'
19
+ expect(page).to have_link '0', href: '/catalog/facet/language.html?facet.prefix=0&facet.sort=index'
20
+ expect(page).to have_link '1'
21
+ expect(page).to have_link '8'
22
+ expect(page).to have_link '9'
23
+ end
24
+
25
+ it 'renders an "all" button' do
26
+ expect(page).to have_css '.page-link', text: 'All'
27
+ end
28
+
29
+ context 'with a selected index' do
30
+ let(:display_facet) { instance_double(Blacklight::Solr::Response::Facets::FacetField, items: [], offset: 0, prefix: '5', sort: 'index', index?: true) }
31
+
32
+ it 'highlights the selected index' do
33
+ expect(page).to have_css '.active', text: '5'
34
+ end
35
+
36
+ it 'enables the clear facets button' do
37
+ expect(page).to have_link 'All'
38
+ end
39
+ end
40
+ end
@@ -2,9 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Blacklight::FacetItemComponent, type: :component do
6
- subject(:rendered) do
7
- render_inline_to_capybara_node(described_class.new(facet_item: facet_item))
5
+ RSpec.describe Blacklight::Facets::ItemComponent, type: :component do
6
+ before do
7
+ render_inline(described_class.new(facet_item: facet_item))
8
8
  end
9
9
 
10
10
  let(:facet_item) do
@@ -19,11 +19,11 @@ RSpec.describe Blacklight::FacetItemComponent, type: :component do
19
19
  end
20
20
 
21
21
  it 'links to the facet and shows the number of hits' do
22
- expect(rendered).to have_css 'li'
23
- expect(rendered).to have_link 'x', href: '/catalog?f=x' do |link|
22
+ expect(page).to have_css 'li'
23
+ expect(page).to have_link 'x', href: '/catalog?f=x' do |link|
24
24
  link['rel'] == 'nofollow'
25
25
  end
26
- expect(rendered).to have_css '.facet-count', text: '10'
26
+ expect(page).to have_css '.facet-count', text: '10'
27
27
  end
28
28
 
29
29
  context 'with a selected facet' do
@@ -39,12 +39,12 @@ RSpec.describe Blacklight::FacetItemComponent, type: :component do
39
39
  end
40
40
 
41
41
  it 'links to the facet and shows the number of hits' do
42
- expect(rendered).to have_css 'li'
43
- expect(rendered).to have_css '.selected', text: 'x'
44
- expect(rendered).to have_link '[remove]', href: '/catalog' do |link|
42
+ expect(page).to have_css 'li'
43
+ expect(page).to have_css '.selected', text: 'x'
44
+ expect(page).to have_link '[remove]', href: '/catalog' do |link|
45
45
  link['rel'] == 'nofollow'
46
46
  end
47
- expect(rendered).to have_css '.selected.facet-count', text: '10'
47
+ expect(page).to have_css '.selected.facet-count', text: '10'
48
48
  end
49
49
  end
50
50
  end