Sha256: 79e35e67915b4e84bb3d23988e84d4265210dc76ee29f908d27bbc4cc4dfe592

Contents?: true

Size: 1.99 KB

Versions: 51

Compression:

Stored size: 1.99 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_selector("span.applied-filter.constraint") do |s|
        expect(s).to have_css("span.constraint-value")
        expect(s).not_to have_css("a.constraint-value")
        expect(s).to have_selector "span.filter-name", text: "my label"
        expect(s).to have_selector "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_selector("span.applied-filter") do |s|
        expect(s).to have_selector(".remove[href='http://remove']")
      end
    end

    it "has an accessible remove label" do
      expect(rendered).to have_selector(".remove") do |s|
        expect(s).to have_selector('.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_selector("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_selector("span.applied-filter.constraint span.filter-name span.custom_label")
      expect(rendered).to have_selector("span.applied-filter.constraint span.filter-value span.custom_value")
    end
  end
end

Version data entries

51 entries across 51 versions & 2 rubygems

Version Path
blacklight-7.23.0.1 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-7.23.0 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-7.22.2 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-7.22.1 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-7.22.0 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-7.21.2 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-7.21.1 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-7.21.0 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-7.20.1 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-7.20.0 spec/components/blacklight/constraint_layout_component_spec.rb
blacklight-7.19.2 spec/components/blacklight/constraint_layout_component_spec.rb