blacklight 8.0.0.beta3 → 8.0.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +3 -1
  3. data/VERSION +1 -1
  4. data/app/assets/javascripts/blacklight/blacklight.esm.js +5 -5
  5. data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
  6. data/app/assets/javascripts/blacklight/blacklight.js +5 -5
  7. data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
  8. data/app/assets/stylesheets/blacklight/_bootstrap_overrides.scss +1 -1
  9. data/app/components/blacklight/document_component.rb +26 -19
  10. data/app/components/blacklight/document_metadata_component.html.erb +4 -2
  11. data/app/components/blacklight/document_metadata_component.rb +8 -2
  12. data/app/components/blacklight/metadata_field_layout_component.rb +7 -4
  13. data/app/components/blacklight/metadata_field_plain_text_layout_component.rb +17 -0
  14. data/app/components/blacklight/response/sort_component.rb +1 -1
  15. data/app/components/blacklight/response/spellcheck_component.rb +1 -1
  16. data/app/components/blacklight/response/view_type_button_component.rb +1 -1
  17. data/app/components/blacklight/response/view_type_component.rb +1 -1
  18. data/app/components/blacklight/search_context/server_applied_params_component.html.erb +4 -0
  19. data/app/components/blacklight/search_context/server_applied_params_component.rb +13 -0
  20. data/app/components/blacklight/{search_context_component.html.erb → search_context/server_item_pagination_component.html.erb} +0 -0
  21. data/app/components/blacklight/search_context/server_item_pagination_component.rb +71 -0
  22. data/app/components/blacklight/system/dropdown_component.rb +1 -1
  23. data/app/components/blacklight/system/flash_message_component.rb +1 -1
  24. data/app/components/blacklight/system/modal_component.rb +1 -1
  25. data/app/controllers/concerns/blacklight/bookmarks.rb +1 -1
  26. data/app/controllers/concerns/blacklight/search_context.rb +46 -6
  27. data/app/helpers/blacklight/blacklight_helper_behavior.rb +0 -96
  28. data/app/helpers/blacklight/catalog_helper_behavior.rb +27 -54
  29. data/app/helpers/blacklight/component_helper_behavior.rb +0 -11
  30. data/app/helpers/blacklight/document_helper_behavior.rb +76 -0
  31. data/app/helpers/blacklight/layout_helper_behavior.rb +59 -0
  32. data/app/helpers/blacklight/url_helper_behavior.rb +11 -3
  33. data/app/javascript/blacklight/modal.js +5 -5
  34. data/app/models/record_mailer.rb +19 -15
  35. data/app/presenters/blacklight/document_presenter.rb +13 -11
  36. data/app/presenters/blacklight/index_presenter.rb +1 -1
  37. data/app/presenters/blacklight/rendering/abstract_step.rb +4 -0
  38. data/app/presenters/blacklight/rendering/join.rb +7 -1
  39. data/app/presenters/blacklight/rendering/link_to_facet.rb +1 -1
  40. data/app/presenters/blacklight/rendering/microdata.rb +1 -1
  41. data/app/services/blacklight/search_service.rb +2 -1
  42. data/app/views/catalog/_document.atom.builder +1 -1
  43. data/app/views/catalog/_document.html.erb +2 -7
  44. data/app/views/catalog/_document_list.html.erb +2 -1
  45. data/app/views/catalog/_show_main_content.html.erb +3 -9
  46. data/app/views/catalog/index.html.erb +3 -0
  47. data/app/views/catalog/show.html.erb +1 -6
  48. data/app/views/layouts/blacklight/base.html.erb +0 -1
  49. data/app/views/record_mailer/email_record.text.erb +4 -3
  50. data/app/views/record_mailer/sms_record.text.erb +4 -4
  51. data/config/locales/blacklight.ar.yml +0 -6
  52. data/config/locales/blacklight.ca.yml +0 -6
  53. data/config/locales/blacklight.de.yml +0 -6
  54. data/config/locales/blacklight.en.yml +0 -6
  55. data/config/locales/blacklight.es.yml +0 -6
  56. data/config/locales/blacklight.fr.yml +0 -6
  57. data/config/locales/blacklight.hu.yml +0 -6
  58. data/config/locales/blacklight.it.yml +0 -6
  59. data/config/locales/blacklight.nl.yml +0 -6
  60. data/config/locales/blacklight.pt-BR.yml +0 -6
  61. data/config/locales/blacklight.sq.yml +0 -6
  62. data/config/locales/blacklight.zh.yml +0 -6
  63. data/lib/blacklight/configuration/session_tracking_config.rb +45 -0
  64. data/lib/blacklight/configuration.rb +8 -4
  65. data/lib/blacklight/routes/searchable.rb +1 -0
  66. data/lib/generators/blacklight/assets/importmap_generator.rb +0 -6
  67. data/lib/generators/blacklight/templates/solr_document.rb +0 -6
  68. data/package.json +1 -1
  69. data/spec/components/blacklight/document_component_spec.rb +9 -4
  70. data/spec/components/blacklight/search_context/server_applied_params_component_spec.rb +29 -0
  71. data/spec/components/blacklight/{search_context_component_spec.rb → search_context/server_item_pagination_component_spec.rb} +15 -4
  72. data/spec/controllers/bookmarks_controller_spec.rb +1 -1
  73. data/spec/controllers/catalog_controller_spec.rb +17 -5
  74. data/spec/features/component_template_override_spec.rb +8 -0
  75. data/spec/features/modal_spec.rb +12 -0
  76. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +1 -1
  77. data/spec/helpers/blacklight_helper_spec.rb +0 -56
  78. data/spec/helpers/catalog_helper_spec.rb +56 -0
  79. data/spec/lib/blacklight/configuration/session_tracking_config_spec.rb +38 -0
  80. data/spec/models/record_mailer_spec.rb +36 -23
  81. data/spec/presenters/blacklight/document_presenter_spec.rb +1 -0
  82. data/spec/presenters/blacklight/field_presenter_spec.rb +2 -2
  83. data/spec/presenters/blacklight/index_presenter_spec.rb +1 -0
  84. data/spec/presenters/blacklight/show_presenter_spec.rb +1 -0
  85. data/spec/presenters/pipeline_spec.rb +13 -2
  86. data/spec/routing/catalog_routing_spec.rb +4 -0
  87. data/spec/test_app_templates/lib/generators/test_app_generator.rb +8 -0
  88. data/spec/views/catalog/_document.html.erb_spec.rb +1 -1
  89. data/spec/views/catalog/_document_list.html.erb_spec.rb +7 -2
  90. metadata +19 -12
  91. data/app/components/blacklight/search_context_component.rb +0 -68
  92. data/app/models/concerns/blacklight/document/email.rb +0 -27
  93. data/app/models/concerns/blacklight/document/sms.rb +0 -25
  94. data/spec/models/blacklight/document/email_spec.rb +0 -57
  95. data/spec/models/blacklight/document/sms_spec.rb +0 -58
