Sha256: d7438f1f6a7c1a22a581dcc1e0b982d10734ddfe657a0c0a27ee374f6797e4f8

Contents?: true

Size: 1.8 KB

Versions: 3

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'
RSpec.describe NewspaperWorks::BlacklightIiifSearch::AnnotationBehavior do
  let(:page_document) { build(:newspaper_page_solr_document) }
  let(:controller) { CatalogController.new }
  let(:coordinates) do
    JSON.parse("{\"coords\":{\"software\":[[2641,4102,512,44]]}}")
  end
  let(:parent_document) do
    SolrDocument.new('id' => page_document[:issue_id_ssi],
                     'has_model_ssim' => ['NewspaperIssue'])
  end
  let(:iiif_search_annotation) do
    BlacklightIiifSearch::IiifSearchAnnotation.new(page_document, 'software',
                                                   0, nil, controller,
                                                   parent_document)
  end
  let(:test_request) { ActionDispatch::TestRequest.new({}) }

  before { allow(controller).to receive(:request).and_return(test_request) }

  describe '#annotation_id' do
    subject { iiif_search_annotation.annotation_id }
    it 'returns a properly formatted URL' do
      expect(subject).to include("#{page_document[:issue_id_ssi]}/manifest/canvas/#{page_document[:file_set_ids_ssim].first}/annotation/0")
    end
  end

  describe '#canvas_uri_for_annotation' do
    before { allow(iiif_search_annotation).to receive(:fetch_and_parse_coords).and_return(coordinates) }

    subject { iiif_search_annotation.canvas_uri_for_annotation }
    it 'returns a properly formatted URL' do
      expect(subject).to include("#{page_document[:issue_id_ssi]}/manifest/canvas/#{page_document[:file_set_ids_ssim].first}")
    end

    describe 'private methods' do
      # test #coordinates based on output of #canvas_uri_for_annotation, which calls it
      describe '#coordinates' do
        it 'gets the expected value from #coordinates' do
          expect(subject).to include("#xywh=2641,4102,512,44")
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
newspaper_works-1.0.1 spec/models/concerns/newspaper_works/blacklight_iiif_search/annotation_behavior_spec.rb
newspaper_works-1.0.0 spec/models/concerns/newspaper_works/blacklight_iiif_search/annotation_behavior_spec.rb
newspaper_works-0.1.0 spec/models/concerns/newspaper_works/blacklight_iiif_search/annotation_behavior_spec.rb