blacklight 9.0.0.beta1 → 9.0.0

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 (263) hide show
  1. checksums.yaml +4 -4
  2. data/.docker/app/Dockerfile +2 -1
  3. data/.github/matrix.json +55 -0
  4. data/.github/workflows/build.yml +16 -0
  5. data/.github/workflows/lint.yml +25 -0
  6. data/.github/workflows/main.yml +22 -0
  7. data/.github/workflows/release_7_x_scheduled.yml +39 -0
  8. data/.github/workflows/release_8_x_scheduled.yml +39 -0
  9. data/.github/workflows/test.yml +53 -0
  10. data/.rubocop.yml +81 -3
  11. data/.rubocop_todo.yml +46 -71
  12. data/.solr_wrapper.yml +3 -1
  13. data/README.md +2 -2
  14. data/VERSION +1 -1
  15. data/app/assets/builds/blacklight.css +51 -38
  16. data/app/assets/javascripts/blacklight/blacklight.esm.js +62 -77
  17. data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
  18. data/app/assets/javascripts/blacklight/blacklight.js +62 -77
  19. data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
  20. data/app/assets/stylesheets/blacklight/_blacklight_base.scss +0 -1
  21. data/app/assets/stylesheets/blacklight/_bootstrap_overrides.scss +4 -0
  22. data/app/assets/stylesheets/blacklight/_facets.scss +37 -29
  23. data/app/assets/stylesheets/blacklight/_header.scss +4 -0
  24. data/app/assets/stylesheets/blacklight/_modal.scss +9 -8
  25. data/app/assets/stylesheets/blacklight/_pagination.scss +1 -3
  26. data/app/assets/stylesheets/blacklight/_search_history.scss +0 -4
  27. data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +3 -0
  28. data/app/components/blacklight/advanced_search_form_component.html.erb +4 -4
  29. data/app/components/blacklight/advanced_search_form_component.rb +6 -5
  30. data/app/components/blacklight/constraint_component.html.erb +1 -5
  31. data/app/components/blacklight/constraint_component.rb +11 -0
  32. data/app/components/blacklight/constraint_layout_component.html.erb +1 -6
  33. data/app/components/blacklight/constraint_layout_component.rb +9 -0
  34. data/app/components/blacklight/constraints_component.html.erb +3 -8
  35. data/app/components/blacklight/constraints_component.rb +59 -14
  36. data/app/components/blacklight/document/action_component.rb +1 -3
  37. data/app/components/blacklight/document/bookmark_component.html.erb +3 -3
  38. data/app/components/blacklight/document/bookmark_component.rb +10 -4
  39. data/app/components/blacklight/document/group_component.html.erb +1 -1
  40. data/app/components/blacklight/document/more_like_this_component.rb +2 -2
  41. data/app/components/blacklight/document/page_header_component.rb +3 -3
  42. data/app/components/blacklight/document/thumbnail_component.html.erb +3 -7
  43. data/app/components/blacklight/document/thumbnail_component.rb +7 -6
  44. data/app/components/blacklight/document_component.html.erb +3 -3
  45. data/app/components/blacklight/document_component.rb +22 -26
  46. data/app/components/blacklight/document_title_component.rb +6 -10
  47. data/app/components/blacklight/facet_field_checkboxes_component.rb +4 -18
  48. data/app/components/blacklight/facet_field_component.rb +4 -15
  49. data/app/components/blacklight/facet_field_filter_component.rb +4 -19
  50. data/app/components/blacklight/facet_field_inclusive_constraint_component.rb +4 -23
  51. data/app/components/blacklight/facet_field_list_component.rb +4 -30
  52. data/app/components/blacklight/facet_field_no_layout_component.rb +4 -8
  53. data/app/components/blacklight/facet_field_pagination_component.html.erb +2 -2
  54. data/app/components/blacklight/facet_item_component.rb +4 -72
  55. data/app/components/blacklight/facet_item_pivot_component.rb +8 -4
  56. data/app/components/blacklight/{facet_field_checkboxes_component.html.erb → facets/checkboxes_component.html.erb} +4 -4
  57. data/app/components/blacklight/facets/checkboxes_component.rb +26 -0
  58. data/app/components/blacklight/facets/count_component.rb +23 -0
  59. data/app/components/blacklight/{facet_field_component.html.erb → facets/field_component.html.erb} +1 -3
  60. data/app/components/blacklight/facets/field_component.rb +23 -0
  61. data/app/components/blacklight/facets/filters_component.html.erb +4 -0
  62. data/app/components/blacklight/facets/filters_component.rb +39 -0
  63. data/app/components/blacklight/{facet_field_inclusive_constraint_component.html.erb → facets/inclusive_constraint_component.html.erb} +1 -1
  64. data/app/components/blacklight/facets/inclusive_constraint_component.rb +31 -0
  65. data/app/components/blacklight/{facet_field_filter_component.html.erb → facets/index_navigation_component.html.erb} +1 -1
  66. data/app/components/blacklight/facets/index_navigation_component.rb +32 -0
  67. data/app/components/blacklight/facets/item_component.rb +76 -0
  68. data/app/components/blacklight/facets/list_component.html.erb +11 -0
  69. data/app/components/blacklight/facets/list_component.rb +46 -0
  70. data/app/components/blacklight/facets/no_layout_component.rb +16 -0
  71. data/app/components/blacklight/facets/pivot_list_component.rb +14 -0
  72. data/app/components/blacklight/facets/selected_value_component.rb +29 -0
  73. data/app/components/blacklight/facets/suggest_component.html.erb +17 -0
  74. data/app/components/blacklight/facets/suggest_component.rb +21 -0
  75. data/app/components/blacklight/header_component.rb +2 -2
  76. data/app/components/blacklight/icons/remove_component.rb +2 -2
  77. data/app/components/blacklight/metadata_field_component.html.erb +2 -2
  78. data/app/components/blacklight/metadata_field_component.rb +2 -1
  79. data/app/components/blacklight/metadata_field_layout_component.rb +9 -4
  80. data/app/components/blacklight/metadata_field_plain_text_layout_component.rb +2 -2
  81. data/app/components/blacklight/response/facet_group_component.html.erb +3 -3
  82. data/app/components/blacklight/response/facet_group_component.rb +9 -1
  83. data/app/components/blacklight/search_bar_component.html.erb +2 -2
  84. data/app/components/blacklight/system/dropdown_component.html.erb +1 -1
  85. data/app/components/blacklight/system/dropdown_component.rb +1 -1
  86. data/app/components/blacklight/system/flash_message_component.html.erb +1 -1
  87. data/app/components/blacklight/system/flash_message_component.rb +0 -9
  88. data/app/components/blacklight/system/modal_component.html.erb +1 -2
  89. data/app/components/blacklight/top_navbar_component.html.erb +2 -2
  90. data/app/controllers/concerns/blacklight/bookmarks.rb +13 -3
  91. data/app/controllers/concerns/blacklight/catalog.rb +27 -30
  92. data/app/controllers/concerns/blacklight/controller.rb +1 -1
  93. data/app/controllers/concerns/blacklight/search_context.rb +1 -1
  94. data/app/controllers/concerns/blacklight/searchable.rb +1 -1
  95. data/app/helpers/blacklight/catalog_helper_behavior.rb +5 -3
  96. data/app/helpers/blacklight/configuration_helper_behavior.rb +2 -2
  97. data/app/helpers/blacklight/document_helper_behavior.rb +3 -1
  98. data/app/helpers/blacklight/facets_helper_behavior.rb +7 -12
  99. data/app/helpers/blacklight/icon_helper_behavior.rb +2 -2
  100. data/app/javascript/blacklight-frontend/bookmark_toggle.js +7 -2
  101. data/app/javascript/blacklight-frontend/button_focus.js +1 -1
  102. data/app/javascript/blacklight-frontend/checkbox_submit.js +9 -2
  103. data/app/javascript/blacklight-frontend/debounce.js +1 -1
  104. data/app/javascript/blacklight-frontend/facet_suggest.js +27 -3
  105. data/app/javascript/blacklight-frontend/index.js +0 -2
  106. data/app/javascript/blacklight-frontend/modal.js +15 -8
  107. data/app/javascript/blacklight-frontend/search_context.js +3 -2
  108. data/app/presenters/blacklight/constraint_presenter.rb +22 -0
  109. data/app/presenters/blacklight/document_presenter.rb +6 -5
  110. data/app/presenters/blacklight/facet_field_presenter.rb +18 -2
  111. data/app/presenters/blacklight/facet_grouped_item_presenter.rb +6 -0
  112. data/app/presenters/blacklight/facet_item_pivot_presenter.rb +1 -5
  113. data/app/presenters/blacklight/facet_item_presenter.rb +5 -18
  114. data/app/presenters/blacklight/field_presenter.rb +4 -2
  115. data/app/presenters/blacklight/json_presenter.rb +8 -4
  116. data/app/presenters/blacklight/rendering/abstract_step.rb +7 -1
  117. data/app/presenters/blacklight/rendering/helper_method.rb +4 -4
  118. data/app/presenters/blacklight/rendering/join.rb +11 -7
  119. data/app/presenters/blacklight/rendering/terminator.rb +1 -1
  120. data/app/services/blacklight/field_retriever.rb +1 -1
  121. data/app/services/blacklight/search_service.rb +10 -8
  122. data/app/values/blacklight/types.rb +2 -2
  123. data/app/views/blacklight/nav/_bookmark.html.erb +1 -1
  124. data/app/views/catalog/_document.atom.builder +1 -1
  125. data/app/views/catalog/_document.html.erb +1 -1
  126. data/app/views/catalog/_email_form.html.erb +4 -4
  127. data/app/views/catalog/_home_text.html.erb +2 -2
  128. data/app/views/catalog/_show_main_content.html.erb +9 -5
  129. data/app/views/catalog/_sms_form.html.erb +4 -4
  130. data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
  131. data/app/views/catalog/advanced_search.html.erb +1 -1
  132. data/app/views/catalog/facet.html.erb +8 -10
  133. data/app/views/catalog/index.html.erb +0 -1
  134. data/app/views/catalog/index.json.jbuilder +5 -3
  135. data/app/views/catalog/show.html.erb +2 -2
  136. data/app/views/layouts/blacklight/base.html.erb +1 -1
  137. data/blacklight.gemspec +1 -1
  138. data/config/locales/blacklight.ar.yml +14 -14
  139. data/config/locales/blacklight.ca.yml +2 -2
  140. data/config/locales/blacklight.de.yml +13 -13
  141. data/config/locales/blacklight.en.yml +3 -3
  142. data/config/locales/blacklight.es.yml +13 -13
  143. data/config/locales/blacklight.fr.yml +14 -14
  144. data/config/locales/blacklight.hu.yml +15 -15
  145. data/config/locales/blacklight.it.yml +16 -16
  146. data/config/locales/blacklight.nl.yml +13 -13
  147. data/config/locales/blacklight.pt-BR.yml +15 -15
  148. data/config/locales/blacklight.sq.yml +14 -14
  149. data/config/locales/blacklight.zh.yml +12 -12
  150. data/lib/blacklight/abstract_repository.rb +2 -2
  151. data/lib/blacklight/component.rb +7 -1
  152. data/lib/blacklight/configuration/context.rb +3 -3
  153. data/lib/blacklight/configuration/facet_field.rb +11 -6
  154. data/lib/blacklight/configuration/field.rb +4 -4
  155. data/lib/blacklight/configuration/fields.rb +0 -1
  156. data/lib/blacklight/configuration/search_field.rb +1 -1
  157. data/lib/blacklight/configuration/view_config.rb +32 -18
  158. data/lib/blacklight/configuration.rb +64 -10
  159. data/lib/blacklight/nested_open_struct_with_hash_access.rb +1 -1
  160. data/lib/blacklight/open_struct_with_hash_access.rb +2 -2
  161. data/lib/blacklight/routes/searchable.rb +1 -1
  162. data/lib/blacklight/search_builder.rb +2 -1
  163. data/lib/blacklight/search_state/filter_field.rb +4 -4
  164. data/lib/blacklight/search_state/pivot_filter_field.rb +5 -5
  165. data/lib/blacklight/search_state.rb +2 -0
  166. data/lib/blacklight/solr/abstract_filter_query_builder.rb +77 -0
  167. data/lib/blacklight/solr/default_filter_query_builder.rb +20 -0
  168. data/lib/blacklight/solr/field_reflection_search_builder.rb +11 -0
  169. data/lib/blacklight/solr/repository.rb +17 -15
  170. data/lib/blacklight/solr/response/facets.rb +2 -2
  171. data/lib/blacklight/solr/response/params.rb +0 -4
  172. data/lib/blacklight/solr/response.rb +5 -1
  173. data/lib/blacklight/solr/search_builder_behavior.rb +48 -97
  174. data/lib/blacklight/solr/single_doc_search_builder.rb +25 -0
  175. data/lib/blacklight.rb +6 -4
  176. data/lib/generators/blacklight/assets/importmap_generator.rb +3 -5
  177. data/lib/generators/blacklight/assets_generator.rb +1 -1
  178. data/lib/generators/blacklight/search_builder_generator.rb +1 -1
  179. data/lib/generators/blacklight/templates/.solr_wrapper.yml +3 -1
  180. data/lib/generators/blacklight/templates/catalog_controller.rb +34 -8
  181. data/lib/generators/blacklight/templates/solr/conf/solrconfig.xml +0 -71
  182. data/package.json +3 -3
  183. data/spec/components/blacklight/advanced_search_form_component_spec.rb +18 -22
  184. data/spec/components/blacklight/constraint_layout_component_spec.rb +8 -8
  185. data/spec/components/blacklight/constraints_component_spec.rb +11 -11
  186. data/spec/components/blacklight/document/action_component_spec.rb +23 -15
  187. data/spec/components/blacklight/document/group_component_spec.rb +10 -15
  188. data/spec/components/blacklight/document/page_header_component_spec.rb +35 -28
  189. data/spec/components/blacklight/document/sidebar_component_spec.rb +5 -11
  190. data/spec/components/blacklight/document_component_spec.rb +105 -79
  191. data/spec/components/blacklight/facet_component_spec.rb +12 -8
  192. data/spec/components/blacklight/facet_item_pivot_component_spec.rb +12 -12
  193. data/spec/components/blacklight/{facet_field_checkboxes_component_spec.rb → facets/checkboxes_component_spec.rb} +13 -13
  194. data/spec/components/blacklight/facets/filters_component_spec.rb +36 -0
  195. data/spec/components/blacklight/facets/index_navigation_component_spec.rb +41 -0
  196. data/spec/components/blacklight/{facet_item_component_spec.rb → facets/item_component_spec.rb} +10 -10
  197. data/spec/components/blacklight/{facet_field_list_component_spec.rb → facets/list_component_spec.rb} +34 -23
  198. data/spec/components/blacklight/facets/pivot_list_component_spec.rb +53 -0
  199. data/spec/components/blacklight/facets/suggest_component_spec.rb +82 -0
  200. data/spec/components/blacklight/header_component_spec.rb +2 -4
  201. data/spec/components/blacklight/hidden_search_state_component_spec.rb +7 -7
  202. data/spec/components/blacklight/metadata_field_component_spec.rb +17 -15
  203. data/spec/components/blacklight/response/facet_group_component_spec.rb +37 -0
  204. data/spec/components/blacklight/response/pagination_component_spec.rb +1 -1
  205. data/spec/components/blacklight/response/spellcheck_component_spec.rb +1 -1
  206. data/spec/components/blacklight/search_bar_component_spec.rb +28 -5
  207. data/spec/components/blacklight/search_context/server_applied_params_component_spec.rb +2 -2
  208. data/spec/components/blacklight/search_context/server_item_pagination_component_spec.rb +3 -5
  209. data/spec/components/blacklight/skip_link_component_spec.rb +8 -11
  210. data/spec/components/blacklight/start_over_button_component_spec.rb +4 -4
  211. data/spec/components/blacklight/system/dropdown_component_spec.rb +26 -0
  212. data/spec/components/blacklight/system/flash_message_component_spec.rb +7 -11
  213. data/spec/controllers/blacklight/catalog_spec.rb +1 -1
  214. data/spec/controllers/catalog_controller_spec.rb +12 -20
  215. data/spec/features/advanced_search_spec.rb +42 -21
  216. data/spec/features/facets_spec.rb +84 -12
  217. data/spec/features/modal_spec.rb +1 -1
  218. data/spec/features/search_filters_spec.rb +6 -4
  219. data/spec/features/search_spec.rb +3 -3
  220. data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +10 -0
  221. data/spec/lib/blacklight/configuration/facet_field_spec.rb +2 -2
  222. data/spec/lib/blacklight/parameters_spec.rb +12 -1
  223. data/spec/lib/blacklight/search_state/filter_field_spec.rb +18 -0
  224. data/spec/models/blacklight/configuration_spec.rb +178 -28
  225. data/spec/models/blacklight/solr/default_filter_query_builder_spec.rb +72 -0
  226. data/spec/models/blacklight/solr/document_spec.rb +0 -4
  227. data/spec/models/blacklight/solr/repository_spec.rb +37 -29
  228. data/spec/models/blacklight/solr/response/facets_spec.rb +86 -40
  229. data/spec/models/blacklight/solr/response/group_response_spec.rb +8 -5
  230. data/spec/models/blacklight/solr/response/group_spec.rb +9 -5
  231. data/spec/models/blacklight/solr/response_spec.rb +96 -64
  232. data/spec/models/blacklight/solr/search_builder_behavior_spec.rb +38 -57
  233. data/spec/models/solr_document_spec.rb +5 -1
  234. data/spec/presenters/blacklight/constraint_presenter_spec.rb +32 -0
  235. data/spec/presenters/blacklight/document_presenter_spec.rb +3 -3
  236. data/spec/presenters/blacklight/facet_item_presenter_spec.rb +0 -7
  237. data/spec/presenters/blacklight/field_presenter_spec.rb +103 -22
  238. data/spec/presenters/blacklight/json_presenter_spec.rb +17 -0
  239. data/spec/presenters/blacklight/rendering/pipeline_spec.rb +130 -14
  240. data/spec/services/blacklight/search_service_spec.rb +6 -27
  241. data/spec/spec_helper.rb +0 -1
  242. data/spec/support/presenter_test_helpers.rb +1 -1
  243. data/spec/support/view_component_test_helpers.rb +0 -18
  244. data/spec/views/catalog/facet.html.erb_spec.rb +10 -3
  245. data/spec/views/catalog/index.atom.builder_spec.rb +8 -3
  246. data/spec/views/catalog/index.html.erb_spec.rb +3 -1
  247. metadata +69 -38
  248. data/.github/workflows/ruby.yml +0 -98
  249. data/app/assets/stylesheets/blacklight/_icons.scss +0 -4
  250. data/app/components/blacklight/facet_field_list_component.html.erb +0 -19
  251. data/app/components/blacklight/search/facet_suggest_input.html.erb +0 -9
  252. data/app/components/blacklight/search/facet_suggest_input.rb +0 -16
  253. data/app/javascript/blacklight-frontend/modalForm.js +0 -60
  254. data/app/views/catalog/_facet_index_navigation.html.erb +0 -1
  255. data/app/views/catalog/_facet_layout.html.erb +0 -8
  256. data/app/views/catalog/_facet_pagination.html.erb +0 -1
  257. data/app/views/catalog/_facet_pivot.html.erb +0 -3
  258. data/app/views/shared/_sitelinks_search_box.html.erb +0 -12
  259. data/spec/components/blacklight/document_metadata_component_spec.rb +0 -0
  260. data/spec/components/blacklight/search/facet_suggest_input_spec.rb +0 -33
  261. data/spec/features/sitelinks_search_box_spec.rb +0 -13
  262. data/spec/views/catalog/_facet_index_navigation.html.erb_spec.rb +0 -43
  263. data/spec/views/catalog/_facet_layout.html.erb_spec.rb +0 -41
