blacklight_range_limit 8.5.0 → 9.0.0.beta2

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 (77) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +117 -26
  3. data/.gitignore +2 -1
  4. data/.solr_wrapper.yml +8 -0
  5. data/Gemfile +7 -1
  6. data/README.md +84 -87
  7. data/Rakefile +69 -0
  8. data/VERSION +1 -1
  9. data/app/assets/javascripts/blacklight-range-limit/index.js +345 -0
  10. data/app/components/blacklight_range_limit/range_facet_component.html.erb +29 -27
  11. data/app/components/blacklight_range_limit/range_facet_component.rb +27 -9
  12. data/app/components/blacklight_range_limit/range_form_component.html.erb +23 -5
  13. data/app/components/blacklight_range_limit/range_form_component.rb +8 -20
  14. data/app/presenters/blacklight_range_limit/facet_field_presenter.rb +13 -2
  15. data/app/presenters/blacklight_range_limit/facet_item_presenter.rb +15 -11
  16. data/app/presenters/blacklight_range_limit/filter_field.rb +9 -3
  17. data/blacklight_range_limit.gemspec +1 -1
  18. data/config/importmap.rb +9 -0
  19. data/config/locales/blacklight_range_limit.ar.yml +13 -8
  20. data/config/locales/blacklight_range_limit.de.yml +13 -8
  21. data/config/locales/blacklight_range_limit.en.yml +5 -1
  22. data/config/locales/blacklight_range_limit.es.yml +18 -0
  23. data/config/locales/blacklight_range_limit.it.yml +13 -8
  24. data/doc/example-screenshot.png +0 -0
  25. data/lib/blacklight_range_limit/controller_override.rb +8 -35
  26. data/lib/blacklight_range_limit/engine.rb +48 -0
  27. data/lib/blacklight_range_limit/range_limit_builder.rb +61 -3
  28. data/lib/blacklight_range_limit.rb +10 -30
  29. data/lib/generators/blacklight_range_limit/assets_generator.rb +82 -18
  30. data/lib/generators/blacklight_range_limit/install_generator.rb +5 -2
  31. data/lib/generators/blacklight_range_limit/jsbundling_bl7_fixup_generator.rb +98 -0
  32. data/package-lock.json +8 -7
  33. data/package.json +10 -14
  34. data/spec/components/range_facet_component_spec.rb +101 -32
  35. data/spec/components/range_form_component_spec.rb +2 -2
  36. data/spec/components/range_segments_component_spec.rb +64 -0
  37. data/spec/features/blacklight_range_limit_spec.rb +21 -13
  38. data/spec/features/run_through_spec.rb +210 -0
  39. data/spec/presenters/facet_field_presenter_spec.rb +72 -0
  40. data/spec/presenters/filter_field_spec.rb +36 -1
  41. data/spec/requests/bad_param_requests_spec.rb +61 -0
  42. data/spec/spec_helper.rb +10 -0
  43. data/spec/test_app_templates/Gemfile.extra +11 -1
  44. data/spec/test_app_templates/lib/generators/test_app_generator.rb +37 -6
  45. metadata +27 -51
  46. data/app/assets/javascripts/blacklight_range_limit/blacklight_range_limit.esm.js +0 -534
  47. data/app/assets/javascripts/blacklight_range_limit/blacklight_range_limit.esm.js.map +0 -1
  48. data/app/assets/javascripts/blacklight_range_limit/blacklight_range_limit.umd.js +0 -542
  49. data/app/assets/javascripts/blacklight_range_limit/blacklight_range_limit.umd.js.map +0 -1
  50. data/app/assets/javascripts/blacklight_range_limit.js +0 -27
  51. data/app/assets/stylesheets/blacklight_range_limit/blacklight_range_limit.css +0 -60
  52. data/app/assets/stylesheets/blacklight_range_limit.css +0 -7
  53. data/app/helpers/range_limit_helper.rb +0 -130
  54. data/app/javascript/blacklight_range_limit/index.js +0 -11
  55. data/app/javascript/blacklight_range_limit/range_limit_distro_facets.js +0 -76
  56. data/app/javascript/blacklight_range_limit/range_limit_plotting.js +0 -186
  57. data/app/javascript/blacklight_range_limit/range_limit_shared.js +0 -112
  58. data/app/javascript/blacklight_range_limit/range_limit_slider.js +0 -163
  59. data/app/javascripts/blacklight_range_limit/index.js +0 -13
  60. data/app/views/blacklight_range_limit/_range_segments.html.erb +0 -8
  61. data/app/views/blacklight_range_limit/range_segments.html.erb +0 -1
  62. data/app/views/catalog/range_limit_panel.html.erb +0 -1
  63. data/rollup.config.js +0 -37
  64. data/spec/features/a_javascript_spec.rb +0 -70
  65. data/spec/helpers/blacklight_range_limit_helper_spec.rb +0 -37
  66. data/vendor/assets/javascripts/bootstrap-slider.js +0 -388
  67. data/vendor/assets/javascripts/flot/jquery.canvaswrapper.js +0 -549
  68. data/vendor/assets/javascripts/flot/jquery.colorhelpers.js +0 -199
  69. data/vendor/assets/javascripts/flot/jquery.event.drag.js +0 -145
  70. data/vendor/assets/javascripts/flot/jquery.flot.browser.js +0 -98
  71. data/vendor/assets/javascripts/flot/jquery.flot.drawSeries.js +0 -662
  72. data/vendor/assets/javascripts/flot/jquery.flot.hover.js +0 -359
  73. data/vendor/assets/javascripts/flot/jquery.flot.js +0 -2818
  74. data/vendor/assets/javascripts/flot/jquery.flot.saturated.js +0 -43
  75. data/vendor/assets/javascripts/flot/jquery.flot.selection.js +0 -527
  76. data/vendor/assets/javascripts/flot/jquery.flot.uiConstants.js +0 -10
  77. data/vendor/assets/stylesheets/slider.css +0 -138
