blacklight 8.0.0.beta1 → 8.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 (151) hide show
  1. checksums.yaml +4 -4
  2. data/.env +1 -0
  3. data/.github/workflows/ruby.yml +6 -0
  4. data/.gitignore +1 -0
  5. data/.rubocop_todo.yml +3 -1
  6. data/README.md +1 -1
  7. data/Rakefile +18 -0
  8. data/VERSION +1 -1
  9. data/app/assets/config/blacklight/manifest.js +3 -0
  10. data/app/assets/javascripts/blacklight/blacklight.esm.js +132 -140
  11. data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
  12. data/app/assets/javascripts/blacklight/blacklight.js +132 -140
  13. data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
  14. data/app/assets/stylesheets/blacklight/_bootstrap_overrides.scss +1 -1
  15. data/app/assets/stylesheets/blacklight/_facets.scss +32 -5
  16. data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +1 -1
  17. data/app/components/blacklight/advanced_search_form_component.rb +3 -3
  18. data/app/components/blacklight/document/actions_component.rb +1 -1
  19. data/app/components/blacklight/document/show_tools_component.html.erb +12 -0
  20. data/app/components/blacklight/document/show_tools_component.rb +23 -0
  21. data/app/components/blacklight/document_component.rb +48 -20
  22. data/app/components/blacklight/document_metadata_component.html.erb +4 -2
  23. data/app/components/blacklight/document_metadata_component.rb +8 -2
  24. data/app/components/blacklight/facet_field_checkboxes_component.html.erb +2 -2
  25. data/app/components/blacklight/facet_field_list_component.html.erb +2 -2
  26. data/app/components/blacklight/metadata_field_component.html.erb +2 -2
  27. data/app/components/blacklight/metadata_field_layout_component.rb +7 -4
  28. data/app/components/blacklight/metadata_field_plain_text_layout_component.rb +17 -0
  29. data/app/components/blacklight/response/facet_group_component.html.erb +2 -1
  30. data/app/components/blacklight/response/facet_group_component.rb +1 -1
  31. data/app/components/blacklight/response/sort_component.rb +1 -1
  32. data/app/components/blacklight/response/spellcheck_component.rb +1 -1
  33. data/app/components/blacklight/response/view_type_button_component.rb +1 -1
  34. data/app/components/blacklight/response/view_type_component.rb +2 -2
  35. data/app/components/blacklight/search/sidebar_component.html.erb +1 -1
  36. data/app/components/blacklight/search_context/server_applied_params_component.html.erb +4 -0
  37. data/app/components/blacklight/search_context/server_applied_params_component.rb +13 -0
  38. data/app/components/blacklight/search_context/server_item_pagination_component.rb +71 -0
  39. data/app/components/blacklight/system/dropdown_component.rb +3 -3
  40. data/app/components/blacklight/system/flash_message_component.rb +2 -2
  41. data/app/components/blacklight/system/modal_component.rb +1 -1
  42. data/app/components/blacklight/top_navbar_component.html.erb +1 -1
  43. data/app/components/blacklight/top_navbar_component.rb +4 -0
  44. data/app/controllers/concerns/blacklight/bookmarks.rb +1 -1
  45. data/app/controllers/concerns/blacklight/search_context.rb +46 -6
  46. data/app/helpers/blacklight/blacklight_helper_behavior.rb +0 -101
  47. data/app/helpers/blacklight/catalog_helper_behavior.rb +27 -54
  48. data/app/helpers/blacklight/component_helper_behavior.rb +0 -11
  49. data/app/helpers/blacklight/document_helper_behavior.rb +76 -0
  50. data/app/helpers/blacklight/layout_helper_behavior.rb +59 -0
  51. data/app/helpers/blacklight/render_partials_helper_behavior.rb +1 -0
  52. data/app/helpers/blacklight/url_helper_behavior.rb +11 -3
  53. data/app/javascript/blacklight/bookmark_toggle.js +8 -15
  54. data/app/javascript/blacklight/button_focus.js +10 -10
  55. data/app/javascript/blacklight/index.js +6 -5
  56. data/app/javascript/blacklight/modal.js +24 -24
  57. data/app/javascript/blacklight/search_context.js +51 -57
  58. data/app/models/concerns/blacklight/document.rb +11 -0
  59. data/app/models/record_mailer.rb +19 -15
  60. data/app/presenters/blacklight/document_presenter.rb +13 -11
  61. data/app/presenters/blacklight/index_presenter.rb +1 -1
  62. data/app/presenters/blacklight/rendering/abstract_step.rb +4 -0
  63. data/app/presenters/blacklight/rendering/join.rb +7 -1
  64. data/app/presenters/blacklight/rendering/link_to_facet.rb +1 -1
  65. data/app/presenters/blacklight/rendering/microdata.rb +1 -1
  66. data/app/services/blacklight/search_service.rb +2 -1
  67. data/app/views/catalog/_document.atom.builder +1 -1
  68. data/app/views/catalog/_document.html.erb +3 -8
  69. data/app/views/catalog/_document_list.html.erb +2 -1
  70. data/app/views/catalog/_facet_layout.html.erb +2 -2
  71. data/app/views/catalog/_show_main_content.html.erb +5 -11
  72. data/app/views/catalog/_show_tools.html.erb +1 -14
  73. data/app/views/catalog/facet.html.erb +3 -3
  74. data/app/views/catalog/index.html.erb +3 -0
  75. data/app/views/catalog/show.html.erb +1 -6
  76. data/app/views/layouts/blacklight/base.html.erb +4 -5
  77. data/app/views/record_mailer/email_record.text.erb +4 -3
  78. data/app/views/record_mailer/sms_record.text.erb +4 -4
  79. data/blacklight.gemspec +2 -2
  80. data/config/importmap.rb +1 -1
  81. data/config/locales/blacklight.ar.yml +209 -232
  82. data/config/locales/blacklight.ca.yml +0 -6
  83. data/config/locales/blacklight.de.yml +197 -215
  84. data/config/locales/blacklight.en.yml +2 -6
  85. data/config/locales/blacklight.es.yml +196 -215
  86. data/config/locales/blacklight.fr.yml +196 -219
  87. data/config/locales/blacklight.hu.yml +193 -212
  88. data/config/locales/blacklight.it.yml +197 -215
  89. data/config/locales/blacklight.nl.yml +193 -212
  90. data/config/locales/blacklight.pt-BR.yml +195 -215
  91. data/config/locales/blacklight.sq.yml +193 -212
  92. data/config/locales/blacklight.zh.yml +194 -213
  93. data/docker-compose.yml +1 -0
  94. data/lib/blacklight/configuration/session_tracking_config.rb +45 -0
  95. data/lib/blacklight/configuration/view_config.rb +0 -4
  96. data/lib/blacklight/configuration.rb +8 -4
  97. data/lib/blacklight/engine.rb +6 -7
  98. data/lib/blacklight/routes/searchable.rb +1 -0
  99. data/lib/generators/blacklight/assets/importmap_generator.rb +9 -8
  100. data/lib/generators/blacklight/assets/propshaft_generator.rb +11 -2
  101. data/lib/generators/blacklight/assets/sprockets_generator.rb +2 -0
  102. data/lib/generators/blacklight/assets_generator.rb +3 -1
  103. data/lib/generators/blacklight/install_generator.rb +3 -1
  104. data/lib/generators/blacklight/templates/solr_document.rb +0 -6
  105. data/package.json +7 -4
  106. data/rollup.config.js +11 -1
  107. data/spec/components/blacklight/document_component_spec.rb +66 -15
  108. data/spec/components/blacklight/header_component_spec.rb +20 -0
  109. data/spec/components/blacklight/response/view_type_component_spec.rb +17 -0
  110. data/spec/components/blacklight/search_bar_component_spec.rb +1 -1
  111. data/spec/components/blacklight/search_context/server_applied_params_component_spec.rb +29 -0
  112. data/spec/components/blacklight/{search_context_component_spec.rb → search_context/server_item_pagination_component_spec.rb} +15 -4
  113. data/spec/controllers/bookmarks_controller_spec.rb +1 -1
  114. data/spec/controllers/catalog_controller_spec.rb +18 -6
  115. data/spec/features/component_template_override_spec.rb +8 -0
  116. data/spec/features/modal_spec.rb +12 -0
  117. data/spec/features/sitelinks_search_box_spec.rb +13 -0
  118. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +1 -1
  119. data/spec/helpers/blacklight_helper_spec.rb +0 -56
  120. data/spec/helpers/catalog_helper_spec.rb +56 -0
  121. data/spec/lib/blacklight/configuration/session_tracking_config_spec.rb +38 -0
  122. data/spec/lib/blacklight/open_struct_with_hash_access_spec.rb +2 -2
  123. data/spec/models/blacklight/configuration_spec.rb +2 -2
  124. data/spec/models/blacklight/icon_spec.rb +0 -2
  125. data/spec/models/blacklight/search_builder_spec.rb +3 -3
  126. data/spec/models/blacklight/solr/request_spec.rb +2 -2
  127. data/spec/models/record_mailer_spec.rb +36 -23
  128. data/spec/presenters/blacklight/document_presenter_spec.rb +1 -0
  129. data/spec/presenters/blacklight/field_presenter_spec.rb +2 -2
  130. data/spec/presenters/blacklight/index_presenter_spec.rb +1 -0
  131. data/spec/presenters/blacklight/show_presenter_spec.rb +1 -0
  132. data/spec/presenters/pipeline_spec.rb +13 -2
  133. data/spec/routing/catalog_routing_spec.rb +4 -0
  134. data/spec/spec_helper.rb +1 -1
  135. data/spec/support/view_component_test_helpers.rb +21 -0
  136. data/spec/test_app_templates/Gemfile.extra +4 -0
  137. data/spec/test_app_templates/lib/generators/test_app_generator.rb +8 -0
  138. data/spec/views/catalog/_document.html.erb_spec.rb +22 -1
  139. data/spec/views/catalog/_document_list.html.erb_spec.rb +7 -2
  140. data/spec/views/catalog/_show_tools.html.erb_spec.rb +2 -2
  141. data/spec/views/catalog/index.json.jbuilder_spec.rb +1 -1
  142. data/tasks/blacklight.rake +1 -1
  143. metadata +39 -21
  144. data/app/components/blacklight/search_context_component.rb +0 -68
  145. data/app/models/concerns/blacklight/document/email.rb +0 -27
  146. data/app/models/concerns/blacklight/document/sms.rb +0 -25
  147. data/spec/features/sitelinks_search_box.rb +0 -13
  148. data/spec/models/blacklight/document/email_spec.rb +0 -57
  149. data/spec/models/blacklight/document/sms_spec.rb +0 -58
  150. data/spec/support/view_component_capybara_test_helpers.rb +0 -8
  151. /data/app/components/blacklight/{search_context_component.html.erb → search_context/server_item_pagination_component.html.erb} +0 -0