@@ -6,12 +6,6 @@ class <%= model_name.classify %>
6
6
 
7
7
  # self.unique_key = 'id'
8
8
 
9
- # Email uses the semantic field mappings below to generate the body of an email.
10
- SolrDocument.use_extension(Blacklight::Document::Email)
11
-
12
- # SMS uses the semantic field mappings below to generate the body of an SMS email.
13
- SolrDocument.use_extension(Blacklight::Document::Sms)
14
-
15
9
  # DublinCore uses the semantic field mappings below to assemble an OAI-compliant Dublin Core document
16
10
  # Semantic mappings of solr stored fields. Fields may be multi or
17
11
  # single valued. See Blacklight::Document::SemanticFields#field_semantics
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blacklight-frontend",
3
- "version": "8.0.0-beta.3",
3
+ "version": "8.0.0-beta.5",
4
4
  "description": "[![Build Status](https://travis-ci.com/projectblacklight/blacklight.png?branch=main)](https://travis-ci.com/projectblacklight/blacklight) [![Gem Version](https://badge.fury.io/rb/blacklight.png)](http://badge.fury.io/rb/blacklight) [![Coverage Status](https://coveralls.io/repos/github/projectblacklight/blacklight/badge.svg?branch=main)](https://coveralls.io/github/projectblacklight/blacklight?branch=main)",
5
5
  "main": "app/assets/javascripts/blacklight",
