blacklight 9.2.1 → 9.3.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 (133) hide show
  1. checksums.yaml +4 -4
  2. data/.github/matrix.json +4 -4
  3. data/.github/workflows/build.yml +3 -0
  4. data/.github/workflows/lint.yml +17 -2
  5. data/.github/workflows/main.yml +3 -0
  6. data/.github/workflows/release_7_x_scheduled.yml +3 -0
  7. data/.github/workflows/release_8_x_scheduled.yml +3 -0
  8. data/.github/workflows/test.yml +3 -2
  9. data/.gitignore +0 -1
  10. data/.prettierignore +5 -0
  11. data/.prettierrc.json +4 -0
  12. data/.rubocop.yml +4 -0
  13. data/.rubocop_todo.yml +0 -143
  14. data/VERSION +1 -1
  15. data/app/assets/builds/blacklight.css +39 -9
  16. data/app/assets/javascripts/blacklight/blacklight.esm.js +207 -125
  17. data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
  18. data/app/assets/javascripts/blacklight/blacklight.js +207 -125
  19. data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
  20. data/app/assets/stylesheets/blacklight/_search_results.scss +24 -0
  21. data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +18 -3
  22. data/app/components/blacklight/constraints_component.rb +2 -1
  23. data/app/components/blacklight/facet_field_component.rb +1 -1
  24. data/app/components/blacklight/open_graph_metadata_component.rb +33 -0
  25. data/app/components/blacklight/search/sidebar_component.html.erb +2 -2
  26. data/app/components/blacklight/search/sidebar_component.rb +3 -2
  27. data/app/controllers/concerns/blacklight/catalog.rb +3 -5
  28. data/app/controllers/concerns/blacklight/controller.rb +2 -6
  29. data/app/controllers/concerns/blacklight/search_context.rb +2 -7
  30. data/app/controllers/concerns/blacklight/token_based_user.rb +2 -6
  31. data/app/helpers/blacklight/catalog_helper_behavior.rb +9 -9
  32. data/app/helpers/blacklight/url_helper_behavior.rb +2 -7
  33. data/app/javascript/blacklight-frontend/bookmark_toggle.js +10 -8
  34. data/app/javascript/blacklight-frontend/checkbox_submit.js +42 -33
  35. data/app/javascript/blacklight-frontend/color_theme_switcher.js +47 -16
  36. data/app/javascript/blacklight-frontend/core.js +18 -19
  37. data/app/javascript/blacklight-frontend/debounce.js +7 -5
  38. data/app/javascript/blacklight-frontend/facet_suggest.js +27 -25
  39. data/app/javascript/blacklight-frontend/index.js +1 -1
  40. data/app/javascript/blacklight-frontend/modal.js +69 -52
  41. data/app/javascript/blacklight-frontend/search_context.js +36 -17
  42. data/app/models/blacklight/facet_paginator.rb +1 -3
  43. data/app/presenters/blacklight/document_presenter.rb +10 -1
  44. data/app/presenters/blacklight/facet_grouped_item_presenter.rb +1 -3
  45. data/app/presenters/blacklight/facet_item_pivot_presenter.rb +0 -8
  46. data/app/presenters/blacklight/json_presenter.rb +1 -3
  47. data/app/presenters/blacklight/open_graph_presenter.rb +34 -0
  48. data/app/presenters/blacklight/thumbnail_presenter.rb +24 -1
  49. data/app/services/blacklight/field_retriever.rb +1 -3
  50. data/app/services/blacklight/search_service.rb +1 -1
  51. data/app/views/catalog/_document.atom.builder +3 -5
  52. data/app/views/catalog/_show_main_content.html.erb +1 -0
  53. data/app/views/catalog/index.atom.builder +8 -4
  54. data/app/views/layouts/blacklight/base.html.erb +7 -1
  55. data/config/i18n-tasks.yml +1 -1
  56. data/config/locales/blacklight.ja.yml +256 -0
  57. data/lib/blacklight/configuration/context.rb +1 -1
  58. data/lib/blacklight/configuration/fields.rb +3 -9
  59. data/lib/blacklight/configuration/view_config.rb +16 -0
  60. data/lib/blacklight/configuration.rb +6 -2
  61. data/lib/blacklight/engine.rb +2 -4
  62. data/lib/blacklight/search_builder.rb +4 -4
  63. data/lib/blacklight/search_state/filter_field.rb +0 -1
  64. data/lib/blacklight/search_state.rb +2 -6
  65. data/lib/blacklight/solr/facet_paginator.rb +1 -1
  66. data/lib/blacklight/solr/repository.rb +1 -3
  67. data/lib/blacklight/solr/response/facets.rb +11 -9
  68. data/lib/blacklight/solr/response/spelling.rb +51 -47
  69. data/lib/blacklight/solr/search_builder_behavior.rb +14 -15
  70. data/lib/blacklight.rb +3 -9
  71. data/lib/generators/blacklight/assets/importmap_generator.rb +3 -3
  72. data/lib/generators/blacklight/assets_generator.rb +1 -1
  73. data/lib/railties/blacklight.rake +3 -5
  74. data/package-lock.json +1054 -0
  75. data/package.json +7 -4
  76. data/rollup.config.js +5 -7
  77. data/spec/components/blacklight/constraints_component_spec.rb +23 -1
  78. data/spec/components/blacklight/document/page_header_component_spec.rb +4 -4
  79. data/spec/components/blacklight/document_component_spec.rb +16 -3
  80. data/spec/components/blacklight/metadata_field_component_spec.rb +2 -2
  81. data/spec/components/blacklight/response/spellcheck_component_spec.rb +2 -2
  82. data/spec/components/blacklight/search_bar_component_spec.rb +1 -1
  83. data/spec/components/blacklight/search_context/server_item_pagination_component_spec.rb +1 -1
  84. data/spec/components/blacklight/system/dropdown_component_spec.rb +1 -2
  85. data/spec/controllers/bookmarks_controller_spec.rb +3 -9
  86. data/spec/controllers/catalog_controller_spec.rb +56 -26
  87. data/spec/features/dark_mode_spec.rb +30 -0
  88. data/spec/features/did_you_mean_spec.rb +1 -1
  89. data/spec/features/facet_missing_spec.rb +3 -3
  90. data/spec/features/modal_spec.rb +2 -2
  91. data/spec/features/open_graph_spec.rb +43 -0
  92. data/spec/features/search_context_spec.rb +1 -1
  93. data/spec/fixtures/sample_solr_documents.yml +6 -0
  94. data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +11 -8
  95. data/spec/helpers/blacklight/render_partials_helper_behavior_spec.rb +1 -1
  96. data/spec/helpers/blacklight/url_helper_behavior_spec.rb +5 -5
  97. data/spec/helpers/blacklight_helper_spec.rb +6 -4
  98. data/spec/helpers/catalog_helper_spec.rb +34 -8
  99. data/spec/lib/blacklight/configuration/session_tracking_config_spec.rb +2 -2
  100. data/spec/lib/blacklight/nested_open_struct_with_hash_access_spec.rb +2 -2
  101. data/spec/lib/blacklight/search_state/filter_field_spec.rb +1 -1
  102. data/spec/lib/blacklight/search_state/pivot_filter_field_spec.rb +1 -1
  103. data/spec/lib/blacklight/search_state_spec.rb +14 -19
  104. data/spec/lib/blacklight_spec.rb +5 -5
  105. data/spec/models/blacklight/configuration_spec.rb +1 -1
  106. data/spec/models/blacklight/document/cache_key_spec.rb +32 -12
  107. data/spec/models/blacklight/facet_paginator_spec.rb +5 -5
  108. data/spec/models/blacklight/icon_spec.rb +3 -3
  109. data/spec/models/blacklight/search_builder_spec.rb +21 -16
  110. data/spec/models/blacklight/solr/default_filter_query_builder_spec.rb +1 -1
  111. data/spec/models/blacklight/solr/document_spec.rb +8 -8
  112. data/spec/models/blacklight/solr/response/facets_spec.rb +5 -5
  113. data/spec/models/blacklight/solr/response/group_response_spec.rb +1 -1
  114. data/spec/models/blacklight/solr/response/group_spec.rb +1 -1
  115. data/spec/models/blacklight/solr/response_spec.rb +18 -3
  116. data/spec/models/blacklight/solr/search_builder_behavior_spec.rb +46 -7
  117. data/spec/models/blacklight/suggest_search_spec.rb +1 -1
  118. data/spec/models/record_mailer_spec.rb +2 -2
  119. data/spec/models/search_spec.rb +7 -7
  120. data/spec/presenters/blacklight/document_presenter_spec.rb +19 -6
  121. data/spec/presenters/blacklight/facet_field_presenter_spec.rb +4 -4
  122. data/spec/presenters/blacklight/field_presenter_spec.rb +12 -9
  123. data/spec/presenters/blacklight/open_graph_presenter_spec.rb +56 -0
  124. data/spec/presenters/blacklight/rendering/pipeline_spec.rb +3 -3
  125. data/spec/presenters/blacklight/thumbnail_presenter_spec.rb +129 -13
  126. data/spec/routing/catalog_routing_spec.rb +1 -1
  127. data/spec/services/blacklight/field_retriever_spec.rb +1 -1
  128. data/spec/services/blacklight/search_service_spec.rb +8 -8
  129. data/spec/test_app_templates/lib/generators/test_app_generator.rb +1 -3
  130. data/spec/views/catalog/_document_list.html.erb_spec.rb +1 -2
  131. data/spec/views/catalog/index.atom.builder_spec.rb +16 -20
  132. data/spec/views/shared/_user_util_links.html.erb_spec.rb +1 -1
  133. metadata +12 -2
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blacklight-frontend",
3
- "version": "9.2.1",
3
+ "version": "9.3.0",
4
4
  "description": "The frontend code and styles for Blacklight",