@@ -172,8 +172,8 @@ RSpec.describe "Blacklight::Configuration", api: true do
172
172
 
173
173
  expect(config.a[:value]).to eq 1
174
174
  expect(config_copy.a[:value]).to eq 2
175
- expect(config.b).to match_array [1, 2, 3]
176
- expect(config_copy.b).to match_array [1, 2, 3, 5]
175
+ expect(config.b).to contain_exactly(1, 2, 3)
176
+ expect(config_copy.b).to contain_exactly(1, 2, 3, 5)
177
177
  expect(config.c.value).to match_array %w[a b]
178
178
  expect(config_copy.c.value).to match_array %w[a b c]
179
179
  end
@@ -12,8 +12,6 @@ RSpec.describe Blacklight::Icon do
12
12
  elsif defined?(Propshaft)
13
13
  allow(Rails.application.assets.load_path).to receive(:find).and_return(asset)
14
14
  end
15
- # FileUtils.mkdir_p '.internal_test_app/app/assets/images/blacklight'
16
- # File.write '.internal_test_app/app/assets/images/blacklight/test.svg', Blacklight::Icons::SearchComponent.new.svg
17
15
  end
18
16
 
19
17
  describe '#svg' do
@@ -45,7 +45,7 @@ RSpec.describe Blacklight::SearchBuilder, api: true do
45
45
 
