blacklight 7.5.1 → 7.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.docker/app/Dockerfile +26 -0
- data/.docker/app/entrypoint.sh +6 -0
- data/.env +5 -0
- data/.gitignore +0 -1
- data/.rubocop_todo.yml +25 -36
- data/.travis.yml +15 -23
- data/Gemfile +4 -1
- data/README.md +4 -0
- data/VERSION +1 -1
- data/app/assets/stylesheets/blacklight/_facets.scss +20 -4
- data/app/assets/stylesheets/blacklight/_pagination.scss +4 -0
- data/app/components/blacklight/constraint_layout_component.html.erb +23 -0
- data/app/components/blacklight/constraint_layout_component.rb +16 -0
- data/app/components/blacklight/facet_field_component.html.erb +25 -0
- data/app/components/blacklight/facet_field_component.rb +11 -0
- data/app/components/blacklight/facet_field_list_component.html.erb +18 -0
- data/app/components/blacklight/facet_field_list_component.rb +22 -0
- data/app/components/blacklight/facet_field_no_layout_component.rb +13 -0
- data/app/components/blacklight/facet_item_component.rb +120 -0
- data/app/components/blacklight/facet_item_pivot_component.rb +84 -0
- data/app/helpers/blacklight/blacklight_helper_behavior.rb +4 -2
- data/app/helpers/blacklight/catalog_helper_behavior.rb +2 -4
- data/app/helpers/blacklight/configuration_helper_behavior.rb +3 -2
- data/app/helpers/blacklight/facets_helper_behavior.rb +92 -49
- data/app/helpers/blacklight/render_constraints_helper_behavior.rb +64 -33
- data/app/javascript/blacklight/modal.js +1 -1
- data/app/models/blacklight/icon.rb +13 -11
- data/app/models/concerns/blacklight/document.rb +0 -10
- data/app/models/concerns/blacklight/document/extensions.rb +3 -0
- data/app/models/concerns/blacklight/document/semantic_fields.rb +0 -4
- data/app/presenters/blacklight/document_presenter.rb +27 -36
- data/app/presenters/blacklight/facet_field_presenter.rb +57 -0
- data/app/presenters/blacklight/facet_item_presenter.rb +81 -0
- data/app/presenters/blacklight/field_presenter.rb +31 -6
- data/app/presenters/blacklight/index_presenter.rb +2 -2
- data/app/presenters/blacklight/show_presenter.rb +3 -3
- data/app/views/catalog/_citation.html.erb +1 -1
- data/app/views/catalog/_constraints.html.erb +3 -3
- data/app/views/catalog/_constraints_element.html.erb +5 -24
- data/app/views/catalog/_email_form.html.erb +1 -1
- data/app/views/catalog/_facet_layout.html.erb +8 -17
- data/app/views/catalog/_facet_limit.html.erb +3 -12
- data/app/views/catalog/_facet_pagination.html.erb +2 -2
- data/app/views/catalog/_facet_pivot.html.erb +3 -18
- data/app/views/catalog/_field.json.jbuilder +2 -2
- data/app/views/catalog/_index.html.erb +3 -3
- data/app/views/catalog/_previous_next_doc.html.erb +5 -5
- data/app/views/catalog/_search_form.html.erb +1 -1
- data/app/views/catalog/_show.html.erb +3 -3
- data/app/views/catalog/_sms_form.html.erb +1 -1
- data/app/views/catalog/_sort_and_per_page.html.erb +1 -1
- data/app/views/catalog/_start_over.html.erb +1 -0
- data/app/views/catalog/_thumbnail.html.erb +1 -1
- data/app/views/catalog/index.json.jbuilder +2 -1
- data/app/views/catalog/show.html.erb +1 -1
- data/app/views/catalog/show.json.jbuilder +2 -1
- data/app/views/layouts/blacklight/base.html.erb +2 -2
- data/blacklight.gemspec +1 -0
- data/config/locales/blacklight.ar.yml +33 -24
- data/config/locales/blacklight.de.yml +5 -0
- data/config/locales/blacklight.en.yml +5 -0
- data/config/locales/blacklight.es.yml +5 -0
- data/config/locales/blacklight.fr.yml +5 -0
- data/config/locales/blacklight.hu.yml +5 -0
- data/config/locales/blacklight.it.yml +5 -0
- data/config/locales/blacklight.nl.yml +5 -0
- data/config/locales/blacklight.pt-BR.yml +5 -0
- data/config/locales/blacklight.sq.yml +5 -0
- data/config/locales/blacklight.zh.yml +5 -0
- data/docker-compose.yml +35 -0
- data/lib/blacklight/configuration.rb +35 -8
- data/lib/blacklight/configuration/field.rb +5 -4
- data/lib/blacklight/engine.rb +2 -6
- data/lib/blacklight/search_state.rb +52 -0
- data/lib/blacklight/solr/response/facets.rb +2 -0
- data/lib/generators/blacklight/assets_generator.rb +10 -0
- data/lib/generators/blacklight/templates/catalog_controller.rb +1 -1
- data/package-lock.json +4 -4
- data/package.json +2 -2
- data/spec/{views/catalog/_constraints_element.html.erb_spec.rb → components/blacklight/constraint_layout_component_spec.rb} +22 -12
- data/spec/components/blacklight/facet_field_list_component_spec.rb +108 -0
- data/spec/components/blacklight/facet_item_component_spec.rb +50 -0
- data/spec/components/blacklight/facet_item_pivot_component_spec.rb +66 -0
- data/spec/features/facets_spec.rb +21 -1
- data/spec/helpers/blacklight/configuration_helper_behavior_spec.rb +3 -0
- data/spec/helpers/blacklight/facets_helper_behavior_spec.rb +24 -12
- data/spec/helpers/blacklight/render_constraints_helper_behavior_spec.rb +4 -23
- data/spec/helpers/blacklight_helper_spec.rb +17 -0
- data/spec/helpers/catalog_helper_spec.rb +0 -7
- data/spec/lib/blacklight/search_state_spec.rb +50 -0
- data/spec/models/blacklight/configuration_spec.rb +4 -0
- data/spec/models/blacklight/icon_spec.rb +11 -10
- data/spec/models/blacklight/solr/response/facets_spec.rb +30 -1
- data/spec/presenters/blacklight/document_presenter_spec.rb +22 -62
- data/spec/presenters/blacklight/facet_field_presenter_spec.rb +109 -0
- data/spec/presenters/blacklight/facet_item_presenter_spec.rb +92 -0
- data/spec/presenters/blacklight/field_presenter_spec.rb +268 -0
- data/spec/presenters/blacklight/index_presenter_spec.rb +0 -142
- data/spec/presenters/blacklight/show_presenter_spec.rb +0 -177
- data/spec/spec_helper.rb +3 -0
- data/spec/support/presenter_test_helpers.rb +11 -0
- data/spec/views/catalog/_facet_group.html.erb_spec.rb +1 -0
- data/spec/views/catalog/_previous_next_doc.html.erb_spec.rb +18 -0
- data/tasks/blacklight.rake +30 -23
- metadata +51 -7
- data/Vagrantfile +0 -79
- data/provision.sh +0 -30
data/docker-compose.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
version: "3.7"
|
2
|
+
|
3
|
+
services:
|
4
|
+
app:
|
5
|
+
build:
|
6
|
+
context: .
|
7
|
+
dockerfile: .docker/app/Dockerfile
|
8
|
+
args:
|
9
|
+
- ALPINE_RUBY_VERSION
|
10
|
+
volumes:
|
11
|
+
- .:/app
|
12
|
+
depends_on:
|
13
|
+
- solr
|
14
|
+
ports:
|
15
|
+
- "3000:3000"
|
16
|
+
environment:
|
17
|
+
- SOLR_URL # Set via environment variable or use default defined in .env file
|
18
|
+
- RAILS_VERSION # Set via environment variable or use default defined in .env file
|
19
|
+
|
20
|
+
solr:
|
21
|
+
environment:
|
22
|
+
- SOLR_PORT # Set via environment variable or use default defined in .env file
|
23
|
+
- SOLR_VERSION # Set via environment variable or use default defined in .env file
|
24
|
+
image: "solr:${SOLR_VERSION}"
|
25
|
+
volumes:
|
26
|
+
- $PWD/lib/generators/blacklight/templates/solr/conf:/opt/solr/conf
|
27
|
+
ports:
|
28
|
+
- "${SOLR_PORT}:8983"
|
29
|
+
entrypoint:
|
30
|
+
- docker-entrypoint.sh
|
31
|
+
- solr-precreate
|
32
|
+
- blacklight-core
|
33
|
+
- /opt/solr/conf
|
34
|
+
- "-Xms256m"
|
35
|
+
- "-Xmx512m"
|
@@ -282,15 +282,10 @@ module Blacklight
|
|
282
282
|
# Provide a 'deep copy' of Blacklight::Configuration that can be modified without effecting
|
283
283
|
# the original Blacklight::Configuration instance.
|
284
284
|
#
|
285
|
-
# Rails
|
286
|
-
#
|
285
|
+
# Note: Rails provides `#deep_dup`, but it aggressively `#dup`'s class names too, turning them
|
286
|
+
# into anonymous class instances.
|
287
287
|
def deep_copy
|
288
|
-
|
289
|
-
%w(repository_class response_model document_model document_presenter_class search_builder_class facet_paginator_class).each do |klass|
|
290
|
-
# Don't copy if nil, so as not to prematurely autoload default classes
|
291
|
-
copy.send("#{klass}=", send(klass)) unless fetch(klass.to_sym, nil).nil?
|
292
|
-
end
|
293
|
-
end
|
288
|
+
deep_transform_values_in_object(self, &method(:_deep_copy))
|
294
289
|
end
|
295
290
|
|
296
291
|
# builds a copy for the provided controller class
|
@@ -402,5 +397,37 @@ module Blacklight
|
|
402
397
|
yield(config) if block_given?
|
403
398
|
config_hash[name] = config
|
404
399
|
end
|
400
|
+
|
401
|
+
# Provide custom duplication for certain types of configuration (intended for use in e.g. deep_transform_values)
|
402
|
+
def _deep_copy(value)
|
403
|
+
case value
|
404
|
+
when Module then value
|
405
|
+
when NestedOpenStructWithHashAccess then value.class.new(value.nested_class, deep_transform_values_in_object(value.to_h, &method(:_deep_copy)))
|
406
|
+
when OpenStruct then value.class.new(deep_transform_values_in_object(value.to_h, &method(:_deep_copy)))
|
407
|
+
else
|
408
|
+
value.dup
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
# This is a little shim to support Rails 6 (which has Hash#deep_transform_values) and
|
413
|
+
# earlier versions (which use our backport). Once we drop support for Rails 6, this
|
414
|
+
# can go away.
|
415
|
+
def deep_transform_values_in_object(object, &block)
|
416
|
+
return object.deep_transform_values(&block) if object.respond_to?(:deep_transform_values)
|
417
|
+
|
418
|
+
_deep_transform_values_in_object(object, &block)
|
419
|
+
end
|
420
|
+
|
421
|
+
# Ported from Rails 6
|
422
|
+
def _deep_transform_values_in_object(object, &block)
|
423
|
+
case object
|
424
|
+
when Hash
|
425
|
+
object.transform_values { |value| _deep_transform_values_in_object(value, &block) }
|
426
|
+
when Array
|
427
|
+
object.map { |e| _deep_transform_values_in_object(e, &block) }
|
428
|
+
else
|
429
|
+
yield(object)
|
430
|
+
end
|
431
|
+
end
|
405
432
|
end
|
406
433
|
end
|
@@ -19,12 +19,13 @@ module Blacklight
|
|
19
19
|
raise ArgumentError, "Must supply a field name" if self.field.nil?
|
20
20
|
end
|
21
21
|
|
22
|
-
def display_label(context = nil)
|
22
|
+
def display_label(context = nil, **options)
|
23
23
|
field_label(
|
24
24
|
(:"blacklight.search.fields.#{context}.#{key}" if context),
|
25
25
|
:"blacklight.search.fields.#{key}",
|
26
26
|
label,
|
27
|
-
default_label
|
27
|
+
default_label,
|
28
|
+
**options
|
28
29
|
)
|
29
30
|
end
|
30
31
|
|
@@ -50,10 +51,10 @@ module Blacklight
|
|
50
51
|
# before falling back to the label
|
51
52
|
# @param [Symbol] any number of additional keys
|
52
53
|
# @param [Symbol] ...
|
53
|
-
def field_label *i18n_keys
|
54
|
+
def field_label *i18n_keys, **options
|
54
55
|
first, *rest = i18n_keys.compact
|
55
56
|
|
56
|
-
I18n.t(first, default: rest)
|
57
|
+
I18n.t(first, default: rest, **options)
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
data/lib/blacklight/engine.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'view_component/engine'
|
3
|
+
|
2
4
|
module Blacklight
|
3
5
|
class Engine < Rails::Engine
|
4
6
|
engine_name "blacklight"
|
@@ -9,12 +11,6 @@ module Blacklight
|
|
9
11
|
ActionView::Base.send :include, BlacklightHelper
|
10
12
|
end
|
11
13
|
|
12
|
-
config.autoload_paths += %W(
|
13
|
-
#{config.root}/app/presenters
|
14
|
-
#{config.root}/app/controllers/concerns
|
15
|
-
#{config.root}/app/models/concerns
|
16
|
-
)
|
17
|
-
|
18
14
|
# This makes our rake tasks visible.
|
19
15
|
rake_tasks do
|
20
16
|
Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '..'))) do
|
@@ -37,6 +37,42 @@ module Blacklight
|
|
37
37
|
end
|
38
38
|
alias to_h to_hash
|
39
39
|
|
40
|
+
def to_unsafe_h
|
41
|
+
Deprecation.warn(self, 'Use SearchState#to_h instead of SearchState#to_unsafe_h')
|
42
|
+
to_hash
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(method_name, *arguments, &block)
|
46
|
+
if @params.respond_to?(method_name)
|
47
|
+
Deprecation.warn(self, "Calling `#{method_name}` on Blacklight::SearchState " \
|
48
|
+
'is deprecated and will be removed in Blacklight 8. Call #to_h first if you ' \
|
49
|
+
' need to use hash methods (or, preferably, use your own SearchState implementation)')
|
50
|
+
@params.public_send(method_name, *arguments, &block)
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def respond_to_missing?(method_name, include_private = false)
|
57
|
+
@params.respond_to?(method_name, include_private) || super
|
58
|
+
end
|
59
|
+
|
60
|
+
# Tiny shim to make it easier to migrate raw params access to using this class
|
61
|
+
delegate :[], to: :params
|
62
|
+
deprecation_deprecate :[]
|
63
|
+
|
64
|
+
def has_constraints?
|
65
|
+
!(query_param.blank? && filter_params.blank?)
|
66
|
+
end
|
67
|
+
|
68
|
+
def query_param
|
69
|
+
params[:q]
|
70
|
+
end
|
71
|
+
|
72
|
+
def filter_params
|
73
|
+
params[:f] || {}
|
74
|
+
end
|
75
|
+
|
40
76
|
def reset(params = nil)
|
41
77
|
self.class.new(params || ActionController::Parameters.new, blacklight_config, controller)
|
42
78
|
end
|
@@ -57,6 +93,12 @@ module Blacklight
|
|
57
93
|
end
|
58
94
|
end
|
59
95
|
|
96
|
+
def remove_query_params
|
97
|
+
p = reset_search_params
|
98
|
+
p.delete(:q)
|
99
|
+
p
|
100
|
+
end
|
101
|
+
|
60
102
|
# adds the value and/or field to params[:f]
|
61
103
|
# Does NOT remove request keys and otherwise ensure that the hash
|
62
104
|
# is suitable for a redirect. See
|
@@ -130,6 +172,16 @@ module Blacklight
|
|
130
172
|
p
|
131
173
|
end
|
132
174
|
|
175
|
+
def has_facet?(config, value: nil)
|
176
|
+
facet = params&.dig(:f, config.key)
|
177
|
+
|
178
|
+
if value
|
179
|
+
(facet || []).include? value
|
180
|
+
else
|
181
|
+
facet.present?
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
133
185
|
# Merge the source params with the params_to_merge hash
|
134
186
|
# @param [Hash] params_to_merge to merge into above
|
135
187
|
# @return [ActionController::Parameters] the current search parameters after being sanitized by Blacklight::Parameters.sanitize
|
@@ -210,6 +210,8 @@ module Blacklight::Solr::Response::Facets
|
|
210
210
|
Blacklight::Solr::Response::Facets::FacetItem.new(value: key, hits: hits, label: facet_field.query[key][:label])
|
211
211
|
end
|
212
212
|
|
213
|
+
items = items.sort_by(&:hits).reverse if facet_field.sort && facet_field.sort.to_sym == :count
|
214
|
+
|
213
215
|
hash[field_name] = Blacklight::Solr::Response::Facets::FacetField.new field_name, items
|
214
216
|
end
|
215
217
|
end
|
@@ -22,6 +22,16 @@ module Blacklight
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
##
|
26
|
+
# Remove the empty generated app/assets/images directory. Without doing this,
|
27
|
+
# the default Sprockets 4 manifest will raise an exception.
|
28
|
+
def appease_sprockets4
|
29
|
+
return if !defined?(Sprockets::VERSION) || Sprockets::VERSION < '4'
|
30
|
+
|
31
|
+
append_to_file 'app/assets/config/manifest.js', "\n//= link application.js"
|
32
|
+
empty_directory 'app/assets/images'
|
33
|
+
end
|
34
|
+
|
25
35
|
def assets
|
26
36
|
copy_file "blacklight.scss", "app/assets/stylesheets/blacklight.scss"
|
27
37
|
|
@@ -84,7 +84,7 @@ class <%= controller_name.classify %>Controller < ApplicationController
|
|
84
84
|
config.add_facet_field 'subject_geo_ssim', label: 'Region'
|
85
85
|
config.add_facet_field 'subject_era_ssim', label: 'Era'
|
86
86
|
|
87
|
-
config.add_facet_field 'example_pivot_field', label: 'Pivot Field', :
|
87
|
+
config.add_facet_field 'example_pivot_field', label: 'Pivot Field', pivot: ['format', 'language_ssim'], collapsing: true
|
88
88
|
|
89
89
|
config.add_facet_field 'example_query_facet_field', label: 'Publish Date', :query => {
|
90
90
|
:years_5 => { label: 'within 5 Years', fq: "pub_date_ssim:[#{Time.zone.now.year - 5 } TO *]" },
|
data/package-lock.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "blacklight-frontend",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.7.0",
|
4
4
|
"lockfileVersion": 1,
|
5
5
|
"requires": true,
|
6
6
|
"dependencies": {
|
@@ -1884,9 +1884,9 @@
|
|
1884
1884
|
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
|
1885
1885
|
},
|
1886
1886
|
"jquery": {
|
1887
|
-
"version": "3.
|
1888
|
-
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.
|
1889
|
-
"integrity": "sha512-
|
1887
|
+
"version": "3.5.1",
|
1888
|
+
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz",
|
1889
|
+
"integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg=="
|
1890
1890
|
},
|
1891
1891
|
"js-tokens": {
|
1892
1892
|
"version": "4.0.0",
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "blacklight-frontend",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.7.0",
|
4
4
|
"description": "[![Build Status](https://travis-ci.org/projectblacklight/blacklight.png?branch=master)](https://travis-ci.org/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=master)](https://coveralls.io/github/projectblacklight/blacklight?branch=master)",
|
5
5
|
"main": "app/assets/javascripts/blacklight",
|
6
6
|
"scripts": {
|
@@ -24,7 +24,7 @@
|
|
24
24
|
"dependencies": {
|
25
25
|
"bloodhound-js": "^1.2.3",
|
26
26
|
"bootstrap": "^4.3.1",
|
27
|
-
"jquery": "^3.
|
27
|
+
"jquery": "^3.5.1",
|
28
28
|
"typeahead.js": "^0.11.1"
|
29
29
|
}
|
30
30
|
}
|
@@ -1,24 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Blacklight::ConstraintLayoutComponent, type: :component do
|
6
|
+
subject(:render) do
|
7
|
+
render_inline(described_class.new(params))
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:rendered) do
|
11
|
+
Capybara::Node::Simple.new(render)
|
12
|
+
end
|
13
|
+
|
4
14
|
describe "for simple display" do
|
5
|
-
|
6
|
-
|
15
|
+
let(:params) do
|
16
|
+
{ label: "my label", value: "my value" }
|
7
17
|
end
|
8
18
|
|
9
19
|
it "renders label and value" do
|
10
20
|
expect(rendered).to have_selector("span.applied-filter.constraint") do |s|
|
11
21
|
expect(s).to have_css("span.constraint-value")
|
12
22
|
expect(s).not_to have_css("a.constraint-value")
|
13
|
-
expect(s).to have_selector "span.filter-name",
|
14
|
-
expect(s).to have_selector "span.filter-value",
|
23
|
+
expect(s).to have_selector "span.filter-name", text: "my label"
|
24
|
+
expect(s).to have_selector "span.filter-value", text: "my value"
|
15
25
|
end
|
16
26
|
end
|
17
27
|
end
|
18
28
|
|
19
29
|
describe "with remove link" do
|
20
|
-
|
21
|
-
|
30
|
+
let(:params) do
|
31
|
+
{ label: "my label", value: "my value", remove_path: "http://remove" }
|
22
32
|
end
|
23
33
|
|
24
34
|
it "includes remove link" do
|
@@ -28,14 +38,14 @@ RSpec.describe "catalog/_constraints_element.html.erb" do
|
|
28
38
|
end
|
29
39
|
it "has an accessible remove label" do
|
30
40
|
expect(rendered).to have_selector(".remove") do |s|
|
31
|
-
expect(s).to
|
41
|
+
expect(s).to have_selector('.sr-only', text: 'Remove constraint my label: my value')
|
32
42
|
end
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
36
46
|
describe "with custom classes" do
|
37
|
-
|
38
|
-
|
47
|
+
let(:params) do
|
48
|
+
{ label: "my label", value: "my value", classes: %w[class1 class2] }
|
39
49
|
end
|
40
50
|
|
41
51
|
it "includes them" do
|
@@ -44,8 +54,8 @@ RSpec.describe "catalog/_constraints_element.html.erb" do
|
|
44
54
|
end
|
45
55
|
|
46
56
|
describe "with no escaping" do
|
47
|
-
|
48
|
-
|
57
|
+
let(:params) do
|
58
|
+
{ label: "<span class='custom_label'>my label</span>".html_safe, value: "<span class='custom_value'>my value</span>".html_safe }
|
49
59
|
end
|
50
60
|
|
51
61
|
it "does not escape key and value" do
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Blacklight::FacetFieldListComponent, type: :component do
|
6
|
+
subject(:render) do
|
7
|
+
render_inline(described_class.new(facet_field: facet_field))
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:rendered) do
|
11
|
+
Capybara::Node::Simple.new(render)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:facet_field) do
|
15
|
+
instance_double(
|
16
|
+
Blacklight::FacetFieldPresenter,
|
17
|
+
paginator: paginator,
|
18
|
+
key: 'field',
|
19
|
+
label: 'Field',
|
20
|
+
active?: false,
|
21
|
+
collapsed?: false,
|
22
|
+
modal_path: nil,
|
23
|
+
html_id: 'facet-field'
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:paginator) do
|
28
|
+
instance_double(Blacklight::FacetPaginator, items: [
|
29
|
+
double(label: 'x', hits: 10),
|
30
|
+
double(label: 'y', hits: 33)
|
31
|
+
])
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'renders a collapsible card' do
|
35
|
+
expect(rendered).to have_selector '.card'
|
36
|
+
expect(rendered).to have_button 'Field'
|
37
|
+
expect(rendered).to have_selector 'button[data-target="#facet-field"]'
|
38
|
+
expect(rendered).to have_selector '#facet-field.collapse.show'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'renders the facet items' do
|
42
|
+
expect(rendered).to have_selector 'ul.facet-values'
|
43
|
+
expect(rendered).to have_selector 'li', count: 2
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with an active facet' do
|
47
|
+
let(:facet_field) do
|
48
|
+
instance_double(
|
49
|
+
Blacklight::FacetFieldPresenter,
|
50
|
+
paginator: paginator,
|
51
|
+
key: 'field',
|
52
|
+
label: 'Field',
|
53
|
+
active?: true,
|
54
|
+
collapsed?: false,
|
55
|
+
modal_path: nil,
|
56
|
+
html_id: 'facet-field'
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'adds the facet-limit-active class' do
|
61
|
+
expect(rendered).to have_selector 'div.facet-limit-active'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'with a collapsed facet' do
|
66
|
+
let(:facet_field) do
|
67
|
+
instance_double(
|
68
|
+
Blacklight::FacetFieldPresenter,
|
69
|
+
paginator: paginator,
|
70
|
+
key: 'field',
|
71
|
+
label: 'Field',
|
72
|
+
active?: false,
|
73
|
+
collapsed?: true,
|
74
|
+
modal_path: nil,
|
75
|
+
html_id: 'facet-field'
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'renders a collapsed facet' do
|
80
|
+
expect(rendered).to have_selector '.facet-content.collapse'
|
81
|
+
expect(rendered).not_to have_selector '.facet-content.collapse.show'
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'renders the toggle button in the collapsed state' do
|
85
|
+
expect(rendered).to have_selector '.btn.collapsed'
|
86
|
+
expect(rendered).to have_selector '.btn[aria-expanded="false"]'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'with a modal_path' do
|
91
|
+
let(:facet_field) do
|
92
|
+
instance_double(
|
93
|
+
Blacklight::FacetFieldPresenter,
|
94
|
+
paginator: paginator,
|
95
|
+
key: 'field',
|
96
|
+
label: 'Field',
|
97
|
+
active?: false,
|
98
|
+
collapsed?: false,
|
99
|
+
modal_path: '/catalog/facet/modal',
|
100
|
+
html_id: 'facet-field'
|
101
|
+
)
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'renders a link to the modal' do
|
105
|
+
expect(rendered).to have_link 'more Field', href: '/catalog/facet/modal'
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|