blacklight_range_limit 8.4.0 → 9.0.0.beta1
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/.github/workflows/ruby.yml +117 -23
- data/.gitignore +2 -0
- data/.solr_wrapper.yml +8 -0
- data/Gemfile +7 -1
- data/README.md +77 -86
- data/Rakefile +31 -0
- data/VERSION +1 -1
- data/app/assets/javascripts/blacklight-range-limit/index.js +345 -0
- data/app/components/blacklight_range_limit/range_facet_component.html.erb +29 -27
- data/app/components/blacklight_range_limit/range_facet_component.rb +15 -9
- data/app/components/blacklight_range_limit/range_form_component.html.erb +13 -5
- data/app/components/blacklight_range_limit/range_form_component.rb +8 -20
- data/app/presenters/blacklight_range_limit/facet_field_presenter.rb +13 -2
- data/app/presenters/blacklight_range_limit/facet_item_presenter.rb +6 -11
- data/app/presenters/blacklight_range_limit/filter_field.rb +2 -2
- data/blacklight_range_limit.gemspec +1 -1
- data/config/importmap.rb +9 -0
- data/config/locales/blacklight_range_limit.ar.yml +13 -8
- data/config/locales/blacklight_range_limit.de.yml +13 -8
- data/config/locales/blacklight_range_limit.en.yml +5 -1
- data/config/locales/blacklight_range_limit.es.yml +18 -0
- data/config/locales/blacklight_range_limit.it.yml +13 -8
- data/lib/blacklight_range_limit/controller_override.rb +1 -25
- data/lib/blacklight_range_limit/engine.rb +48 -0
- data/lib/blacklight_range_limit/range_limit_builder.rb +40 -3
- data/lib/blacklight_range_limit.rb +8 -31
- data/lib/generators/blacklight_range_limit/assets_generator.rb +82 -18
- data/lib/generators/blacklight_range_limit/install_generator.rb +1 -1
- data/lib/generators/blacklight_range_limit/jsbundling_bl7_fixup_generator.rb +98 -0
- data/package-lock.json +51 -0
- data/package.json +10 -11
- data/spec/components/range_facet_component_spec.rb +41 -32
- data/spec/components/range_form_component_spec.rb +2 -2
- data/spec/components/range_segments_component_spec.rb +64 -0
- data/spec/features/blacklight_range_limit_spec.rb +21 -13
- data/spec/features/run_through_spec.rb +157 -0
- data/spec/presenters/facet_field_presenter_spec.rb +72 -0
- data/spec/presenters/filter_field_spec.rb +36 -1
- data/spec/spec_helper.rb +10 -0
- data/spec/test_app_templates/Gemfile.extra +11 -1
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +37 -6
- metadata +26 -44
- data/app/assets/javascripts/blacklight_range_limit/range_limit_distro_facets.js +0 -77
- data/app/assets/javascripts/blacklight_range_limit/range_limit_plotting.js +0 -185
- data/app/assets/javascripts/blacklight_range_limit/range_limit_shared.js +0 -73
- data/app/assets/javascripts/blacklight_range_limit/range_limit_slider.js +0 -161
- data/app/assets/javascripts/blacklight_range_limit.js +0 -25
- data/app/assets/stylesheets/blacklight_range_limit/blacklight_range_limit.css +0 -60
- data/app/assets/stylesheets/blacklight_range_limit.css +0 -7
- data/app/helpers/range_limit_helper.rb +0 -130
- data/app/views/blacklight_range_limit/_range_segments.html.erb +0 -8
- data/app/views/blacklight_range_limit/range_segments.html.erb +0 -1
- data/app/views/catalog/range_limit_panel.html.erb +0 -1
- data/spec/features/a_javascript_spec.rb +0 -70
- data/spec/helpers/blacklight_range_limit_helper_spec.rb +0 -37
- data/vendor/assets/javascripts/bootstrap-slider.js +0 -388
- data/vendor/assets/javascripts/flot/jquery.canvaswrapper.js +0 -549
- data/vendor/assets/javascripts/flot/jquery.colorhelpers.js +0 -199
- data/vendor/assets/javascripts/flot/jquery.event.drag.js +0 -145
- data/vendor/assets/javascripts/flot/jquery.flot.browser.js +0 -98
- data/vendor/assets/javascripts/flot/jquery.flot.drawSeries.js +0 -662
- data/vendor/assets/javascripts/flot/jquery.flot.hover.js +0 -359
- data/vendor/assets/javascripts/flot/jquery.flot.js +0 -2818
- data/vendor/assets/javascripts/flot/jquery.flot.saturated.js +0 -43
- data/vendor/assets/javascripts/flot/jquery.flot.selection.js +0 -527
- data/vendor/assets/javascripts/flot/jquery.flot.uiConstants.js +0 -10
- data/vendor/assets/stylesheets/slider.css +0 -138
    
        data/package.json
    CHANGED
    
    | @@ -1,16 +1,20 @@ | |