46
46
  it "is mutable" do
47
47
  subject.processor_chain.insert(-1, :d)
48
- expect(subject.processor_chain).to match_array [:a, :b, :c, :d]
48
+ expect(subject.processor_chain).to contain_exactly(:a, :b, :c, :d)
49
49
  end
50
50
  end
51
51
 
@@ -56,7 +56,7 @@ RSpec.describe Blacklight::SearchBuilder, api: true do
56
56
  builder = subject.append(:d, :e)
57
57
  expect(subject.processor_chain).to eq processor_chain
58
58
  expect(builder.processor_chain).not_to eq subject.processor_chain
59
- expect(builder.processor_chain).to match_array [:a, :b, :c, :d, :e]
59
+ expect(builder.processor_chain).to contain_exactly(:a, :b, :c, :d, :e)
60
60
  end
61
61
  end
62
62
 
@@ -68,7 +68,7 @@ RSpec.describe Blacklight::SearchBuilder, api: true do
68
68
  expect(builder).not_to equal(subject)
69
69
  expect(subject.processor_chain).to eq processor_chain
70
70
  expect(builder.processor_chain).not_to eq subject.processor_chain
71
- expect(builder.processor_chain).to match_array [:a, :c, :e]
71
+ expect(builder.processor_chain).to contain_exactly(:a, :c, :e)
72
72
  end