data/package-lock.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "blacklight-range-limit",
3
- "version": "8.3.0",
3
+ "version": "8.5.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "blacklight-range-limit",
9
- "version": "8.3.0",
9
+ "version": "8.5.0",
10
10
  "license": "Apache-2.0",
11
11
  "devDependencies": {
12
- "rollup": "^2.60.0",
12
+ "rollup": "^3.29.5",
13
13
  "rollup-plugin-includepaths": "^0.2.4"
14
14
  }
15
15
  },
@@ -26,15 +26,16 @@
26
26
  }
27
27
  },
28
28
  "node_modules/rollup": {
29
- "version": "2.79.1",
30
- "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.1.tgz",
31
- "integrity": "sha512-uKxbd0IhMZOhjAiD5oAFp7BqvkA4Dv47qpOCtaNvng4HBwdbWtdOh8f5nZNuk2rp51PMGk3bzfWu5oayNEuYnw==",
29
+ "version": "3.29.5",
30
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.29.5.tgz",
31
+ "integrity": "sha512-GVsDdsbJzzy4S/v3dqWPJ7EfvZJfCHiDqe80IyrF59LYuP+e6U1LJoUqeuqRbwAWoMNoXivMNeNAOf5E22VA1w==",
32
32
  "dev": true,
33
33
  "bin": {
34
34
  "rollup": "dist/bin/rollup"
35
35
  },
36
36
  "engines": {
37
- "node": ">=10.0.0"
37
+ "node": ">=14.18.0",
38
+ "npm": ">=8.0.0"
38
39
  },
39
40
  "optionalDependencies": {
40
41
  "fsevents": "~2.3.2"
data/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "blacklight-range-limit",
3
- "version": "8.5.0",
3
+ "version": "9.0.0-beta2",
4
4
  "description": "A range facet UI component plugin for blacklight",
5
- "main": "app/assets/javascripts/blacklight_range_limit",
6
5
  "type": "module",
7
- "scripts": {
8
- "prepare": "rollup --config rollup.config.js --sourcemap && ESM=true rollup --config rollup.config.js --sourcemap"
9
- },
6
+
7
+ "exports": {
8
+ ".": "./app/assets/javascripts/blacklight-range-limit/index.js",
9
+ "./*": "./app/assets/javascripts/blacklight-range-limit/*"
10
+ },
11
+
10
12
  "repository": {
11
13
  "type": "git",
12
14
  "url": "git+https://github.com/projectblacklight/blacklight_range_limit.git"
13
15
  },
14
16
  "files": [
15
- "app/assets",
16
- "vendor/assets"
17
+ "app/assets/javascripts/blacklight-range-limit/"
17
18
  ],
18
19
  "author": "",
19
20
  "license": "Apache-2.0",
@@ -21,12 +22,7 @@
21
22
  "url": "https://github.com/projectblacklight/blacklight_range_limit/issues"
22
23
  },
23
24
  "homepage": "https://github.com/projectblacklight/blacklight_range_limit#readme",
24
- "browserslist": [
25
- "defaults",
26
- "not IE 11"
27
- ],
28
- "devDependencies": {
29
- "rollup": "^2.60.0",
30
- "rollup-plugin-includepaths": "^0.2.4"
25
+ "dependencies": {
26
+ "chart.js": "^ 4.4.1"
31
27
  }
32
28
  }
@@ -26,7 +26,7 @@ RSpec.describe BlacklightRangeLimit::RangeFacetComponent, type: :component do
26
26
  min: nil,
27
27
  max: nil,
28
28
  search_state: Blacklight::SearchState.new({}, nil),
29
- range_config: {},
29
+ range_config: BlacklightRangeLimit.default_range_config[:range_config],
30
30
  modal_path: nil,
31
31
  facet_field: facet_config,
32
32
  **facet_field_params,
@@ -45,15 +45,6 @@ RSpec.describe BlacklightRangeLimit::RangeFacetComponent, type: :component do
45
45
  allow(component).to receive(:search_facet_path).and_return('/range/key')
46
46
  end
47
47
 
48
- it 'renders into the default facet layout' do
49
- expect(rendered).to have_selector('h3', text: 'My facet field')
50
- .and have_selector('div.collapse')
51
- end
52
-
53
- it 'renders a placeholder profile area' do
54
- expect(rendered).to have_selector('div.profile', text: '')
55
- end
56
-
57
48
  context 'with range data' do
58
49
  let(:facet_field_params) do
59
50
  {
@@ -66,33 +57,26 @@ RSpec.describe BlacklightRangeLimit::RangeFacetComponent, type: :component do
66
57
  }
67
58
  end
68
59
 
69
- it 'renders the range data into the profile' do
70
- expect(rendered).to have_selector('.profile li', count: 2)
71
- .and have_selector('.profile li', text: '100 to 199')
72
- .and have_selector('.profile li', text: '200 to 300')
60
+ it 'renders into the default facet layout' do
61
+ expect(rendered).to have_selector('h3', text: 'My facet field')
62
+ .and have_selector('div.collapse')
73
63
  end
74
- end
75
-
76
- it 'renders a form for the range' do
77
- expect(rendered).to have_selector('form[action="http://test.host/catalog"][method="get"]')
78
- .and have_field('range[key][begin]')
79
- .and have_field('range[key][end]')
80
- end
81
-
82
- it 'renders a link to the modal' do
83
- expect(rendered).to have_link 'View larger', href: '/range/key'
84
- end
85
64
 
86
- context 'within a modal' do
87
- let(:facet_field_params) { { in_modal?: true } }
65
+ it 'renders the range data into the profile' do
66
+ expect(rendered).to have_selector('.distribution li', count: 2)
67
+ .and have_selector('.distribution li', text: '100 to 199')
68
+ .and have_selector('.distribution li', text: '200 to 300')
69
+ end
88
70
 
89
- it 'does not link to the modal' do
90
- expect(rendered).not_to have_link 'View larger'
71
+ it 'renders a form for the range' do
72
+ expect(rendered).to have_selector('form[action="http://test.host/catalog"][method="get"]')
73
+ .and have_field('range[key][begin]')
74
+ .and have_field('range[key][end]')
91
75
  end
92
- end
93
76
 
94
- it 'does not render the missing link if there are no matching documents' do
95
- expect(rendered).not_to have_link '[Missing]'
77
+ it 'does not render the missing link if there are no matching documents' do
78
+ expect(rendered).not_to have_link '[Missing]'
79
+ end
96
80
  end
97
81
 
98
82
  context 'with missing documents' do
@@ -109,4 +93,89 @@ RSpec.describe BlacklightRangeLimit::RangeFacetComponent, type: :component do
109
93
  expect(rendered).to have_link '[Missing]', href: expected_facet_query_param
110
94
  end
111
95
  end
96
+
97
+ context 'with min/max but no range segments' do
98
+ let(:facet_field_params) do
99
+ {
100
+ range_queries: [],
101
+ min: 100,
102
+ max: 300
103
+ }
104
+ end
105
+
106
+ it "renders a link to fetch distribution info" do
107
+ # need request_url for routing of links generated
108
+ with_request_url '/catalog' do
109
+ load_link = rendered.find(".distribution a.load_distribution[href]")
110
+ expect(load_link).to be_present
111
+
112
+ expect(load_link["href"]).to be_present
113
+ params = Rack::Utils.parse_nested_query(load_link["href"].split("?").try(:last))
114
+ expect(params["range_field"]).to eq facet_field.key
115
+ expect(params["range_start"]).to eq facet_field_params[:min].to_s
116
+ expect(params["range_end"]).to eq facet_field_params[:max].to_s
117
+ end
118
+ end
119
+ end
120
+
121
+ context 'with open-ended query' do
122
+ let(:selected_max) { 200 }
123
+ let(:data_max) { 300 }
124
+
125
+ let(:facet_field) do
126
+ instance_double(
127
+ BlacklightRangeLimit::FacetFieldPresenter,
128
+ key: 'key',
129
+ active?: false,
130
+ collapsed?: false,
131
+ in_modal?: false,
132
+ label: 'My facet field',
133
+ selected_range: nil,
134
+ selected_range_facet_item: Blacklight::Solr::Response::Facets::FacetItem.new(..selected_max),
135
+ missing_facet_item: nil,
136
+ missing_selected?: false,
137
+ min: nil,
138
+ max: nil,
139
+ search_state: Blacklight::SearchState.new({}, nil),
140
+ range_config: BlacklightRangeLimit.default_range_config[:range_config],
141
+ modal_path: nil,
142
+ facet_field: facet_config,
143
+ **facet_field_params,
144
+ **extra_facet_field_params
145
+ )
146
+ end
147
+
148
+ let(:facet_field_params) do
149
+ {
150
+ range_queries: [],
151
+ min: 100,
152
+ max: data_max
153
+ }
154
+ end
155
+
156
+ # This can be relevant in multi-valued queries, where even though you limited to
157
+ # < 200, some items in search can ALSO have additional values greater than 200, but
158
+ # we don't want to include them in our range buckets.
159
+ it "renders fetch distribution with expressed boundaries taking priority" do
160
+ # need request_url for routing of links generated
161
+ with_request_url '/catalog' do
162
+ load_link = rendered.find(".distribution a.load_distribution[href]")
163
+ expect(load_link).to be_present
164
+
165
+ expect(load_link["href"]).to be_present
166
+ params = Rack::Utils.parse_nested_query(load_link["href"].split("?").try(:last))
167
+ expect(params["range_field"]).to eq facet_field.key
168
+ expect(params["range_start"]).to eq facet_field_params[:min].to_s
169
+ expect(params["range_end"]).to eq selected_max.to_s
170
+ end
171
+ end
172
+ end
173
+
174
+ context 'with no data to display (e.g., no results page)' do
175
+ let(:facet_field_params) { { min: nil, max: nil, missing_facet_item: nil } }
176
+
177
+ it 'does not render the range limit facet' do
178
+ expect(component.render?).to be false
179
+ end
180
+ end
112
181
  end
@@ -62,13 +62,13 @@ RSpec.describe BlacklightRangeLimit::RangeFormComponent, type: :component do
62
62
  context 'with range data' do
63
63
  let(:selected_range) { (100..300) }
64
64
  let(:search_params) do
65
- {
65
+ {
66
66
  another_field: 'another_value',
67
67
  range: {
68
68
  another_range: { begin: 128, end: 1024 },
69
69
  key: { begin: selected_range.first, end: selected_range.last }
70
70
  }
71
- }
71
+ }
72
72
  end
73
73
 
74
74
  it 'renders a form for the selected range' do
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe BlacklightRangeLimit::RangeSegmentsComponent, type: :component do
4
+ subject(:component) do
5
+ described_class.new(facet_field: facet_field)
6
+ end
7
+
8
+ let(:raw_rendered) { render_inline(component) }
9
+
10
+ let(:rendered) do
11
+ Capybara::Node::Simple.new(raw_rendered)
12
+ end
13
+
14
+ let(:facet_field) do
15
+ instance_double(
16
+ BlacklightRangeLimit::FacetFieldPresenter,
17
+ key: 'key',
18
+ active?: false,
19
+ collapsed?: false,
20
+ in_modal?: false,
21
+ label: 'My facet field',
22
+ selected_range: nil,
23
+ selected_range_facet_item: nil,
24
+ missing_facet_item: nil,
25
+ missing_selected?: false,
26
+ search_state: Blacklight::SearchState.new({}, nil),
27
+ range_config: {},
28
+ modal_path: nil,
29
+ facet_field: facet_config,
30
+ **extra_facet_field_params
31
+ )
32
+ end
33
+
34
+ let(:facet_config) do
35
+ Blacklight::Configuration::FacetField.new(key: 'key', item_presenter: BlacklightRangeLimit::FacetItemPresenter)
36
+ end
37
+
38
+
39
+ let(:extra_facet_field_params) do
40
+ {
41
+ range_queries: [
42
+ OpenStruct.new(value: 100..199, hits: 5),
43
+ OpenStruct.new(value: 200..300, hits: 3)
44
+ ],
45
+ min: 100,
46
+ max: 300,
47
+ }
48
+ end
49
+
50
+ # This is JS api and should ideally not be changed without major version
51
+ it "renders list with expected data attributes for JS" do
52
+ # <span class="from" data-blrl-begin="%{begin_value}">%{begin}</span> to <span class="to" data-blrl-end="%{end_value}">%{end}</span>'
53
+ list_items = rendered.all("ul.facet-values li")
54
+ expect(list_items.count).to eq 2
55
+
56
+ expect(list_items.first).to have_selector("span.from[data-blrl-begin=100]")
57
+ expect(list_items.first).to have_selector("span.to[data-blrl-end=199]")
58
+ expect(list_items.first).to have_selector("span.facet-count", text: 5)
59
+
60
+ expect(list_items[1]).to have_selector("span.from[data-blrl-begin=200]")
61
+ expect(list_items[1]).to have_selector("span.to[data-blrl-end=300]")
62
+ expect(list_items[1]).to have_selector("span.facet-count", text: 3)
63
+ end
64
+ end
@@ -6,8 +6,8 @@ describe "Blacklight Range Limit" do
6
6
  visit search_catalog_path
7
7
  expect(page).to have_selector 'input.range_begin'
8
8
  expect(page).to have_selector 'input.range_end'
9
- expect(page).to have_selector 'label.sr-only[for="range_pub_date_si_begin"]', :text => 'Publication Date Sort range begin'
10
- expect(page).to have_selector 'label.sr-only[for="range_pub_date_si_end"]', :text => 'Publication Date Sort range end'
9
+ expect(page).to have_selector 'label[for="range_pub_date_si_begin"]', :text => I18n.t("blacklight.range_limit.range_begin_short")
10
+ expect(page).to have_selector 'label[for="range_pub_date_si_end"]', :text => I18n.t("blacklight.range_limit.range_end_short")
11
11
  expect(page).to have_button 'Apply'
12
12
  end
13
13
 
@@ -26,7 +26,9 @@ describe "Blacklight Range Limit" do
26
26
  click_link '2000 to 2008'
27
27
 
28
28
  within '.blacklight-pub_date_si' do
29
- expect(page).to have_content "2000 to 2008✖[remove]12"
29
+ # depending on version of chrome driver, the 'x' may or may not show up
30
+ # here before [remove]
31
+ expect(page).to have_content /2000 to 2008.\[remove\]12/
30
32
  end
31
33
 
32
34
  within '.constraints-container' do
@@ -63,27 +65,33 @@ describe "Blacklight Range Limit" do
63
65
  expect(page).to_not have_content 'Publication Date Sort'
64
66
  end
65
67
  end
68
+
69
+ context 'when on a zero results found page' do
70
+ it 'should not render the range limit facet' do
71
+ visit search_catalog_path(q: 'asdfasdfasdf')
72
+ expect(page).to_not have_selector '#facets .facet-limit.blacklight-pub_date_si'
73
+ expect(page).to_not have_selector 'input#range_pub_date_si_begin'
74
+ expect(page).to_not have_selector 'input#range_pub_date_si_end'
75
+ end
76
+ end
66
77
  end
67
78
 
68
79
  describe "Blacklight Range Limit with configured input labels" do
69
80
  before do
70
81
  CatalogController.blacklight_config = Blacklight::Configuration.new
71
82
  CatalogController.configure_blacklight do |config|
72
- config.add_facet_field 'pub_date_si', **CatalogController.default_range_config, range_config: {
73
- input_label_range_begin: 'from publication date',
74
- input_label_range_end: 'to publication date',
75
- maxlength: 6
76
- }
83
+ config.add_facet_field 'pub_date_si', range: true
77
84
  config.default_solr_params[:'facet.field'] = config.facet_fields.keys
78
85
  end
79
86
  end
80
87
 
81
- it "should show the range limit facet with configured labels and maxlength" do
88
+ it "should show the range limit facet with configured labels" do
82
89
  visit '/catalog'
83
- expect(page).to have_selector 'label.sr-only[for="range_pub_date_si_begin"]', :text => 'from publication date'
84
- expect(page).to have_selector 'label.sr-only[for="range_pub_date_si_end"]', :text => 'to publication date'
85
- expect(page).to have_selector 'input#range_pub_date_si_begin[maxlength="6"]'
86
- expect(page).to have_selector 'input#range_pub_date_si_end[maxlength="6"]'
90
+ expect(page).to have_selector 'label[for="range_pub_date_si_begin"]', :text => I18n.t("blacklight.range_limit.range_begin_short")
91
+ expect(page).to have_selector 'label[for="range_pub_date_si_end"]', :text => I18n.t("blacklight.range_limit.range_end_short")
92
+
93
+ expect(page).to have_selector 'input#range_pub_date_si_begin'
94
+ expect(page).to have_selector 'input#range_pub_date_si_end'
87
95
  end
88
96
 
89
97
  end
@@ -0,0 +1,210 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe 'Run through with javascript', js: true do
6
+ # hacky way to inject browser logs into failure message for failed ones
7
+ after(:each) do |example|
8
+ if example.exception
9
+ browser_logs = page.driver.browser.logs.get(:browser).collect { |log| "#{log.level}: #{log.message}" }
10
+
11
+ if browser_logs.present?
12
+ # pretty hacky internal way to get browser logs into long-form failure message
13
+ new_exception = example.exception.class.new("#{example.exception.message}\n\nBrowser console:\n\n#{browser_logs.join("\n")}\n")
14
+ new_exception.set_backtrace(example.exception.backtrace)
15
+
16
+ example.display_exception = new_exception
17
+ end
18
+ end
19
+ end
20
+
21
+
22
+ let(:start_range) { "1900"}
23
+ let(:end_range) { "2100" }
24
+
25
+ # capybara tests are slow to setiup, we do a single basic happy path script
26
+ # in one test. We can only check for placement of "canvas"
27
+ # element, not really what's in it.
28
+ it "basically works" do
29
+ visit search_catalog_path
30
+
31
+ click_button 'Publication Date Sort'
32
+
33
+ within ".facet-limit.blacklight-pub_date_si" do
34
+ expect(page).to have_css('canvas')
35
+
36
+ # min/max in actual results are filled in inputs
37
+ expect(find("input#range_pub_date_si_begin").value).to be_present
38
+ expect(find("input#range_pub_date_si_end").value).to be_present
39
+
40
+ # expect expandable limits
41
+ find("summary", text: "Range List").click
42
+ expect(page).to have_css("details ul.facet-values li")
43
+
44
+ # expect "missing" facet
45
+ within 'ul.missing' do
46
+ expect(page).to have_link '[Missing]'
47
+ end
48
+
49
+ # fill in some limits and submit
50
+ find("input#range_pub_date_si_begin").set(start_range)
51
+ find("input#range_pub_date_si_end").set(end_range)
52
+
53
+ click_button "Apply limit"
54
+ end
55
+
56
+ # new page with limit
57
+ expect(page).to have_css(".applied-filter", text: /Publication Date Sort.*#{start_range} to #{end_range}/)
58
+
59
+ within ".facet-limit.blacklight-pub_date_si" do
60
+ expect(page).to have_css 'canvas'
61
+
62
+ # min/max from specified range
63
+ expect(find("input#range_pub_date_si_begin").value).to eq start_range
64
+ expect(find("input#range_pub_date_si_end").value).to eq end_range
65
+
66
+ # expect expandable limits
67
+ find("summary", text: "Range List").click
68
+ expect(page).to have_css("details ul.facet-values li")
69
+ end
70
+ end
71
+
72
+ context "for single dates" do
73
+ it "does not show chart or facet list" do
74
+ visit search_catalog_path
75
+
76
+ click_button 'Publication Date Sort'
77
+ last_date = nil
78
+ within ".facet-limit.blacklight-pub_date_si" do
79
+ last_date = find("input#range_pub_date_si_begin").value
80
+
81
+ find("input#range_pub_date_si_begin").set(last_date)
82
+ find("input#range_pub_date_si_end").set(last_date)
83
+ click_button "Apply limit"
84
+ end
85
+
86
+ expect(page).to have_css(".applied-filter", text: /Publication Date Sort.*#{last_date}/)
87
+ within ".facet-limit.blacklight-pub_date_si" do
88
+ expect(page).not_to have_css 'canvas'
89
+ expect(page).not_to have_css 'details'
90
+ end
91
+ end
92
+ end
93
+
94
+ context "open-ended range" do
95
+ it "can search" do
96
+ visit search_catalog_path
97
+
98
+ click_button 'Publication Date Sort'
99
+
100
+ within ".facet-limit.blacklight-pub_date_si" do
101
+ find("input#range_pub_date_si_begin").set("")
102
+ find("input#range_pub_date_si_end").set(end_range)
103
+ click_button "Apply limit"
104
+ end
105
+
106
+ expect(page).to have_css(".applied-filter", text: /Publication Date Sort +to #{end_range}/)
107
+ expect(page).not_to have_text("No entries found")
108
+ expect(page).to have_css(".document")
109
+
110
+ within ".facet-limit.blacklight-pub_date_si" do
111
+ # expect expandable limits
112
+ find("summary", text: "Range List").click
113
+ expect(page).to have_css("details ul.facet-values li")
114
+ end
115
+ end
116
+ end
117
+
118
+ context "submitted with empty boundaries" do
119
+ it "does not apply filter" do
120
+ visit search_catalog_path
121
+
122
+ click_button 'Publication Date Sort'
123
+
124
+ within ".facet-limit.blacklight-pub_date_si" do
125
+ find("input#range_pub_date_si_begin").set("")
126
+ find("input#range_pub_date_si_end").set("")
127
+ click_button "Apply limit"
128
+ end
129
+ expect(page).not_to have_css(".applied-filter")
130
+
131
+ click_button 'Publication Date Sort'
132
+ within ".facet-limit.blacklight-pub_date_si" do
133
+ expect(page).not_to have_css(".selected")
134
+ end
135
+ end
136
+ end
137
+
138
+ context 'when assumed boundaries configured' do
139
+ around do |example|
140
+ original = CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config
141
+ CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = original.merge({
142
+ :assumed_boundaries=>1900...2100,
143
+ })
144
+
145
+ example.run
146
+
147
+ CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = original
148
+ end
149
+
150
+ it 'should show the range limit with set boundaries' do
151
+ visit '/catalog'
152
+
153
+ click_button 'Publication Date Sort'
154
+ expect(find("input#range_pub_date_si_begin").value).to be_present
155
+ expect(find("input#range_pub_date_si_end").value).to be_present
156
+ end
157
+ end
158
+
159
+ context 'when missing facet item is configured not to show' do
160
+ around do |example|
161
+ original = CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config
162
+ CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = original.merge({
163
+ show_missing_link: false
164
+ })
165
+
166
+ example.run
167
+
168
+ CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = original
169
+ end
170
+
171
+ it 'should not show the missing facet item' do
172
+ visit search_catalog_path
173
+
174
+ within ".facet-limit.blacklight-pub_date_si" do
175
+ expect(page).not_to have_css("ul.missing")
176
+ end
177
+ end
178
+ end
179
+
180
+ context "Range Limit text facets" do
181
+ # Make sure it works with strict permitted params
182
+ around do |example|
183
+ original = ActionController::Parameters.action_on_unpermitted_parameters
184
+ ActionController::Parameters.action_on_unpermitted_parameters = :raise
185
+
186
+ example.run
187
+
188
+ ActionController::Parameters.action_on_unpermitted_parameters = original
189
+ end
190
+
191
+ it "work with strict permitted params" do
192
+ visit search_catalog_path
193
+
194
+ click_button 'Publication Date Sort'
195
+
196
+ from_val, to_val = nil, nil
197
+ within ".facet-limit.blacklight-pub_date_si" do
198
+ find("summary", text: "Range List").click
199
+
200
+ facet_link = first(".facet-values li a")
201
+ from_val = facet_link.find("span[data-blrl-begin]")["data-blrl-begin"]
202
+ to_val = facet_link.find("span[data-blrl-end]")["data-blrl-end"]
203
+
204
+ facet_link.click
205
+ end
206
+
207
+ expect(page).to have_css(".applied-filter", text: /Publication Date Sort.*#{from_val} to #{to_val}/)
208
+ end
209
+ end
210
+ end
@@ -141,4 +141,76 @@ RSpec.describe BlacklightRangeLimit::FacetFieldPresenter, type: :presenter do
141
141
  end
142
142
  end
143
143
  end
144
+
145
+ describe '#selected_range_facet_item' do
146
+ before do
147
+ allow(presenter).to receive(:selected_range).and_return(1990..1999)
148
+ end
149
+
150
+ context 'when the response is not a grouped response' do
151
+ let(:response) do
152
+ Blacklight::Solr::Response.new(
153
+ {
154
+ response: { numFound: 501 }
155
+ },
156
+ nil
157
+ )
158
+ end
159
+
160
+ it 'returns the facet item with the correct value and hits' do
161
+ expected_facet_item = Blacklight::Solr::Response::Facets::FacetItem.new(value: 1990..1999, hits: 501)
162
+ expect(presenter.selected_range_facet_item).to eq expected_facet_item
163
+ end
164
+ end
165
+
166
+ context 'when the response is a grouped response with one group' do
167
+ let(:response) do
168
+ Blacklight::Solr::Response.new(
169
+ {
170
+ grouped: {
171
+ _root_: {
172
+ matches: 123
173
+ }
174
+ }
175
+ },
176
+ nil
177
+ )
178
+ end
179
+
180
+ it 'returns the facet item with the hits from the group' do
181
+ expected_facet_item = Blacklight::Solr::Response::Facets::FacetItem.new(value: 1990..1999, hits: 123)
182
+ expect(presenter.selected_range_facet_item).to eq expected_facet_item
183
+ end
184
+ end
185
+
186
+ context 'when the response is a grouped response with multiple groups' do
187
+ let(:response) do
188
+ Blacklight::Solr::Response.new(
189
+ {
190
+ grouped: {
191
+ field_one_ssi: {
192
+ matches: 123
193
+ },
194
+ field_two_ssi: {
195
+ matches: 456
196
+ }
197
+ }
198
+ },
199
+ nil
200
+ )
201
+ end
202
+
203
+ let(:blacklight_config) do
204
+ Blacklight::Configuration.new.tap do |config|
205
+ config.facet_fields['field_key'] = facet_field
206
+ config.index.group = 'field_two_ssi'
207
+ end
208
+ end
209
+
210
+ it 'returns the facet item with the hits from the configured group' do
211
+ expected_facet_item = Blacklight::Solr::Response::Facets::FacetItem.new(value: 1990..1999, hits: 456)
212
+ expect(presenter.selected_range_facet_item).to eq expected_facet_item
213
+ end
214
+ end
215
+ end
144
216
  end