| 1 1 | 
             
            {
         | 
| 2 2 | 
             
              "name": "blacklight-range-limit",
         | 
| 3 | 
            -
              "version": " | 
| 3 | 
            +
              "version": "9.0.0.beta1",
         | 
| 4 4 | 
             
              "description": "A range facet UI component plugin for blacklight",
         | 
| 5 | 
            -
              " | 
| 6 | 
            -
             | 
| 7 | 
            -
               | 
| 5 | 
            +
              "type": "module",
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              "exports": {
         | 
| 8 | 
            +
                ".": "./app/assets/javascripts/blacklight-range-limit/index.js",
         | 
| 9 | 
            +
                "./*": "./app/assets/javascripts/blacklight-range-limit/*"
         | 
| 10 | 
            +
               },
         | 
| 11 | 
            +
             | 
| 8 12 | 
             
              "repository": {
         | 
| 9 13 | 
             
                "type": "git",
         | 
| 10 14 | 
             
                "url": "git+https://github.com/projectblacklight/blacklight_range_limit.git"
         | 
| 11 15 | 
             
              },
         | 
| 12 16 | 
             
              "files": [
         | 
| 13 | 
            -
                "app/assets | 
| 17 | 
            +
                "app/assets/javascripts/blacklight-range-limit/"
         | 
| 14 18 | 
             
              ],
         | 
| 15 19 | 
             
              "author": "",
         | 
| 16 20 | 
             
              "license": "Apache-2.0",
         | 
| @@ -18,12 +22,7 @@ | |
| 18 22 | 
             
                "url": "https://github.com/projectblacklight/blacklight_range_limit/issues"
         | 
| 19 23 | 
             
              },
         | 
| 20 24 | 
             
              "homepage": "https://github.com/projectblacklight/blacklight_range_limit#readme",
         | 
| 21 | 
            -
              "devDependencies": {
         | 
| 22 | 
            -
              },
         | 
| 23 | 
            -
              "browserslist": [
         | 
| 24 | 
            -
                "defaults",
         | 
| 25 | 
            -
                "not IE 11"
         | 
| 26 | 
            -
              ],
         | 
| 27 25 | 
             
              "dependencies": {
         | 
| 26 | 
            +
                "chart.js": "^ 4.4.1"
         | 
| 28 27 | 
             
              }
         | 