73
73
  end
74
74
 
@@ -45,7 +45,7 @@ RSpec.describe Blacklight::Solr::Request, api: true do
45
45
  subject.append_query 'this is my query'
46
46
  subject.append_query 'another:query'
47
47
  expect(subject).not_to have_key 'q'
48
- expect(subject.dig('json', 'query', 'bool', 'must')).to match_array ['this is my query', 'another:query']
48
+ expect(subject.dig('json', 'query', 'bool', 'must')).to contain_exactly('this is my query', 'another:query')
49
49
  end
50
50
  end
51
51
 
@@ -62,7 +62,7 @@ RSpec.describe Blacklight::Solr::Request, api: true do
62
62
  subject['q'] = 'some query'
63
63
  subject.append_boolean_query :must, 'also required'
64
64
 
65
- expect(subject.dig('json', 'query', 'bool', 'must')).to match_array ['some query', 'also required']
65
+ expect(subject.dig('json', 'query', 'bool', 'must')).to contain_exactly('some query', 'also required')
66
66
  end
67
67
  end
68
68
  end
@@ -2,7 +2,16 @@
2
2
 
3
3
  RSpec.describe RecordMailer do
4
4
  let(:config) do
5
- Blacklight::Configuration.new
5
+ Blacklight::Configuration.new do |config|
6
+ config.email.title_field = 'title_tsim'
7
+ config.add_email_field 'title_tsim', label: 'Title'
8
+ config.add_email_field "author_tsim", label: 'Author'
9
+ config.add_email_field "language_ssim", label: 'Language'
10
+ config.add_email_field "format", label: 'Format'
11
+
12
+ config.add_sms_field 'title_tsim', label: 'Title'
13
+ config.add_sms_field "author_tsim", label: 'Author'
14
+ end
6
15
  end
