Sha256: 7c30cab701bc4302ad7fe1655137b48313610d953fb6791dedf5f484756b5a20

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

describe SirTrevorRails::Blocks::FeaturedPagesBlock do
  subject { described_class.new({ type: '', data: block_data }, page) }

  let(:page) { FactoryBot.create(:feature_page, exhibit: exhibit) }
  let(:exhibit) { FactoryBot.create(:exhibit) }
  let(:block_data) { {} }

  describe '#items' do
    it 'is the array of items with display set to true' do
      block_data[:item] = {
        '0': { id: 'abc123', display: 'true' },
        '1': { id: 'xyz321', display: 'false' }
      }
      expect(subject.items.length).to eq 1
      expect(subject.items).to eq([{ id: 'abc123', display: 'true' }])
    end

    it 'is an empty array when there is no browse category' do
      expect(subject.items).to eq([])
    end
  end

  describe '#pages' do
    let!(:page_a) { FactoryBot.create(:feature_page, slug: 'a', exhibit: exhibit) }
    let!(:translated_page_a) { page_a.clone_for_locale('a').tap { |x| x.update(published: true) && x.save } }
    let!(:page_b) { FactoryBot.create(:feature_page, slug: 'b', exhibit: exhibit) }

    before do
      block_data[:item] = {
        '0': { id: 'a', display: 'true' },
        '1': { id: 'b', display: 'true' }
      }
    end

    it 'retrieves the pages from the default locale' do
      expect(subject.pages.length).to eq 2
    end
  end

  describe '#as_json' do
    context 'when no items are present' do
      it 'returns an empty items value' do
        block_data[:item] = nil
        expect(subject.as_json[:data]).to include item: {}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
blacklight-spotlight-3.4.0 spec/models/sir_trevor_rails/blocks/featured_pages_block_spec.rb
blacklight-spotlight-3.3.0 spec/models/sir_trevor_rails/blocks/featured_pages_block_spec.rb
blacklight-spotlight-3.2.0 spec/models/sir_trevor_rails/blocks/featured_pages_block_spec.rb