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.
- checksums.yaml +4 -4
- data/.env +1 -0
- data/.github/workflows/ruby.yml +6 -0
- data/.gitignore +1 -0
- data/.rubocop_todo.yml +3 -1
- data/README.md +1 -1
- data/Rakefile +18 -0
- data/VERSION +1 -1
- data/app/assets/config/blacklight/manifest.js +3 -0
- data/app/assets/javascripts/blacklight/blacklight.esm.js +132 -140
- data/app/assets/javascripts/blacklight/blacklight.esm.js.map +1 -1
- data/app/assets/javascripts/blacklight/blacklight.js +132 -140
- data/app/assets/javascripts/blacklight/blacklight.js.map +1 -1
- data/app/assets/stylesheets/blacklight/_bootstrap_overrides.scss +1 -1
- data/app/assets/stylesheets/blacklight/_facets.scss +32 -5
- data/app/assets/stylesheets/blacklight/blacklight_defaults.scss +1 -1
- data/app/components/blacklight/advanced_search_form_component.rb +3 -3
- data/app/components/blacklight/document/actions_component.rb +1 -1
- data/app/components/blacklight/document/show_tools_component.html.erb +12 -0
- data/app/components/blacklight/document/show_tools_component.rb +23 -0
- data/app/components/blacklight/document_component.rb +48 -20
- data/app/components/blacklight/document_metadata_component.html.erb +4 -2
- data/app/components/blacklight/document_metadata_component.rb +8 -2
- data/app/components/blacklight/facet_field_checkboxes_component.html.erb +2 -2
- data/app/components/blacklight/facet_field_list_component.html.erb +2 -2
- data/app/components/blacklight/metadata_field_component.html.erb +2 -2
- data/app/components/blacklight/metadata_field_layout_component.rb +7 -4
- data/app/components/blacklight/metadata_field_plain_text_layout_component.rb +17 -0
- data/app/components/blacklight/response/facet_group_component.html.erb +2 -1
- data/app/components/blacklight/response/facet_group_component.rb +1 -1
- data/app/components/blacklight/response/sort_component.rb +1 -1
- data/app/components/blacklight/response/spellcheck_component.rb +1 -1
- data/app/components/blacklight/response/view_type_button_component.rb +1 -1
- data/app/components/blacklight/response/view_type_component.rb +2 -2
- data/app/components/blacklight/search/sidebar_component.html.erb +1 -1
- data/app/components/blacklight/search_context/server_applied_params_component.html.erb +4 -0
- data/app/components/blacklight/search_context/server_applied_params_component.rb +13 -0
- data/app/components/blacklight/search_context/server_item_pagination_component.rb +71 -0
- data/app/components/blacklight/system/dropdown_component.rb +3 -3
- data/app/components/blacklight/system/flash_message_component.rb +2 -2
- data/app/components/blacklight/system/modal_component.rb +1 -1
- data/app/components/blacklight/top_navbar_component.html.erb +1 -1
- data/app/components/blacklight/top_navbar_component.rb +4 -0
- data/app/controllers/concerns/blacklight/bookmarks.rb +1 -1
- data/app/controllers/concerns/blacklight/search_context.rb +46 -6
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +0 -101
- data/app/helpers/blacklight/catalog_helper_behavior.rb +27 -54
- data/app/helpers/blacklight/component_helper_behavior.rb +0 -11
- data/app/helpers/blacklight/document_helper_behavior.rb +76 -0
- data/app/helpers/blacklight/layout_helper_behavior.rb +59 -0
- data/app/helpers/blacklight/render_partials_helper_behavior.rb +1 -0
- data/app/helpers/blacklight/url_helper_behavior.rb +11 -3
- data/app/javascript/blacklight/bookmark_toggle.js +8 -15
- data/app/javascript/blacklight/button_focus.js +10 -10
- data/app/javascript/blacklight/index.js +6 -5
- data/app/javascript/blacklight/modal.js +24 -24
- data/app/javascript/blacklight/search_context.js +51 -57
- data/app/models/concerns/blacklight/document.rb +11 -0
- data/app/models/record_mailer.rb +19 -15
- data/app/presenters/blacklight/document_presenter.rb +13 -11
- data/app/presenters/blacklight/index_presenter.rb +1 -1
- data/app/presenters/blacklight/rendering/abstract_step.rb +4 -0
- data/app/presenters/blacklight/rendering/join.rb +7 -1
- data/app/presenters/blacklight/rendering/link_to_facet.rb +1 -1
- data/app/presenters/blacklight/rendering/microdata.rb +1 -1
- data/app/services/blacklight/search_service.rb +2 -1
- data/app/views/catalog/_document.atom.builder +1 -1
- data/app/views/catalog/_document.html.erb +3 -8
- data/app/views/catalog/_document_list.html.erb +2 -1
- data/app/views/catalog/_facet_layout.html.erb +2 -2
- data/app/views/catalog/_show_main_content.html.erb +5 -11
- data/app/views/catalog/_show_tools.html.erb +1 -14
- data/app/views/catalog/facet.html.erb +3 -3
- data/app/views/catalog/index.html.erb +3 -0
- data/app/views/catalog/show.html.erb +1 -6
- data/app/views/layouts/blacklight/base.html.erb +4 -5
- data/app/views/record_mailer/email_record.text.erb +4 -3
- data/app/views/record_mailer/sms_record.text.erb +4 -4
- data/blacklight.gemspec +2 -2
- data/config/importmap.rb +1 -1
- data/config/locales/blacklight.ar.yml +209 -232
- data/config/locales/blacklight.ca.yml +0 -6
- data/config/locales/blacklight.de.yml +197 -215
- data/config/locales/blacklight.en.yml +2 -6
- data/config/locales/blacklight.es.yml +196 -215
- data/config/locales/blacklight.fr.yml +196 -219
- data/config/locales/blacklight.hu.yml +193 -212
- data/config/locales/blacklight.it.yml +197 -215
- data/config/locales/blacklight.nl.yml +193 -212
- data/config/locales/blacklight.pt-BR.yml +195 -215
- data/config/locales/blacklight.sq.yml +193 -212
- data/config/locales/blacklight.zh.yml +194 -213
- data/docker-compose.yml +1 -0
- data/lib/blacklight/configuration/session_tracking_config.rb +45 -0
- data/lib/blacklight/configuration/view_config.rb +0 -4
- data/lib/blacklight/configuration.rb +8 -4
- data/lib/blacklight/engine.rb +6 -7
- data/lib/blacklight/routes/searchable.rb +1 -0
- data/lib/generators/blacklight/assets/importmap_generator.rb +9 -8
- data/lib/generators/blacklight/assets/propshaft_generator.rb +11 -2
- data/lib/generators/blacklight/assets/sprockets_generator.rb +2 -0
- data/lib/generators/blacklight/assets_generator.rb +3 -1
- data/lib/generators/blacklight/install_generator.rb +3 -1
- data/lib/generators/blacklight/templates/solr_document.rb +0 -6
- data/package.json +7 -4
- data/rollup.config.js +11 -1
- data/spec/components/blacklight/document_component_spec.rb +66 -15
- data/spec/components/blacklight/header_component_spec.rb +20 -0
- data/spec/components/blacklight/response/view_type_component_spec.rb +17 -0
- data/spec/components/blacklight/search_bar_component_spec.rb +1 -1
- data/spec/components/blacklight/search_context/server_applied_params_component_spec.rb +29 -0
- data/spec/components/blacklight/{search_context_component_spec.rb → search_context/server_item_pagination_component_spec.rb} +15 -4
- data/spec/controllers/bookmarks_controller_spec.rb +1 -1
- data/spec/controllers/catalog_controller_spec.rb +18 -6
- data/spec/features/component_template_override_spec.rb +8 -0
- data/spec/features/modal_spec.rb +12 -0
- data/spec/features/sitelinks_search_box_spec.rb +13 -0
- data/spec/helpers/blacklight/url_helper_behavior_spec.rb +1 -1
- data/spec/helpers/blacklight_helper_spec.rb +0 -56
- data/spec/helpers/catalog_helper_spec.rb +56 -0
- data/spec/lib/blacklight/configuration/session_tracking_config_spec.rb +38 -0
- data/spec/lib/blacklight/open_struct_with_hash_access_spec.rb +2 -2
- data/spec/models/blacklight/configuration_spec.rb +2 -2
- data/spec/models/blacklight/icon_spec.rb +0 -2
- data/spec/models/blacklight/search_builder_spec.rb +3 -3
- data/spec/models/blacklight/solr/request_spec.rb +2 -2
- data/spec/models/record_mailer_spec.rb +36 -23
- data/spec/presenters/blacklight/document_presenter_spec.rb +1 -0
- data/spec/presenters/blacklight/field_presenter_spec.rb +2 -2
- data/spec/presenters/blacklight/index_presenter_spec.rb +1 -0
- data/spec/presenters/blacklight/show_presenter_spec.rb +1 -0
- data/spec/presenters/pipeline_spec.rb +13 -2
- data/spec/routing/catalog_routing_spec.rb +4 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/support/view_component_test_helpers.rb +21 -0
- data/spec/test_app_templates/Gemfile.extra +4 -0
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +8 -0
- data/spec/views/catalog/_document.html.erb_spec.rb +22 -1
- data/spec/views/catalog/_document_list.html.erb_spec.rb +7 -2
- data/spec/views/catalog/_show_tools.html.erb_spec.rb +2 -2
- data/spec/views/catalog/index.json.jbuilder_spec.rb +1 -1
- data/tasks/blacklight.rake +1 -1
- metadata +39 -21
- data/app/components/blacklight/search_context_component.rb +0 -68
- data/app/models/concerns/blacklight/document/email.rb +0 -27
- data/app/models/concerns/blacklight/document/sms.rb +0 -25
- data/spec/features/sitelinks_search_box.rb +0 -13
- data/spec/models/blacklight/document/email_spec.rb +0 -57
- data/spec/models/blacklight/document/sms_spec.rb +0 -58
- data/spec/support/view_component_capybara_test_helpers.rb +0 -8
- /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
|
|
176
|
-
expect(config_copy.b).to
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
21
|
-
details
|
|
22
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
43
|
-
expect(
|
|
44
|
-
expect(
|
|
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
|
-
|
|
66
|
+
before do
|
|
57
67
|
config.email.title_field = "foo"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
78
|
+
before do
|
|
68
79
|
config.email.title_field = "foo"
|
|
69
|
-
|
|
70
|
-
|
|
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 /
|
|
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
|
|
|
@@ -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.
|
|
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
|
|
60
|
+
it { is_expected.to eq('<a and b').and be_html_safe }
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
context 'when an explicit array value is provided' 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) {
|
|
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
|
|
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
|
|
@@ -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(
|
|
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::
|
|
6
|
+
let(:component) { instance_double(Blacklight::Document::ShowToolsComponent) }
|
|
7
7
|
|
|
8
8
|
before do
|
|
9
|
-
allow(Blacklight::Document::
|
|
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
|
|
96
|
+
expect(format_item_attributes).to contain_exactly({ value: 'Book', hits: 30, label: 'Book' })
|
|
97
97
|
end
|
|
98
98
|
end
|
|
99
99
|
|