7
16
 
8
17
  let(:document) do
@@ -11,37 +20,38 @@ RSpec.describe RecordMailer do
11
20
 
12
21
  before do
13
22
  allow(described_class).to receive(:default).and_return(from: 'no-reply@projectblacklight.org')
14
- SolrDocument.use_extension(Blacklight::Document::Email)
15
- SolrDocument.use_extension(Blacklight::Document::Sms)
16
23
  @documents = [document]
17
24
  end
18
25
 
19
26
  describe "email" do
20
- before do
21
- details = { to: 'test@test.com', message: "This is my message", config: config }
22
- @email = described_class.email_record(@documents, details, host: 'projectblacklight.org', protocol: 'https')
27
+ subject(:email) do
28
+ described_class.email_record(@documents, details, host: 'projectblacklight.org', protocol: 'https')
29
+ end
30
+
31
+ let(:details) do
32
+ { to: 'test@test.com', message: "This is my message", config: config }
23
33
  end
24
34
 
25
35
  it "receives the TO paramater and send the email to that address" do
26
- expect(@email.to).to include 'test@test.com'
36
+ expect(email.to).to include 'test@test.com'
27
37
  end
28
38
 
29
39
  it "starts the subject w/ Item Record:" do
30
- expect(@email.subject).to match /^Item Record:/
40
+ expect(email.subject).to match /^Item Record:/
31
41
  end
32
42
 
33
43
  it "puts the title of the item in the subject" do
34
- expect(@email.subject).to match /The horn/
44
+ expect(email.subject).to match /The horn/
35
45
  end
36
46
 
37
47
  it "has the correct from address (w/o the port number)" do
38
- expect(@email.from).to include "no-reply@projectblacklight.org"
48
+ expect(email.from).to include "no-reply@projectblacklight.org"
39
49
  end
40
50
 
41
51
  it "prints out the correct body" do
42
- expect(@email.body).to match /Title: The horn/
43
- expect(@email.body).to match /Author: Janetzky, Kurt/
44
- expect(@email.body).to match /projectblacklight.org/
52
+ expect(email.body).to match /Title: The horn/
53
+ expect(email.body).to match /Author: Janetzky, Kurt/
54
+ expect(email.body).to match /projectblacklight.org/
45
55
  end
46
56
 
47
57
  it "uses https URLs when protocol is set" do
@@ -53,28 +63,31 @@ RSpec.describe RecordMailer do
53
63
  context "email title_field is configured and multi valued" do
54
64
  let(:document) { SolrDocument.new(id: "123456", foo: ["Fizz Fizz", "Fuzz Fuzz"], format: ["book"], title_tsim: "The horn", language_ssim: "English", author_tsim: "Janetzky, Kurt") }
55
65
 
56
- it "uses configured email title_field" do
66
+ before do
57
67
  config.email.title_field = "foo"
58
- expect(@email.subject).to match("Fizz Fizz")
59
- expect(@email.subject).not_to match("Fuzz Fuzz")
60
- expect(@email.subject).not_to match("The horn")
68
+ end
69
+
70
+ it "uses configured email title_field" do
71
+ expect(email.subject).to eq 'Item Record: Fizz Fizz and Fuzz Fuzz'
61
72
  end
62
73
  end
63
74
 
64
75
  context "email title_field is configured and single valued" do
65
76
  let(:document) { SolrDocument.new(id: "123456", foo: "Fizz Fizz", format: ["book"], title_tsim: "The horn", language_ssim: "English", author_tsim: "Janetzky, Kurt") }
66
77
 
67
- it "uses configured email title_field" do
78
+ before do
68
79
  config.email.title_field = "foo"
69
- expect(@email.subject).to match("Fizz Fizz")
70
- expect(@email.subject).not_to match("The horn")
80
+ end
81
+
82
+ it "uses configured email title_field" do
83
+ expect(email.subject).to eq 'Item Record: Fizz Fizz'
71
84
  end