@@ -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,88 +29,102 @@ 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
 
43
36
  it 'has some defined content areas' do
44
- component.set_slot(:title) { 'Title' }
45
- component.set_slot(:embed, nil, 'Embed')
46
- component.set_slot(:metadata, nil, 'Metadata')
47
- component.set_slot(:thumbnail, nil, 'Thumbnail')
48
- component.set_slot(:actions) { 'Actions' }
49
-
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'
37
+ component.with_title { 'Title' }
38
+ component.with_embed('Embed')
39
+ component.with_metadata('Metadata')
40
+ component.with_thumbnail('Thumbnail')
41
+ component.with_actions { 'Actions' }
42
+ render_inline component
43
+
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
- component.set_slot(:body) { '-' }
52
+ component.with_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
- component.set_slot(:body) { 'Body content' }
61
+ component.with_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
- component.set_slot(:body) { '-' }
78
+ component.with_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,51 @@ 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"
130
- end
131
-
132
- it 'renders with an id' do
133
- component.set_slot(:body) { '-' }
134
-
135
- expect(rendered).to have_css 'article#document'
136
+ vc_test_controller.action_name = "show"
136
137
  end
137
138
 
138
139
  it 'renders a title' do
139
- expect(rendered).to have_css 'h1', text: 'Title'
140
+ render_inline component
141
+
142
+ expect(page).to have_css 'h1', text: 'Title'
140
143
  end