6
6
  "scripts": {
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Blacklight::DocumentComponent, type: :component do
6
- subject(:component) { described_class.new(document: document, presenter: view_context.document_presenter(document), **attr) }
6
+ subject(:component) { described_class.new(document: document, **attr) }
7
7
 
8
8
  let(:attr) { {} }
9
9
  let(:view_context) { controller.view_context }
@@ -15,7 +15,9 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
15
15
  Capybara::Node::Simple.new(render)
16
16
  end
17
17
 
18
- let(:document) do
18
+ let(:document) { view_context.document_presenter(presented_document) }
19
+
20
+ let(:presented_document) do
19
21
  SolrDocument.new(
20
22
  id: 'x',
21
23
  thumbnail_path_ss: 'http://example.com/image.jpg',
@@ -26,7 +28,7 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
26
28
 
27
29
  let(:blacklight_config) do
28
30
  CatalogController.blacklight_config.deep_copy.tap do |config|
29
- config.track_search_session = false
31
+ config.track_search_session.storage = false
30
32
  config.index.thumbnail_field = 'thumbnail_path_ss'
31
33
  config.index.document_actions[:bookmark].partial = '/catalog/bookmark_control'
32
34
  end
@@ -92,9 +94,12 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
92
94
  end
93
95
 
94
96
  context 'with a document rendered as part of a collection' do
95
- let(:attr) { { document_counter: 10, counter_offset: 100 } }
97
+ # ViewComponent 3 changes iteration counters to begin at 0 rather than 1
98
+ let(:document_counter) { ViewComponent::VERSION::MAJOR < 3 ? 11 : 10 }
99
+ let(:attr) { { document_counter: document_counter, counter_offset: 100 } }
96
100
 
97
101
  it 'renders a counter with the title' do
102
+ # after ViewComponent 2.5, collection counter params are 1-indexed
98
103
  expect(rendered).to have_selector 'header', text: '111. Title'
99
104
  end
100
105
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Blacklight::SearchContext::ServerAppliedParamsComponent, type: :component do
6
+ subject(:render) { instance.render_in(view_context) }
7
+
8
+ let(:instance) { described_class.new }
9
+ let(:current_search_session) { nil }
10
+ let(:view_context) { controller.view_context }
11
+
12
+ before do
13
+ view_context.view_paths.unshift(RSpec::Rails::ViewExampleGroup::StubResolverCache.resolver_for('application/_start_over.html.erb' => 'start over'))
14
+ allow(view_context).to receive(:current_search_session).and_return current_search_session
15
+ allow(view_context).to receive(:link_back_to_catalog).with(any_args)
16
+ end
17
+
18
+ it 'is blank without current session' do
19
+ expect(render).to be_blank
20
+ end
21
+
22
+ context 'with current session' do
23
+ let(:current_search_session) { double(query_params: { q: 'abc' }) }
24
+
25
+ it 'is not blank' do
26
+ expect(render).not_to be_blank
27
+ end
28
+ end
29
+ end
@@ -2,14 +2,17 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Blacklight::SearchContextComponent, type: :component do
5
+ RSpec.describe Blacklight::SearchContext::ServerItemPaginationComponent, type: :component do
6
6
  subject(:render) { render_inline(instance) }
7
7
 
8
- let(:search_session) { {} }
9
- let(:instance) { described_class.new(search_context: search_context, search_session: search_session) }
8
+ let(:current_document_id) { 9 }
9
+ let(:current_document) { SolrDocument.new(id: current_document_id) }
10
+ let(:search_session) { { 'document_id' => current_document_id } }
11
+ let(:instance) { described_class.new(search_context: search_context, search_session: search_session, current_document: current_document) }
10
12
 
11
13
  before do
12
- allow(controller).to receive(:current_search_session).and_return(double(id: 9))
14
+ allow(controller).to receive(:current_search_session).and_return(double(id: current_document_id))
15
+ controller.class.helper_method :current_search_session
13
16
  end
14
17
 
15
18
  context 'when there is no next or previous' do
@@ -36,5 +39,13 @@ RSpec.describe Blacklight::SearchContextComponent, type: :component do
36
39
  it "renders content" do
37
40
  expect(render.css('.pagination-search-widgets').to_html).not_to be_blank
38
41
  end
42
+
43
+ context "session and document are out of sync" do
44
+ let(:current_document) { SolrDocument.new(id: current_document_id + 1) }
45
+
46
+ it "does not render content" do
47
+ expect(render.to_html).to be_blank
48
+ end
49
+ end
39
50
  end
40
51
  end
@@ -7,7 +7,7 @@ RSpec.describe BookmarksController do
7
7
  end
8
8
 
9
9
  it 'opts out of search session tracking' do
10
- expect(@controller.blacklight_config.track_search_session).to be false
10
+ expect(@controller.blacklight_config.track_search_session.storage).to be false
11
11
  end
12
12
  end
13
13
 
@@ -468,17 +468,14 @@ RSpec.describe CatalogController, api: true do
468
468
  end
469
469
 
470
470
  describe "email/sms" do
471
+ let(:mock_document) { SolrDocument.new }
472
+
471
473
  before do
472
- mock_document.extend(Blacklight::Document::Sms)
473
- mock_document.extend(Blacklight::Document::Email)
474
- allow(mock_document).to receive(:to_semantic_values).and_return({})
475
474
  allow(mock_document).to receive(:to_model).and_return(SolrDocument.new(id: 'my_fake_doc'))
476
475
 
477
476
  allow(controller).to receive(:search_service).and_return(search_service)
478
477
  expect(search_service).to receive(:fetch).and_return([mock_document])
479
478
  request.env["HTTP_REFERER"] = "/catalog/#{doc_id}"
480
- SolrDocument.use_extension(Blacklight::Document::Email)
481
- SolrDocument.use_extension(Blacklight::Document::Sms)
482
479
  end
483
480
 
484
481
  describe "email", api: false do
@@ -797,6 +794,21 @@ RSpec.describe CatalogController, api: true do
797
794
  expect(controller.send(:search_facet_path, id: "some_facet", page: 5)).to eq facet_catalog_path(id: "some_facet")
798
795
  end
799
796
  end
797
+
798
+ describe "page_links" do
799
+ it "has prev/next docs and result set data for non-empty result sets", integration: true do
800
+ get :page_links, params: { f: { "format" => 'Book' }, counter: 2 }
801
+ expect(assigns(:page_link_data)).not_to be_empty
802
+ expect(assigns(:page_link_data).fetch(:prev, nil)).to end_with('counter=1')
803
+ expect(assigns(:page_link_data).fetch(:next, nil)).to end_with('counter=3')
804
+ expect(assigns(:page_link_data).fetch(:totalRaw, nil)).to be 30
805
+ end
806
+
807
+ it "is empty for empty result sets", integration: true do
808
+ get :page_links, params: { f: { "format" => 'empty-result-set' }, counter: 1 }
809
+ expect(assigns(:page_link_data)).to be_empty
810
+ end
811
+ end
800
812
  end
801
813
 
802
814
  # there must be at least one facet, and each facet must have at least one value
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'Generated test application template at default path' do
4
+ it 'unobtrusively overrides default top navbar component template' do
5
+ visit root_path
6
+ expect(page).to have_css 'nav[data-template-override="top_navbar_component"]'
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe 'Modal' do
4
+ it 'can open and dismiss the email modal', js: true do
5
+ visit solr_document_path('2007020969')
6
+ expect(page).to have_no_selector 'dialog#blacklight-modal'
7
+ click_link 'Email'
8
+ expect(page).to have_selector 'dialog#blacklight-modal'
9
+ click_button '×'
10
+ expect(page).to have_no_selector 'dialog#blacklight-modal'
11
+ end
12
+ end
@@ -187,7 +187,7 @@ RSpec.describe Blacklight::UrlHelperBehavior do
187
187
  end
188
188
 
189
189
  it "uses the track_search_session configuration to determine whether to track the search session" do
190
- blacklight_config.track_search_session = false
190
+ blacklight_config.track_search_session.storage = false
191
191
  expect(helper.session_tracking_path(document, x: 1)).to be_nil
192
192
  end
193
193
  end
@@ -134,18 +134,6 @@ RSpec.describe BlacklightHelper do
134
134
  end
135
135
  end
136
136
 
137
- describe "render_grouped_response?" do
138
- it "checks if the response ivar contains grouped data" do
139
- assign(:response, instance_double(Blacklight::Solr::Response, grouped?: true))
140
- expect(helper.render_grouped_response?).to be true
141
- end
142
-
143
- it "checks if the response param contains grouped data" do
144
- response = instance_double(Blacklight::Solr::Response, grouped?: true)
145
- expect(helper.render_grouped_response?(response)).to be true
146
- end
147
- end
148
-
149
137
  describe "#opensearch_description_tag" do
150
138
  subject { helper.opensearch_description_tag 'title', 'href' }
151
139
 
@@ -210,48 +198,4 @@ RSpec.describe BlacklightHelper do
210
198
  end
211
199
  end
212
200
  end
213
-
214
- describe "#document_index_view_type" do
215
- it "defaults to the default view" do
216
- allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2)
217
- allow(helper).to receive(:default_document_index_view_type).and_return(:xyz)
218
- expect(helper.document_index_view_type).to eq :xyz
219
- end
220
-
221
- it "uses the query parameter" do
222
- allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2)
223
- expect(helper.document_index_view_type(view: :a)).to eq :a
224
- end
225
-
226
- it "uses the default view if the requested view is not available" do
227
- allow(helper).to receive(:default_document_index_view_type).and_return(:xyz)
228
- allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2)
229
- expect(helper.document_index_view_type(view: :c)).to eq :xyz
230
- end
231
-
232
- context "when they have a preferred view" do
233
- before do
234
- session[:preferred_view] = :b
235
- end
236
-
237
- context "and no view is specified" do
238
- it "uses the saved preference" do
239
- allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2, c: 3)
240
- expect(helper.document_index_view_type).to eq :b
241
- end
242
-
243
- it "uses the default view if the preference is not available" do
244
- allow(helper).to receive(:document_index_views).and_return(a: 1)
245
- expect(helper.document_index_view_type).to eq :a
246
- end
247
- end
248
-
249
- context "and a view is specified" do
250
- it "uses the query parameter" do
251
- allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2, c: 3)
252
- expect(helper.document_index_view_type(view: :c)).to eq :c
253
- end
254
- end
255
- end
256
- end
257
201
  end
