Sha256: 93caa83d50eebfb83f208f8f8397d81b2485b08278d876aac6abd137e32015be

Contents?: true

Size: 1.94 KB

Versions: 7

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Blacklight::ConstraintLayoutComponent, type: :component do
  subject(:rendered) do
    render_inline_to_capybara_node(described_class.new(**params))
  end

  describe "for simple display" do
    let(:params) do
      { label: "my label", value: "my value" }
    end

    it "renders label and value" do
      expect(rendered).to have_css("span.applied-filter.constraint") do |s|
        expect(s).to have_css("span.constraint-value")
        expect(s).to have_no_css("a.constraint-value")
        expect(s).to have_css "span.filter-name", text: "my label"
        expect(s).to have_css "span.filter-value", text: "my value"
      end
    end
  end

  describe "with remove link" do
    let(:params) do
      { label: "my label", value: "my value", remove_path: "http://remove" }
    end

    it "includes remove link" do
      expect(rendered).to have_css("span.applied-filter") do |s|
        expect(s).to have_css(".remove[href='http://remove']")
      end
    end

    it "has an accessible remove label" do
      expect(rendered).to have_css(".remove") do |s|
        expect(s).to have_css('.visually-hidden', text: 'Remove constraint my label: my value')
      end
    end
  end

  describe "with custom classes" do
    let(:params) do
      { label: "my label", value: "my value", classes: %w[class1 class2] }
    end

    it "includes them" do
      expect(rendered).to have_css("span.applied-filter.constraint.class1.class2")
    end
  end

  describe "with no escaping" do
    let(:params) do
      { label: "<span class='custom_label'>my label</span>".html_safe, value: "<span class='custom_value'>my value</span>".html_safe }
    end

    it "does not escape key and value" do
      expect(rendered).to have_css("span.applied-filter.constraint span.filter-name span.custom_label")
      expect(rendered).to have_css("span.applied-filter.constraint span.filter-value span.custom_value")
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
blacklight-8.6.1 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-8.6.0 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-8.5.1 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-8.5.0 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-8.4.0 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-8.3.0 spec/components/blacklight/constraint_layout_component_spec.rb