141
144
 
142
145
  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'
146
+ render_inline component
147
+
148
+ expect(page).to have_css 'dl.document-metadata'
149
+ expect(page).to have_css 'dt', text: 'ISBN:'
150
+ expect(page).to have_css 'dd', text: 'Value'
146
151
  end
147
152
 
148
- it 'renders an embed' do
149
- stub_const('StubComponent', Class.new(ViewComponent::Base) do
150
- def initialize(**); end
153
+ context 'with an embed component' do
154
+ before do
155
+ vc_test_controller.action_name = "show"
156
+
157
+ stub_const('StubComponent', Class.new(ViewComponent::Base) do
158
+ def initialize(**); end
151
159
 
152
- def call
153
- 'embed'.html_safe
154
- end
155
- end)
160
+ def call
161
+ 'embed'.html_safe
162
+ end
163
+ end)
156
164
 
157
- blacklight_config.show.embed_component = StubComponent
158
- expect(rendered).to have_content 'embed'
165
+ blacklight_config.show.embed_component = StubComponent
166
+ render_inline component
167
+ end
168
+
169
+ it 'renders an embed' do
170
+ expect(page).to have_content 'embed'
171
+ end
159
172
  end
160
173
 
161
174
  context 'show view with custom translation' do
162
175
  let!(:original_translations) { I18n.backend.send(:translations).deep_dup }