5
5
  "exports": {
6
6
  "./blacklight.esm.js": "./app/assets/javascripts/blacklight/blacklight.esm.js",
@@ -14,7 +14,9 @@
14
14
  "type": "module",
15
15
  "scripts": {
16
16
  "build": "sass ./app/assets/stylesheets/blacklight/build.scss:./app/assets/builds/blacklight.css --no-source-map --load-path=node_modules --quiet-deps",
17
- "prepare": "rollup --config rollup.config.js --sourcemap && ESM=true rollup --config rollup.config.js --sourcemap"
17
+ "prepare": "rollup --config rollup.config.js --sourcemap && ESM=true rollup --config rollup.config.js --sourcemap",
18
+ "format": "prettier --write \"app/javascript/**/*.js\" \"app/assets/config/**/*.js\" rollup.config.js",
19
+ "format:check": "prettier --check \"app/javascript/**/*.js\" \"app/assets/config/**/*.js\" rollup.config.js"
18
20
  },
19
21
  "repository": {
20
22
  "type": "git",
@@ -31,10 +33,11 @@
31
33
  },
32
34
  "homepage": "https://github.com/projectblacklight/blacklight#readme",
33
35
  "devDependencies": {
36
+ "bootstrap": "^5.3.9",
37
+ "prettier": "3.10.1",
34
38
  "rollup": "^4.24.0",
35
39
  "rollup-plugin-includepaths": "^0.2.4",
36
- "sass": "^1.80.3",
37
- "bootstrap": "^5.3.8"
40
+ "sass": "^1.80.3"
38
41
  },
39
42
  "browserslist": [
40
43
  "defaults",
data/rollup.config.js CHANGED
@@ -1,7 +1,5 @@
1
- import includePaths from 'rollup-plugin-includepaths';
1
+ import includePaths from 'rollup-plugin-includepaths'
2
2
 
3
-
4
- const BUNDLE = process.env.BUNDLE === 'true'
5
3
  const ESM = process.env.ESM === 'true'
6
4
 
7
5
  const fileDest = `blacklight${ESM ? '.esm' : ''}`
@@ -12,8 +10,8 @@ let includePathOptions = {
12
10
  include: {},
13
11
  paths: ['app/javascript'],
14
12
  external: [],
15
- extensions: ['.js']
16
- };
13
+ extensions: ['.js'],
14
+ }
17
15
 
18
16
  const rollupConfig = {
19
17
  input: 'app/javascript/blacklight-frontend/index.js',
@@ -22,10 +20,10 @@ const rollupConfig = {
22
20
  format: ESM ? 'es' : 'umd',
23
21
  globals,
24
22
  generatedCode: { preset: 'es2015' },
25
- name: ESM ? undefined : 'Blacklight'
23
+ name: ESM ? undefined : 'Blacklight',
26
24
  },
27
25
  external,
28
- plugins: [includePaths(includePathOptions)]
26
+ plugins: [includePaths(includePathOptions)],
29
27
  }
30
28
 
31
29
  export default rollupConfig
@@ -55,7 +55,7 @@ RSpec.describe Blacklight::ConstraintsComponent, type: :component do
55
55
  expect(page).to have_css('.constraint-value > .filter-name', text: 'Some Facet').and(have_css('.constraint-value > .filter-value', text: 'some value'))
56
56
  end
57
57
 
58
- context 'that is not configured' do
58
+ context 'when a facet is not configured' do
59
59
  let(:query_params) { { f: { some_facet: ['some value'], missing: ['another value'] } } }
60
60
 
61
61
  it 'renders only the configured constraints' do
@@ -65,6 +65,28 @@ RSpec.describe Blacklight::ConstraintsComponent, type: :component do
65
65
  end
66
66
  end
67
67
 
68
+ context 'with a search clause' do
69
+ let(:blacklight_config) do
70
+ Blacklight::Configuration.new.configure do |config|
71
+ config.add_search_field 'title'
72
+ end
73
+ end
74
+ let(:query_params) { { clause: { '0' => { field: 'title', query: 'dogs' } } } }
75
+
76
+ it 'renders the clause' do
77
+ expect(page).to have_css('.constraint-value > .filter-name', text: 'Title').and(have_css('.constraint-value > .filter-value', text: 'dogs'))
78
+ end
79
+
80
+ context 'when the search field is not configured' do
81
+ let(:query_params) { { clause: { '0' => { field: 'title', query: 'dogs' }, '1' => { field: 'not_a_real_field', query: 'cats' } } } }
82
+
83
+ it 'renders only the clauses for configured search fields' do
84
+ expect(page).to have_css('.constraint-value > .filter-value', text: 'dogs')
85
+ expect(page).to have_no_css('.constraint-value > .filter-value', text: 'cats')
86
+ end
87
+ end
88
+ end
89
+
68
90
  describe '.for_search_history' do
69
91
  subject(:component) { described_class.for_search_history(**params) }
70
92
 
@@ -34,7 +34,7 @@ RSpec.describe Blacklight::Document::PageHeaderComponent, type: :component do
34
34
  end
35
35
  # rubocop:enable RSpec/SubjectStub
36
36
 
37
- context "all variables are empty" do
37
+ context "when all variables are empty" do
38
38
  let(:search_context) { nil }
39
39
  let(:current_search_session) { {} }
40
40
 
@@ -48,7 +48,7 @@ RSpec.describe Blacklight::Document::PageHeaderComponent, type: :component do
48
48
  end
49
49
  end
50
50
 
51
- context 'has header tools' do
51
+ context 'with header tools' do
52
52
  before do
53
53
  blacklight_config.show.show_header_tools_component = show_header_tools_component
54
54
  render_inline component
@@ -61,7 +61,7 @@ RSpec.describe Blacklight::Document::PageHeaderComponent, type: :component do
61
61
  end
62
62
  end
63
63
 
64
- context "has pagination" do
64
+ context "with pagination" do
65
65
  let(:search_context) { { next: next_doc, prev: prev_doc } }
66
66
  let(:prev_doc) { SolrDocument.new(id: '777') }
67
67
  let(:next_doc) { SolrDocument.new(id: '888') }
@@ -80,7 +80,7 @@ RSpec.describe Blacklight::Document::PageHeaderComponent, type: :component do
80
80
  end
81
81
  end
82
82
 
83
- context 'has header tools' do
83
+ context 'with header tools' do
84
84
  before do
85
85
  blacklight_config.show.show_header_tools_component = show_header_tools_component
86
86
  render_inline component
@@ -67,7 +67,7 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
67
67
  end
68
68
  end
69
69
 
70
- context 'index view' do
70
+ context 'with the index view' do
71
71
  before do
72
72
  vc_test_controller.action_name = "index"
73
73
  end
@@ -117,6 +117,19 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
117
117
  expect(page).to have_css 'a[href="/catalog/x"] img[src="http://example.com/image.jpg"]'
118
118
  end
119
119
 
120
+ context 'with a default thumbnail' do
121
+ before do
122
+ blacklight_config.index.default_thumbnail = 'http://example.com/default.png'
123
+ end
124
+
125
+ it 'renders the default thumbnail beneath the thumbnail, inside the link' do
126
+ render_inline component
127
+
128
+ expect(page).to have_css 'a[href="/catalog/x"] .thumbnail-stack .thumbnail-fallback img[src="http://example.com/default.png"]'
129
+ expect(page).to have_css 'a[href="/catalog/x"] .thumbnail-stack > img[src="http://example.com/image.jpg"]'
130
+ end
131
+ end
132
+
120
133
  context 'with default metadata component' do
121
134
  it 'renders metadata' do
122
135
  render_inline component
@@ -129,7 +142,7 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
129
142
  end
130
143
  end
131
144
 
132
- context 'show view' do
145
+ context 'with the show view' do
133
146
  let(:attr) { { title_component: :h1, show: true } }
134
147
 
135
148
  before do
@@ -171,7 +184,7 @@ RSpec.describe Blacklight::DocumentComponent, type: :component do
171
184
  end
172
185
  end
173
186
 
174
- context 'show view with custom translation' do
187
+ context 'with the show view and a custom translation' do
175
188
  let!(:original_translations) { I18n.backend.send(:translations).deep_dup }
176
189
 
177
190
  before do
@@ -19,7 +19,7 @@ RSpec.describe Blacklight::MetadataFieldComponent, type: :component do
19
19
  Blacklight::FieldPresenter.new(view_context, document, field_config)
20
20
  end
21
21
 
22
- context "from index view" do
22
+ context "with the index view" do
23
23
  before do
24
24
  render_inline(described_class.new(field: field))
25
25
  end
@@ -48,7 +48,7 @@ RSpec.describe Blacklight::MetadataFieldComponent, type: :component do
48
48
  end
49
49
  end
50
50
 
51
- context 'from a show view' do
51
+ context 'with a show view' do
52
52
  before do
53
53
  allow(field).to receive(:label).with('show').and_return('custom label')
54
54
 
@@ -33,7 +33,7 @@ RSpec.describe Blacklight::Response::SpellcheckComponent, type: :component do
33
33
  expect(render.to_html).to include(word_suggestion)
34
34
  end
35
35
 
36
- context 'and explicit spellcheck options' do
36
+ context 'with explicit spellcheck options' do
37
37
  let(:explicit_option) { 'explicit option' }
38
38
  let(:spellcheck_options) { [explicit_option] }
39
39
 
@@ -43,7 +43,7 @@ RSpec.describe Blacklight::Response::SpellcheckComponent, type: :component do
43
43
  end
44
44
  end
45
45
 
46
- context 'and collations are present' do
46
+ context 'when collations are present' do
47
47
  let(:word_suggestion) { 'donotuse' }
48
48
  let(:collated_suggestion) { 'yoshida Hajime' }
49
49
  let(:response) { instance_double(Blacklight::Solr::Response, total: 4, spelling: double(words: [word_suggestion], collation: collated_suggestion)) }
@@ -105,7 +105,7 @@ RSpec.describe Blacklight::SearchBarComponent, type: :component do
105
105
  end
106
106
  end
107
107
 
108
- context 'advanced search link' do
108
+ describe 'advanced search link' do
109
109
  subject(:render) { render_inline(instance) }
110
110
 
111
111
  context 'when enabled (default)' do
@@ -47,7 +47,7 @@ RSpec.describe Blacklight::SearchContext::ServerItemPaginationComponent, type: :
47
47
  expect(render.css('.search-context.page-links').to_html).not_to be_blank
48
48
  end
49
49
 
50
- context "session and document are out of sync" do
50
+ context "when session and document are out of sync" do
51
51
  let(:current_document) { SolrDocument.new(id: current_document_id + 1) }
52
52
 
53
53
  it "does not render content" do
@@ -4,8 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe Blacklight::System::DropdownComponent, type: :component do
6
6
  it 'includes a link for each choice' do
7
- search_state = double(Blacklight::SearchState)
8
- allow(search_state).to receive(:params_for_search).and_return('http://example.com')
7
+ search_state = instance_double(Blacklight::SearchState, params_for_search: "http://example.com")
9
8
  rendered = render_inline(described_class.new(
10
9
  param: :per_page,
11
10
  choices: [
@@ -26,11 +26,7 @@ RSpec.describe BookmarksController do
26
26
  end
27
27
 
28
28
  it "has a 500 status code when create is not success" do
29
- allow(@controller).to receive_message_chain(:current_or_guest_user, :existing_bookmark_for).and_return(false)
30
- allow(@controller).to receive_message_chain(:current_or_guest_user, :persisted?).and_return(true)
31
- allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :where, :exists?).and_return(false)
32
- allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :create!).and_raise(ActiveRecord::RecordInvalid)
33
- allow(@controller).to receive_message_chain(:current_or_guest_user, :errors, :full_messages).and_return([1])
29
+ allow(user.bookmarks).to receive(:create!).and_raise(ActiveRecord::RecordInvalid)
34
30
  put :update, xhr: true, params: { id: 'iamabooboo', format: :js }
35
31
  expect(response).to have_http_status :internal_server_error
36
32
  end
@@ -92,9 +88,7 @@ RSpec.describe BookmarksController do
92
88
  end
93
89
 
94
90
  it "has a 500 status code when delete is not success" do
95
- bm = instance_double(Bookmark)
96
- allow(@controller).to receive_message_chain(:current_or_guest_user, :existing_bookmark_for).and_return(bm)
97
- allow(@controller).to receive_message_chain(:current_or_guest_user, :bookmarks, :find_by).and_return(instance_double(Bookmark, delete: nil, destroyed?: false))
91
+ allow(user.bookmarks).to receive(:find_by).and_return(instance_double(Bookmark, delete: nil, destroyed?: false))
98
92
 
99
93
  delete :destroy, xhr: true, params: { id: 'pleasekillme', format: :js }
100
94
 
@@ -116,7 +110,7 @@ RSpec.describe BookmarksController do
116
110
  expect(controller.send(:token_user).id).to eq user.id
117
111
  end
118
112
 
119
- context 'created over an hour ago' do
113
+ context 'when created over an hour ago' do
120
114
  let(:current_time) { 2.hours.ago }
121
115
 
122
116
  it 'is expired' do
@@ -126,11 +126,24 @@ RSpec.describe CatalogController, :api do
126
126
  end
127
127
  end
128
128
 
129
+ describe "with a feed format that has been removed from the view configuration" do
130
+ let(:config) { Blacklight::Configuration.new.tap { |c| c.view.clear } }
131
+
132
+ before do
133
+ allow(controller).to receive_messages(blacklight_config: config, retrieve_search_results: instance_double(Blacklight::Solr::Response, export_formats: []))
134
+ end
135
+
136
+ %w[rss atom].each do |feed_format|
137
+ it "does not serve #{feed_format}" do
138
+ expect { get :index, params: { format: feed_format } }.to raise_error(ActionController::UnknownFormat)
139
+ end
140
+ end
141
+ end
142
+
129
143
  describe "with format :json" do
130
144
  render_views
131
145
  before do
132
146
  get :index, params: { format: 'json' }
133
- expect(response).to be_successful
134
147
  end
135
148
 
136
149
  let(:json) { response.parsed_body }
@@ -139,6 +152,10 @@ RSpec.describe CatalogController, :api do
139
152
  let(:facets) { json['included'].select { |x| x['type'] == 'facet' } }
140
153
  let(:search_fields) { json['included'].select { |x| x['type'] == 'search_field' } }
141
154
 
155
+ it "is successful" do
156
+ expect(response).to be_successful
157
+ end
158
+
142
159
  it "gets the pages" do
143
160
  expect(pages["total_count"]).to eq 30
144
161
  expect(pages["current_page"]).to eq 1
@@ -213,12 +230,13 @@ RSpec.describe CatalogController, :api do
213
230
  end
214
231
 
215
232
  it "with a symbol, it should call a controller method" do
216
- expect(subject).to receive(:render_some_yaml) do
217
- subject.head :ok, layout: false
233
+ allow(controller).to receive(:render_some_yaml) do
234
+ controller.head :ok, layout: false
218
235
  end
219
236
  blacklight_config.index.respond_to.yaml = :render_some_yaml
220
237
  get :index, params: { format: 'yaml' }
221
238
  expect(response.body).to be_blank
239
+ expect(controller).to have_received(:render_some_yaml)
222
240
  end
223
241
  end
224
242
  end # describe index action
@@ -246,7 +264,7 @@ RSpec.describe CatalogController, :api do
246
264
 
247
265
  it "redirects to show action for doc id" do
248
266
  put :track, params: { id: doc_id, counter: 3 }
249
- assert_redirected_to(solr_document_path(doc_id))
267
+ expect(response).to redirect_to(solr_document_path(doc_id))
250
268
  end
251
269
 
252
270
  it "HTTP status code for redirect should be 303" do
@@ -256,17 +274,17 @@ RSpec.describe CatalogController, :api do
256
274
 
257
275
  it "redirects to the path given in the redirect param" do
258
276
  put :track, params: { id: doc_id, counter: 3, redirect: '/xyz' }
259
- assert_redirected_to("/xyz")
277
+ expect(response).to redirect_to("/xyz")
260
278
  end
261
279
 
262
280
  it "redirects to the path of the uri given in the redirect param" do
263
281
  put :track, params: { id: doc_id, counter: 3, redirect: 'http://localhost:3000/xyz' }
264
- assert_redirected_to("/xyz")
282
+ expect(response).to redirect_to("/xyz")
265
283
  end
266
284
 
267
285
  it "keeps querystring on redirect" do
268
286
  put :track, params: { id: doc_id, counter: 3, redirect: 'http://localhost:3000/xyz?locale=pt-BR' }
269
- assert_redirected_to("/xyz?locale=pt-BR")
287
+ expect(response).to redirect_to("/xyz?locale=pt-BR")
270
288
  end
271
289
  end
272
290
 
@@ -335,19 +353,19 @@ RSpec.describe CatalogController, :api do
335
353
 
336
354
  before do
337
355
  allow(mock_document).to receive_messages(export_formats: {})
338
- expect(search_service).to receive(:fetch).and_return(mock_document)
356
+ allow(search_service).to receive(:fetch).and_return(mock_document)
339
357
  allow(controller).to receive_messages(search_service: search_service, current_search_session: current_search)
340
358
  end
341
359
 
342
- context 'if counter is present in session' do
360
+ context 'when counter is present in session' do
343
361
  before do
344
362
  session[:search] = search_session.merge('counter' => 2)
345
363
  end
346
364
 
347
- context 'and no exception is raised' do
365
+ context 'when no exception is raised' do
348
366
  before do
349
- expect(search_service).to receive(:previous_and_next_documents_for_search)
350
- .and_return([double(total: 5), [double("a"), mock_document, double("b")]])
367
+ allow(search_service).to receive(:previous_and_next_documents_for_search)
368
+ .and_return([double(total: 5), [SolrDocument.new(id: "a"), mock_document, SolrDocument.new(id: "b")]])
351
369
  end
352
370
 
353
371
  it "sets previous document" do
@@ -361,11 +379,10 @@ RSpec.describe CatalogController, :api do
361
379
  end
362
380
  end
363
381
 
364
- context 'and an exception is raised' do
382
+ context 'when an exception is raised' do
365
383
  before do
366
- expect(search_service).to receive(:previous_and_next_documents_for_search) {
367
- raise Blacklight::Exceptions::InvalidRequest, "Error"
368
- }
384
+ allow(search_service).to receive(:previous_and_next_documents_for_search)
385
+ .and_raise(Blacklight::Exceptions::InvalidRequest, "Error")
369
386
  end
370
387
 
371
388
  it "does not break" do
@@ -395,16 +412,17 @@ RSpec.describe CatalogController, :api do
395
412
 
396
413
  it "renders show.html.erb" do
397
414
  allow(controller).to receive(:search_service).and_return(search_service)
398
- expect(search_service).to receive(:fetch).and_return(mock_document)
415
+ allow(search_service).to receive(:fetch).and_return(mock_document)
399
416
 
400
417
  get :show, params: { id: doc_id }
401
418
  expect(response).to render_template(:show)
419
+ expect(search_service).to have_received(:fetch)
402
420
  end
403
421
 
404
422
  describe '@document' do
405
423
  before do
406
424
  allow(controller).to receive(:search_service).and_return(search_service)
407
- expect(search_service).to receive(:fetch).and_return(mock_document)
425
+ allow(search_service).to receive(:fetch).and_return(mock_document)
408
426
 
409
427
  get :show, params: { id: doc_id }
410
428
  end
@@ -430,7 +448,7 @@ RSpec.describe CatalogController, :api do
430
448
  Mime::Type.register "application/mock", :mock
431
449
  SolrDocument.use_extension(FakeExtension)
432
450
  allow(controller).to receive(:search_service).and_return(search_service)
433
- expect(search_service).to receive(:fetch).and_return(SolrDocument.new(id: 'my_fake_doc'))
451
+ allow(search_service).to receive(:fetch).and_return(SolrDocument.new(id: 'my_fake_doc'))
434
452
  end
435
453
 
436
454
  after do
@@ -455,7 +473,7 @@ RSpec.describe CatalogController, :api do
455
473
  render_views
456
474
  before do
457
475
  allow(controller).to receive(:search_service).and_return(search_service)
458
- expect(search_service).to receive(:search_results)
476
+ allow(search_service).to receive(:search_results)
459
477
  .and_return(instance_double(Blacklight::Solr::Response, documents: [SolrDocument.new(id: 'my_fake_doc'),
460
478
  SolrDocument.new(id: 'my_other_doc')]))
461
479
  end
@@ -475,7 +493,7 @@ RSpec.describe CatalogController, :api do
475
493
  allow(mock_document).to receive(:to_model).and_return(SolrDocument.new(id: 'my_fake_doc'))
476
494
 
477
495
  allow(controller).to receive(:search_service).and_return(search_service)
478
- expect(search_service).to receive(:fetch).and_return([mock_document])
496
+ allow(search_service).to receive(:fetch).and_return([mock_document])
479
497
  request.env["HTTP_REFERER"] = "/catalog/#{doc_id}"
480
498
  end
481
499
 
@@ -629,7 +647,7 @@ RSpec.describe CatalogController, :api do
629
647
  end
630
648
  end
631
649
 
632
- context 'for a facet field with a key different from the underlying field name' do
650
+ context 'with a facet field with a key different from the underlying field name' do
633
651
  before do
634
652
  controller.blacklight_config.add_facet_field 'params_key', field: 'format'
635
653
  end
@@ -704,6 +722,18 @@ RSpec.describe CatalogController, :api do
704
722
  expect(session).to eq(s)
705
723
  end
706
724
 
725
+ it "ignores a search id that is not in the user's search history" do
726
+ s = Search.create(query_params: { q: "x" })
727
+ allow(controller).to receive_messages(params: parameter_class.new(search_id: s.id))
728
+ expect(controller.send(:current_search_session)).to be_nil
729
+ end
730
+
731
+ it "ignores a stored search session id that is not in the user's search history" do
732
+ s = Search.create(query_params: { q: "x" })
733
+ session[:search] = { 'id' => s.id }
734
+ expect(controller.send(:current_search_session)).to be_nil
735
+ end
736
+
707
737
  it "uses an existing search session if the search is in the uri" do
708
738
  s = Search.create(query_params: { q: "x" })
709
739
  session[:search] ||= {}
@@ -763,18 +793,18 @@ RSpec.describe CatalogController, :api do
763
793
  describe "when posting to the action" do
764
794
  context 'with valid params' do
765
795
  it "calls the supplied method on post" do
766
- expect(controller).to receive(:validate_like_params).and_return(true)
767
- expect(controller).to receive(:perform_like)
796
+ allow(controller).to receive_messages(validate_like_params: true, perform_like: nil)
768
797
  post :like
798
+ expect(controller).to have_received(:perform_like)
769
799
  end
770
800
  end
771
801
 
772
802
  context "with failure on invalid params" do
773
803
  it "does not call the supplied method" do
774
- expect(controller).to receive(:validate_like_params).and_return(false)
775
- expect(controller).not_to receive(:perform_like)
804
+ allow(controller).to receive_messages(validate_like_params: false, perform_like: nil)
776
805
  skip 'Clarify expectations on validator failure: 400? 500? Set a specific error key/msg? Render the same template anyway?'
777
806
  post :like
807
+ expect(controller).not_to have_received(:perform_like)
778
808
  end
779
809
  end
780
810
  end
@@ -22,6 +22,36 @@ RSpec.describe 'Dark mode', :js do
22
22
  expect(page).to have_css('html[data-bs-theme="light"]')
23
23
  end
24
24
 
25
+ context 'when localStorage is unavailable' do
26
+ before do
27
+ # Simulate browsers where touching localStorage throws (e.g. Firefox's NS_ERROR_FAILURE
28
+ # with corrupt profile storage, or a SecurityError when site data is blocked)
29
+ page.driver.browser.execute_cdp(
30
+ 'Page.addScriptToEvaluateOnNewDocument',
31
+ source: <<~JS
32
+ Object.defineProperty(window, 'localStorage', {
33
+ configurable: true,
34
+ get() { throw new DOMException('Storage unavailable', 'SecurityError') }
35
+ })
36
+ JS
37
+ )
38
+ end
39
+
40
+ it 'still initializes the theme and allows switching themes' do
41
+ visit root_path
42
+
43
+ expect(page).to have_css('html[data-bs-theme]')
44
+ expect(page).to have_no_css('html.no-js')
45
+ # showActiveTheme ran on load, so the preferred (OS-derived) theme is marked active
46
+ expect(page).to have_css('[data-bs-theme-value][aria-pressed="true"]', visible: :all)
47
+
48
+ find_by_id('bl-theme-switcher').click
49
+ find('[data-bs-theme-value="dark"]').click
50
+
51
+ expect(page).to have_css('html[data-bs-theme="dark"]')
52
+ end
53
+ end
54
+
25
55
  context 'when dark mode support is disabled in the configuration' do
26
56
  before do
27
57
  allow(Blacklight::Configuration).to receive(:new).and_wrap_original do |m, *args|
@@ -128,7 +128,7 @@ RSpec.describe "Did You Mean" do
128
128
  expect(page).to have_text("Did you mean")
129
129
  end
130
130
 
131
- context 'spellcheck collations are enabled' do
131
+ context 'when spellcheck collations are enabled' do
132
132
  before do
133
133
  CatalogController.blacklight_config[:default_solr_params]["spellcheck.collate"] = true
134
134
  end
@@ -9,7 +9,7 @@ RSpec.describe "Facet missing" do
9
9
  CatalogController.blacklight_config[:default_solr_params].delete("facet.missing")
10
10
  end
11
11
 
12
- context "selecting missing field in facets" do
12
+ context "when selecting missing field in facets" do
13
13
  it "adds facet missing query and constraints" do
14
14
  visit root_path
15
15
 
@@ -31,7 +31,7 @@ RSpec.describe "Facet missing" do
31
31
  end
32
32
  end
33
33
 
34
- context "unselecting the facet missing facet" do
34
+ context "when unselecting the facet missing facet" do
35
35
  it "unselects the missing field facet" do
36
36
  visit root_path
37
37
 
@@ -48,7 +48,7 @@ RSpec.describe "Facet missing" do
48
48
  end
49
49
  end
50
50
 
51
- context "unselecting the facet missing constraint" do
51
+ context "when unselecting the facet missing constraint" do
52
52
  it "unselects the missing field facet" do
53
53
  visit root_path
54
54
 
@@ -3,10 +3,10 @@
3
3
  RSpec.describe 'Modal' do
4
4
  it 'can open and dismiss the email modal', :js do
5
5
  visit solr_document_path('2007020969')
6
- expect(page).to have_no_selector 'dialog#blacklight-modal'
6
+ expect(page).to have_no_css 'dialog#blacklight-modal'
7
7
  click_on 'Email'
8
8
  expect(page).to have_css 'dialog#blacklight-modal'
9
9
  find('button[aria-label=Close]').click
10
- expect(page).to have_no_selector 'dialog#blacklight-modal'
10
+ expect(page).to have_no_css 'dialog#blacklight-modal'
11
11
  end
12
12
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe "Open graph metadata" do
4
+ describe "for a page" do
5
+ before do
6
+ visit "/bookmarks"
7
+ end
8
+
9
+ it "renders open graph metadata for the page" do
10
+ expect(page).to have_css('meta[property="og:type"][content="website"]', visible: :all)
11
+ expect(page).to have_css('meta[property="og:site_name"][content="Blacklight"]', visible: :all)
12
+ expect(page).to have_css('meta[property="og:title"][content="Bookmarks - Blacklight"]', visible: :all)
13
+ expect(page).to have_css('meta[property="og:url"][content="http://www.example.com/bookmarks"]', visible: :all)
14
+ end
15
+ end
16
+
17
+ describe "for a document" do
18
+ before do
19
+ visit "/catalog/2007020969"
20
+ end
21
+
22
+ it "renders open graph metadata for the document" do
23
+ expect(page).to have_css('meta[property="og:type"][content="website"]', visible: :all)
24
+ expect(page).to have_css('meta[property="og:site_name"][content="Blacklight"]', visible: :all)
25
+ expect(page).to have_css('meta[property="og:title"][content="\\"Strong Medicine speaks\\""]', visible: :all)
26
+ expect(page).to have_css('meta[property="og:url"][content="http://www.example.com/catalog/2007020969"]', visible: :all)
27
+ end
28
+ end
29
+
30
+ describe "for a document with a thumbnail" do
31
+ before do
32
+ config = CatalogController.blacklight_config.deep_copy
33
+ config.show.thumbnail_field = 'thumbnail_path_ss'
34
+ allow(CatalogController).to receive(:blacklight_config).and_return(config)
35
+
36
+ visit "/catalog/2008308201"
37
+ end
38
+
39
+ it "renders og:image from the thumbnail field" do
40
+ expect(page).to have_css('meta[property="og:image"][content="https://picsum.photos/seed/2008308201/120/90"]', visible: :all)
41
+ end
42
+ end
43
+ end
@@ -42,7 +42,7 @@ RSpec.describe "Search Results context" do
42
42
  expect(page).to have_no_text "« Previous | 10 of 30 | Next »"
43
43
  end
44
44
 
45
- context "navigating between search results using context pagination" do
45
+ context "when navigating between search results using context pagination" do
46
46
  it "updates the back to search link with the current search pagination context", :js do
47
47
  search_for ''
48
48
  expect(page).to have_text "1 - 10"