Sha256: 207017122af8985c7109f2044bf6ff05b0e58a501a3058e75551dbbe461caa3e

Contents?: true

Size: 1.29 KB

Versions: 15

Compression:

Stored size: 1.29 KB

Contents

describe SirTrevorRails::Blocks::BrowseBlock do
  let(:page) { FactoryBot.create(:feature_page) }
  let(:block_data) { {} }
  subject { described_class.new({ type: '', data: block_data }, page) }

  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 '#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

    context 'when the id of a browse category does not exist' do
      it 'is not included the returned items hash' do
        search = FactoryBot.create(:search, exhibit: page.exhibit)
        block_data[:item] = { item_0: { 'id' => 'abc123' }, item_1: { 'id' => search.slug } }

        expect(subject.as_json[:data][:item]).not_to have_key :item_0
        expect(subject.as_json[:data][:item]).to have_key :item_1
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
blacklight-spotlight-2.0.2 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-2.0.1 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-2.0.0 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-2.0.0.rc6 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-2.0.0.rc5 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-2.0.0.rc4 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-2.0.0.rc3 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-2.0.0.rc2 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-2.0.0.rc1 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-1.5.1 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-1.4.1 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-1.4.0 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-1.3.0 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-1.2.0 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb
blacklight-spotlight-1.1.0 spec/models/sir_trevor_rails/blocks/browse_block_spec.rb