72
85
  end
73
86
  end
74
87
 
75
88
  describe "SMS" do
76
89
  before do
77
- details = { to: '5555555555@txt.att.net' }
90
+ details = { to: '5555555555@txt.att.net', config: config }
78
91
  @sms = described_class.sms_record(@documents, details, host: 'projectblacklight.org:3000')
79
92
  end
80
93
 
@@ -91,8 +104,8 @@ RSpec.describe RecordMailer do
91
104
  end
92
105
 
93
106
  it "prints out the correct body" do
94
- expect(@sms.body).to match /The horn/
95
- expect(@sms.body).to match /by Janetzky, Kurt/
107
+ expect(@sms.body).to match /Title: The horn/
108
+ expect(@sms.body).to match /Author: Janetzky, Kurt/
96
109
  expect(@sms.body).to match /projectblacklight.org:3000/
97
110
  end
98
111
 
@@ -12,6 +12,7 @@ RSpec.describe Blacklight::DocumentPresenter do
12
12
 
13
13
  before do
14
14
  allow(request_context).to receive(:search_state).and_return(search_state)
15
+ allow(request_context).to receive(:action_name).and_return(:show)
15
16
  end
16
17
 
17
18
  describe '#fields_to_render' do
@@ -51,13 +51,13 @@ RSpec.describe Blacklight::FieldPresenter, api: true do
51
51
  context 'when an explicit html value is provided' do
52
52
  let(:options) { { value: '<b>val1</b>' } }
53
53
 
54
- it { is_expected.to eq '&lt;b&gt;val1&lt;/b&gt;' }
54
+ it { is_expected.not_to be_html_safe }
55
55
  end
56
56
 
57
57
  context 'when an explicit array value with unsafe characters is provided' do
58
58
  let(:options) { { value: ['<a', 'b'] } }
59
59
 
60
- it { is_expected.to eq '&lt;a and b' }
60
+ it { is_expected.to eq('&lt;a and b').and be_html_safe }
61
61
  end
62
62
 
63
63
  context 'when an explicit array value is provided' do
@@ -22,6 +22,7 @@ RSpec.describe Blacklight::IndexPresenter, api: true do
22
22
 
23
23
  before do
24
24
  allow(request_context).to receive(:search_state).and_return(search_state)
25
+ allow(request_context).to receive(:action_name).and_return(:index)
25
26
  end
26
27
 
27
28
  describe '#fields' do
@@ -19,6 +19,7 @@ RSpec.describe Blacklight::ShowPresenter, api: true do
19
19
 
20
20
  before do
21
21
  allow(request_context).to receive(:search_state).and_return(search_state)
22
+ allow(request_context).to receive(:action_name).and_return(:show)
22
23
  end
23
24
 
24
25
  describe "link_rel_alternates" do
@@ -4,10 +4,10 @@ RSpec.describe Blacklight::Rendering::Pipeline do
4
4
  include Capybara::RSpecMatchers
5
5
  let(:document) { instance_double(SolrDocument) }
6
6
  let(:context) { double }
7
- let(:options) { double('options') }
7
+ let(:options) { {} }
8
8
 
9
9
  describe '.render' do
10
- subject { described_class.render(values, field_config, document, context, options) }
10
+ subject(:rendered) { described_class.render(values, field_config, document, context, options) }
11
11
 
12
12
  let(:values) { %w[a b] }
13
13
  let(:field_config) { Blacklight::Configuration::NullField.new }
@@ -35,6 +35,17 @@ RSpec.describe Blacklight::Rendering::Pipeline do
35
35
  expect(described_class).to have_received(:new)
36
36
  .with(values, field_config, document, context, described_class.operations, options)
37
37
  end