| 29 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  | 
| 70 | 
            -
                  expect(rendered).to have_selector(' | 
| 71 | 
            -
                    .and have_selector('. | 
| 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 | 
            -
             | 
| 87 | 
            -
             | 
| 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 ' | 
| 90 | 
            -
                  expect(rendered). | 
| 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 | 
            -
             | 
| 95 | 
            -
             | 
| 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,29 @@ 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 | 
            +
                    expect(rendered).to have_selector(".distribution a.load_distribution[href]")
         | 
| 110 | 
            +
                  end
         | 
| 111 | 
            +
                end
         | 
| 112 | 
            +
              end
         | 
| 113 | 
            +
             | 
| 114 | 
            +
              context 'with no data to display (e.g., no results page)' do
         | 
| 115 | 
            +
                let(:facet_field_params) { { min: nil, max: nil, missing_facet_item: nil } }
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                it 'does not render the range limit facet' do
         | 
| 118 | 
            +
                  expect(component.render?).to be false
         | 
| 119 | 
            +
                end
         | 
| 120 | 
            +
              end
         | 
| 112 121 | 
             
            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 | 
| 10 | 
            -
                expect(page).to have_selector 'label | 
| 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 | 
            -
                   | 
| 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',  | 
| 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 | 
| 88 | 
            +
              it "should show the range limit facet with configured labels" do
         | 
| 82 89 | 
             
                visit '/catalog'
         | 
| 83 | 
            -
                expect(page).to have_selector 'label | 
| 84 | 
            -
                expect(page).to have_selector 'label | 
| 85 | 
            -
             | 
| 86 | 
            -
                expect(page).to have_selector 'input# | 
| 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,157 @@ | |
| 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 | 
            +
                before do
         | 
| 140 | 
            +
                  CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = {
         | 
| 141 | 
            +
                    assumed_boundaries: start_range.to_i...end_range.to_i
         | 
| 142 | 
            +
                  }
         | 
| 143 | 
            +
                end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                after do
         | 
| 146 | 
            +
                  CatalogController.blacklight_config.facet_fields['pub_date_si'].range_config = {}
         | 
| 147 | 
            +
                end
         | 
| 148 | 
            +
             | 
| 149 | 
            +
                it 'should show the range limit with set boundaries' do
         | 
| 150 | 
            +
                  visit '/catalog'
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                  click_button 'Publication Date Sort'
         | 
| 153 | 
            +
                  expect(find("input#range_pub_date_si_begin").value).to be_present
         | 
| 154 | 
            +
                  expect(find("input#range_pub_date_si_end").value).to be_present
         | 
| 155 | 
            +
                end
         | 
| 156 | 
            +
              end
         | 
| 157 | 
            +
            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
         | 
| @@ -19,9 +19,18 @@ RSpec.describe BlacklightRangeLimit::FilterField do | |
| 19 19 | 
             
              describe '#add' do
         | 
| 20 20 | 
             
                it 'adds a new range parameter' do
         | 
| 21 21 | 
             
                  new_state = filter.add(1999..2099)
         | 
| 22 | 
            -
             | 
| 23 22 | 
             
                  expect(new_state.params.dig(:range, 'some_field')).to include begin: 1999, end: 2099
         | 
| 24 23 | 
             
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                it "adds end-less range" do
         | 
| 26 | 
            +
                  new_state = filter.add(1999..nil)
         | 
| 27 | 
            +
                  expect(new_state.params.dig(:range, 'some_field')).to include begin: 1999, end: nil
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                it "adds begin-less range" do
         | 
| 31 | 
            +
                  new_state = filter.add(nil..2099)
         | 
| 32 | 
            +
                  expect(new_state.params.dig(:range, 'some_field')).to include begin: nil, end: 2099
         | 
| 33 | 
            +
                end
         | 
| 25 34 | 
             
              end
         | 
| 26 35 |  | 
| 27 36 | 
             
              context 'with some existing data' do
         | 
| @@ -32,6 +41,12 @@ RSpec.describe BlacklightRangeLimit::FilterField do | |
| 32 41 | 
             
                    new_state = filter.add(1999..2099)
         | 
| 33 42 |  | 
| 34 43 | 
             
                    expect(new_state.params.dig(:range, 'some_field')).to include begin: 1999, end: 2099
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                    new_state = filter.add(1999..nil)
         | 
| 46 | 
            +
                    expect(new_state.params.dig(:range, 'some_field')).to include begin: 1999, end: nil
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                    new_state = filter.add(nil..2099)
         | 
| 49 | 
            +
                    expect(new_state.params.dig(:range, 'some_field')).to include begin: nil, end: 2099
         | 
| 35 50 | 
             
                  end
         | 
| 36 51 | 
             
                end
         | 
| 37 52 |  | 
| @@ -66,6 +81,26 @@ RSpec.describe BlacklightRangeLimit::FilterField do | |
| 66 81 | 
             
                end
         | 
| 67 82 | 
             
              end
         | 
| 68 83 |  | 
| 84 | 
            +
              context 'with an end-less range' do
         | 
| 85 | 
            +
                let(:param_values) { { range: { some_field: { begin: '2013', end: '' } } } }
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                describe '#values' do
         | 
| 88 | 
            +
                  it 'converts the parameters to a Range' do
         | 
| 89 | 
            +
                    expect(filter.values).to eq [2013..nil]
         | 
| 90 | 
            +
                  end
         | 
| 91 | 
            +
                end
         | 
| 92 | 
            +
              end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
              context 'with an begin-less range' do
         | 
| 95 | 
            +
                let(:param_values) { { range: { some_field: { begin: '', end: '2022' } } } }
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                describe '#values' do
         | 
| 98 | 
            +
                  it 'converts the parameters to a Range' do
         | 
| 99 | 
            +
                    expect(filter.values).to eq [nil..2022]
         | 
| 100 | 
            +
                  end
         | 
| 101 | 
            +
                end
         | 
| 102 | 
            +
              end
         | 
| 103 | 
            +
             | 
| 69 104 | 
             
              context 'with empty data' do
         | 
| 70 105 | 
             
                let(:param_values) { { range: { some_field: { begin: '', end: '' } } } }
         | 
| 71 106 |  | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -6,6 +6,7 @@ EngineCart.load_application! | |
| 6 6 | 
             
            require 'rspec/rails'
         | 
| 7 7 | 
             
            require 'capybara/rspec'
         | 
| 8 8 | 
             
            require 'selenium-webdriver'
         | 
| 9 | 
            +
            require 'capybara-screenshot/rspec'
         | 
| 9 10 |  | 
| 10 11 | 
             
            Capybara.javascript_driver = :headless_chrome
         | 
| 11 12 |  | 
| @@ -16,10 +17,16 @@ Capybara.register_driver :headless_chrome do |app| | |
| 16 17 | 
             
                opts.args << '--disable-gpu'
         | 
| 17 18 | 
             
                opts.args << '--no-sandbox'
         | 
| 18 19 | 
             
                opts.args << '--window-size=1280,1696'
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                opts.add_option('goog:loggingPrefs', browser: 'ALL')
         | 
| 19 22 | 
             
              end
         | 
| 20 23 | 
             
              Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options)
         | 
| 21 24 | 
             
            end
         | 
| 22 25 |  | 
| 26 | 
            +
            Capybara::Screenshot.register_driver(:headless_chrome) do |driver, path|
         | 
| 27 | 
            +
              driver.browser.save_screenshot(path)
         | 
| 28 | 
            +
            end
         | 
| 29 | 
            +
             | 
| 23 30 | 
             
            # Requires supporting ruby files with custom matchers and macros, etc,
         | 
| 24 31 | 
             
            # in spec/support/ and its subdirectories.
         | 
| 25 32 | 
             
            Dir[Pathname.new(File.expand_path('support/**/*.rb', __dir__))].sort.each { |f| require f }
         | 
| @@ -38,4 +45,7 @@ RSpec.configure do |config| | |
| 38 45 |  | 
| 39 46 | 
             
              config.include PresenterTestHelpers, type: :presenter
         | 
| 40 47 | 
             
              config.include ViewComponent::TestHelpers, type: :component
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              config.example_status_persistence_file_path = 'spec/examples.txt'
         | 
| 50 | 
            +
             | 
| 41 51 | 
             
            end
         | 
| @@ -1,2 +1,12 @@ | |
| 1 1 | 
             
            gem 'rails-controller-testing'
         | 
| 2 | 
            -
             | 
| 2 | 
            +
             | 
| 3 | 
            +
            if ENV['BLACKLIGHT_VERSION']
         | 
| 4 | 
            +
              # allow direct git and other with serialized json kw args
         | 
| 5 | 
            +
              require 'json'
         | 
| 6 | 
            +
              if ENV['BLACKLIGHT_VERSION'].start_with?("{")
         | 
| 7 | 
            +
                gem "blacklight", **JSON.parse(ENV['BLACKLIGHT_VERSION'])
         | 
| 8 | 
            +
              else
         | 
| 9 | 
            +
                gem "blacklight", ENV['BLACKLIGHT_VERSION']
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             |