163
176
 
164
177
  before do
165
- controller.action_name = "show"
178
+ vc_test_controller.action_name = "show"
166
179
  I18n.backend.store_translations(:en, blacklight: { search: { show: { label: "testing:%{label}" } } })
180
+ render_inline component
167
181
  end
168
182
 
169
183
  after do
@@ -172,9 +186,9 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
172
186
  end
173
187
 
174
188
  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'
189
+ expect(page).to have_css 'dl.document-metadata'
190
+ expect(page).to have_css 'dt', text: 'testing:ISBN'
191
+ expect(page).to have_css 'dd', text: 'Value'
178
192
  end
179
193
  end
180
194
 
@@ -191,10 +205,11 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
191
205
  before do
192
206
  stub_const('MyMetadataComponent', custom_component_class)
193
207
  blacklight_config.show.metadata_component = MyMetadataComponent
208
+ render_inline component
194
209
  end
195
210
 
196
211
  it 'renders custom component' do
197
- expect(rendered).to have_text 'blah'
212
+ expect(page).to have_text 'blah'
198
213
  end
199
214
  end
200
215
 
@@ -211,36 +226,47 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
211
226
  before do
212
227
  stub_const('MyTitleComponent', custom_component_class)
213
228
  blacklight_config.show.title_component = MyTitleComponent