38
+
39
+ context 'outside of an HTML context' do
40
+ let(:options) { { format: 'text' } }
41
+
42
+ let(:values) { ['"blah"', "<notatag>"] }
43
+ let(:field_config) { Blacklight::Configuration::NullField.new itemprop: 'some-prop' }
44
+
45
+ it 'does not HTML escape values or inject HTML tags' do
46
+ expect(rendered).to eq '"blah" and <notatag>'
47
+ end
48
+ end
38
49
  end
39
50
 
40
51
  describe '.operations' do
@@ -24,6 +24,10 @@ RSpec.describe "Routing" do
24
24
  it "maps { :controller => 'catalog', :action => 'show', :id => 666 } to /catalog/666" do
25
25
  expect(get: "/catalog/666").to route_to(controller: 'catalog', action: 'show', id: "666")
26
26
  end
27
+
28
+ it "maps GET {:controller => 'catalog', :action => 'prev_next_documents'} to /catalog/page_links" do
29
+ expect(get: "/catalog/page_links").to route_to(controller: 'catalog', action: 'page_links')
30
+ end
27
31
  end
28
32
 
29
33
  describe "solr_document_path for SolrDocument", test: true do
data/spec/spec_helper.rb CHANGED
@@ -68,7 +68,7 @@ RSpec.configure do |config|
68
68
  config.infer_spec_type_from_file_location!
69
69
  config.include PresenterTestHelpers, type: :presenter
70
70
  config.include ViewComponent::TestHelpers, type: :component
71
- config.include ViewComponentCapybaraTestHelpers, type: :component
71
+ config.include ViewComponentTestHelpers, type: :component
72
72
 
73
73
  config.include(ControllerLevelHelpers, type: :helper)
74
74
  config.before(:each, type: :helper) { initialize_controller_helpers(helper) }
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponentTestHelpers
4
+ # Work around for https://github.com/teamcapybara/capybara/issues/2466
5
+ def render_inline_to_capybara_node(component)
6
+ Capybara::Node::Simple.new(render_inline(component).to_s)
7
+ end
8
+
9
+ # Work-around for https://github.com/ViewComponent/view_component/pull/1661
10
+ # which made the component test's controller method (more) private. This makes
11
+ # it available so we can set up controller-level state for our tests.
12
+ def controller
13
+ # ViewComponent 2.x
14
+ return super if defined?(super)
15
+
16
+ # ViewComponent 3.x
17
+ return vc_test_controller if defined?(vc_test_controller)
18
+
19
+ ApplicationController.new.extend(Rails.application.routes.url_helpers)
20
+ end
21
+ end
@@ -1,2 +1,6 @@
1
1
  gem 'rails-controller-testing'
2
2
  gem 'thor', '~> 0.20' if /^5.[12]/.match?(ENV['RAILS_VERSION'])
3
+
4
+ unless ENV['VIEW_COMPONENT_VERSION'].to_s == ""
5
+ gem 'view_component', ENV.fetch('VIEW_COMPONENT_VERSION')
6
+ end
@@ -34,4 +34,12 @@ class TestAppGenerator < Rails::Generators::Base
34
34
 
35
35
  run "yarn add #{Blacklight::Engine.root}"
36
36
  end
37
+
38
+ def add_component_template_override
39
+ src_template = File.join(Blacklight::Engine.root, 'app', 'components', 'blacklight', 'top_navbar_component.html.erb')
40
+ target_template = File.join('app', 'components', 'blacklight', 'top_navbar_component.html.erb')
41
+ create_file(target_template) do
42
+ File.read(src_template).gsub('role="navigation"', 'role="navigation" data-template-override="top_navbar_component"')
43
+ end
44
+ end
37
45
  end
@@ -19,9 +19,30 @@ RSpec.describe "catalog/_document" do
19
19
  stub_template "catalog/_a_default.html.erb" => "a_partial"
20
20
  stub_template "catalog/_b_default.html.erb" => "b_partial"
21
21
  stub_template "catalog/_c_default.html.erb" => "c_partial"
