Skip to content

Commit

Permalink
Merge pull request #6602 from samvera/updates_iiif_manifest_spec
Browse files Browse the repository at this point in the history
Valkyrizes `spec/features/iiif_manifest_spec.rb`.
  • Loading branch information
dlpierce authored Jan 11, 2024
2 parents 7b418b9 + cf50127 commit 2e6aae2
Showing 1 changed file with 46 additions and 24 deletions.
70 changes: 46 additions & 24 deletions spec/features/iiif_manifest_spec.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
# frozen_string_literal: true
require 'rails_helper'

RSpec.describe 'building a IIIF Manifest' do
let(:work) { create(:work, title: ['Comet in Moominland'], creator: ['Jansson, Tove'], description: ['a novel about moomins']) }
let(:member_works) { create_list(:work_with_image_files, 2, title: ['supplemental object'], creator: ['Author, Samantha'], description: ['supplemental materials']) }
let(:file_sets) { create_list(:file_set, 12, :image, title: ['page n'], creator: ['Jansson, Tove'], description: ['the nth page']) }

RSpec.describe 'building a IIIF Manifest', :clean_repo do
let(:work) { valkyrie_create(:comet_in_moominland, :public, description: ['a novel about moomins']) }
let(:user) { create(:admin) }
let(:file_path) { fixture_path + '/world.png' }
let(:original_file) { File.open(file_path) }
let(:uploaded_file) { FactoryBot.create(:uploaded_file, file: original_file) }
let(:persister) { Hyrax.persister }

before do
work.ordered_members += file_sets
work.ordered_members += member_works
work.save
2.times { build_a_child_work }
12.times { build_a_file_set_with_an_image }
persister.save(resource: work)
Hyrax.index_adapter.save(resource: work)

sign_in user
end

it 'gets a full manifest for the work' do
visit "/concern/generic_works/#{work.id}/manifest"

# maybe validate this with https://github.com/IIIF/presentation-validator/blob/master/schema/iiif_3_0.json ?
manifest_json = JSON.parse(page.body)

expect(manifest_json['label']).to eq 'Comet in Moominland'
expect(manifest_json['description']).to contain_exactly('a novel about moomins')
manifest_json = load_manifest_check_standards
expect(manifest_json['sequences']).not_to be_empty

sequence = manifest_json['sequences'].first
Expand All @@ -36,19 +32,45 @@
let(:user) { create(:user) }

before do
work.read_users = [user]
work.save
work.permission_manager.read_users = [user]
persister.save(resource: work)
end

it 'generates a bare manifest' do
visit "/concern/generic_works/#{work.id}/manifest"

# maybe validate this with https://github.com/IIIF/presentation-validator/blob/master/schema/iiif_3_0.json ?
manifest_json = JSON.parse(page.body)

expect(manifest_json['label']).to eq 'Comet in Moominland'
expect(manifest_json['description']).to contain_exactly('a novel about moomins')
manifest_json = load_manifest_check_standards
expect(manifest_json).not_to have_key 'sequences'
end
end

def build_a_child_work
first_file_set = valkyrie_create(:hyrax_file_set)
second_file_set = valkyrie_create(:hyrax_file_set)
valkyrie_create(:hyrax_file_metadata, :original_file, :image, :with_file, original_filename: 'world.png', file_set: first_file_set, file: uploaded_file)
valkyrie_create(:hyrax_file_metadata, :original_file, :image, :with_file, original_filename: 'world.png', file_set: second_file_set, file: uploaded_file)
[first_file_set, second_file_set].each { |fs| persister.save(resource: fs) }
child_work = valkyrie_create(:monograph,
members: [first_file_set, second_file_set],
title: ['supplemental object'],
creator: ['Author, Samantha'],
description: ['supplemental materials'])
work.member_ids << child_work.id
end

def build_a_file_set_with_an_image
file_set = valkyrie_create(:hyrax_file_set, title: ['page n'], creator: ['Jansson, Tove'], description: ['the nth page'])
valkyrie_create(:hyrax_file_metadata, :original_file, :image, :with_file, original_filename: 'world.png', file_set: file_set, file: uploaded_file)
persister.save(resource: file_set)
work.member_ids << file_set.id
end

def load_manifest_check_standards
visit "/concern/generic_works/#{work.id}/manifest"

# maybe validate this with https://github.com/IIIF/presentation-validator/blob/master/schema/iiif_3_0.json ?
manifest_json = JSON.parse(page.body)

expect(manifest_json['label']).to eq 'Comet in Moominland'
expect(manifest_json['description']).to contain_exactly('a novel about moomins')
manifest_json
end
end

0 comments on commit 2e6aae2

Please sign in to comment.