@@ -284,4 +284,60 @@ RSpec.describe CatalogHelper do
284
284
  it { is_expected.to eq "foobar / Format: Book" }
285
285
  end
286
286
  end
287
+
288
+ describe "render_grouped_response?" do
289
+ it "checks if the response ivar contains grouped data" do
290
+ assign(:response, instance_double(Blacklight::Solr::Response, grouped?: true))
291
+ expect(helper.render_grouped_response?).to be true
292
+ end
293
+
294
+ it "checks if the response param contains grouped data" do
295
+ response = instance_double(Blacklight::Solr::Response, grouped?: true)
296
+ expect(helper.render_grouped_response?(response)).to be true
297
+ end
298
+ end
299
+
300
+ describe "#document_index_view_type" do
301
+ it "defaults to the default view" do
302
+ allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2)
303
+ allow(helper).to receive(:default_document_index_view_type).and_return(:xyz)
304
+ expect(helper.document_index_view_type).to eq :xyz
305
+ end
306
+
307
+ it "uses the query parameter" do
308
+ allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2)
309
+ expect(helper.document_index_view_type(view: :a)).to eq :a
310
+ end
311
+
312
+ it "uses the default view if the requested view is not available" do
313
+ allow(helper).to receive(:default_document_index_view_type).and_return(:xyz)
314
+ allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2)
315
+ expect(helper.document_index_view_type(view: :c)).to eq :xyz
316
+ end
317
+
318
+ context "when they have a preferred view" do
319
+ before do
320
+ session[:preferred_view] = :b
321
+ end
322
+
323
+ context "and no view is specified" do
324
+ it "uses the saved preference" do
325
+ allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2, c: 3)
326
+ expect(helper.document_index_view_type).to eq :b
327
+ end
328
+
329
+ it "uses the default view if the preference is not available" do
330
+ allow(helper).to receive(:document_index_views).and_return(a: 1)
331
+ expect(helper.document_index_view_type).to eq :a
332
+ end
333
+ end
334
+
335
+ context "and a view is specified" do
336
+ it "uses the query parameter" do
337
+ allow(helper).to receive(:document_index_views).and_return(a: 1, b: 2, c: 3)
338
+ expect(helper.document_index_view_type(view: :c)).to eq :c
339
+ end
340
+ end
341
+ end
342
+ end
287
343
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Blacklight::Configuration::SessionTrackingConfig do
4
+ subject(:config) { described_class.new }
5
+
6
+ it "defaults @storage to 'server'" do
7
+ expect(config.storage).to eq 'server'
8
+ end
9
+
10
+ context "@storage is set to 'server'" do
11
+ before do
12
+ config.storage = 'server'
13
+ end
14
+
15
+ it "defaults components values" do
16
+ expect(config.applied_params_component).to eq Blacklight::SearchContext::ServerAppliedParamsComponent
17
+ expect(config.item_pagination_component).to eq Blacklight::SearchContext::ServerItemPaginationComponent
18
+ end
19
+
20
+ it "defaults tracking url helper" do
21
+ expect(config.url_helper).to be_nil
22
+ end
23
+ end
24
+
25
+ context "@storage is set to false" do
26
+ before do
27
+ config.storage = false
28
+ end
29
+
30
+ it "defaults components values" do
31
+ expect(config.applied_params_component).to be_nil
32
+ end
33
+
34
+ it "defaults tracking url helper" do
35
+ expect(config.url_helper).to be_nil
36
+ end
37
+ end
38
+ 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
@@ -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,7 +19,7 @@ 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/
@@ -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