229
+ render_inline component
214
230
  end
215
231
 
216
232
  it 'renders custom component' do
217
- expect(rendered).to have_text 'Titleriffic'
233
+ expect(page).to have_text 'Titleriffic'
218
234
  end
219
235
  end
220
236
  end
221
237
 
222
- it 'renders partials' do
223
- component.with_partial { 'Partials' }
224
- expect(rendered).to have_content 'Partials'
238
+ context 'with partials' do
239
+ before do
240
+ component.with_partial { 'Partials' }
241
+ render_inline component
242
+ end
243
+
244
+ it 'renders partials' do
245
+ expect(page).to have_content 'Partials'
246
+ end
225
247
  end
226
248
 
227
- it 'has no partials by default' do
228
- component.render_in(view_context)
249
+ context 'with no partials (default behavior)' do
250
+ before do
251
+ render_inline component
252
+ end
229
253
 
230
- expect(component.partials?).to be false
254
+ it 'has no partials by default' do
255
+ expect(component.partials?).to be false
256
+ end
231
257
  end
232
258
 
233
259
  context 'with before_titles' do
234
- let(:render) do
235
- component.render_in(view_context) do
236
- component.with_title do |c|
260
+ before do
261
+ render_inline(component) do |inner_c|
262
+ inner_c.with_title do |c|
237
263
  c.with_before_title { 'Prefix!' }