22
- render partial: "catalog/document", locals: { document: document, document_counter: 1 }
22
+ render partial: "catalog/document", locals: { document: document, document_counter: 1, view_config: blacklight_config.index }
23
23
  expect(rendered).to match /a_partial/
24
24
  expect(rendered).to match /b_partial/
25
25
  expect(rendered).to match /c_partial/
26
26
  end
27
+
28
+ context 'with a configured document component' do
29
+ let(:custom_component_class) do
30
+ Class.new(Blacklight::DocumentComponent) do
31
+ # Override component rendering with our own value
32
+ def call
33
+ 'blah'
34
+ end
35
+ end
36
+ end
37
+
38
+ before do
39
+ stub_const('MyDocumentComponent', custom_component_class)
40
+ blacklight_config.index.document_component = MyDocumentComponent
41
+ end
42
+
43
+ it 'renders the document component' do
44
+ render partial: "catalog/document", locals: { document: document, document_counter: 1, view_config: blacklight_config.index }
45
+ expect(rendered).to match /blah/
46
+ end
47
+ end
27
48
  end
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe "catalog/_document_list", type: :view do
4
+ let(:view_type) { 'some-view' }
5
+ let(:view_config) { double(Blacklight::Configuration::ViewConfig) }
6
+
4
7
  before do
5
- allow(view).to receive_messages(document_index_view_type: "some-view", documents: [], blacklight_config: nil)
8
+ allow(view_config).to receive_messages(key: view_type, document_component: Blacklight::DocumentComponent, partials: [])
9
+ allow(view).to receive_messages(document_index_view_type: view_type, documents: [], blacklight_config: nil)
10
+ assign(:response, instance_double(Blacklight::Solr::Response, start: 0))
6
11
  end
7
12
 
8
13
  it "includes a class for the current view" do
9
- render
14
+ render(partial: "catalog/document_list", locals: { view_config: view_config })
10
15
  expect(rendered).to have_selector(".documents-some-view")
11
16
  end
12
17
  end
@@ -3,10 +3,10 @@
3
3
  RSpec.describe "catalog/_show_tools.html.erb" do
4
4
  let(:document) { SolrDocument.new id: 'xyz', format: 'a' }
5
5
  let(:blacklight_config) { Blacklight::Configuration.new }
6
- let(:component) { instance_double(Blacklight::Document::ActionsComponent) }
6
+ let(:component) { instance_double(Blacklight::Document::ShowToolsComponent) }
7
7
 
8
8
  before do
9
- allow(Blacklight::Document::ActionsComponent).to receive(:new).and_return(component)
9
+ allow(Blacklight::Document::ShowToolsComponent).to receive(:new).and_return(component)
10
10
  allow(view).to receive(:render).with(component)
11
11
  allow(view).to receive(:render).with('catalog/show_tools', { document: document }).and_call_original
12
12
  allow(view).to receive(:blacklight_config).and_return blacklight_config
@@ -93,7 +93,7 @@ RSpec.describe "catalog/index.json", api: true do
93
93
  expect(facets.pluck('id')).to include 'format'
94
94
  expect(format['links']).to include self: 'http://test.host/some/facet/url'
95
95
  expect(format['attributes']['label']).to eq 'Format'
96
- expect(format_item_attributes).to match_array [{ value: 'Book', hits: 30, label: 'Book' }]
96
+ expect(format_item_attributes).to contain_exactly({ value: 'Book', hits: 30, label: 'Book' })
97
97
  end
98
98
  end
99
99
 
@@ -43,7 +43,7 @@ end
43
43
 
44
44
  # rubocop:disable Rails/RakeEnvironment
45
45
  desc "Run test suite"
46
- task :ci do
46
+ task ci: ['build:npm'] do
47
47
  with_solr do
48
48
  Rake::Task['blacklight:internal:seed'].invoke
49
49
  within_test_app do