238
264
  end
239
265
  end
240
266
  end
241
267
 
242
268
  it 'shows the prefix' do
243
- expect(rendered).to have_content "Prefix!"
269
+ expect(page).to have_content "Prefix!"
244
270
  end
245
271
  end
246
272
  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.treeitem ul li.treeitem'
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.mt-1.mb-3")
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,41 @@
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
+ facet_path = ViewComponent::VERSION::MAJOR == 3 ? '/catalog/facet/language.html' : '/catalog/facet/language'
20
+ expect(page).to have_link '0', href: "#{facet_path}?facet.prefix=0&facet.sort=index"
21
+ expect(page).to have_link '1'
22
+ expect(page).to have_link '8'
23
+ expect(page).to have_link '9'
24
+ end
25
+
26
+ it 'renders an "all" button' do
27
+ expect(page).to have_css '.page-link', text: 'All'
28
+ end
29
+
30
+ context 'with a selected index' do
31
+ let(:display_facet) { instance_double(Blacklight::Solr::Response::Facets::FacetField, items: [], offset: 0, prefix: '5', sort: 'index', index?: true) }
32
+
33
+ it 'highlights the selected index' do
34
+ expect(page).to have_css '.active', text: '5'
35
+ end
36
+
37
+ it 'enables the clear facets button' do
38
+ expect(page).to have_link 'All'
39
+ end
40
+ end
41
+ 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