Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add alt-text controller spec #3286

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions app/controllers/spotlight/accessibility_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ class AccessibilityController < Spotlight::ApplicationController
before_action :authenticate_user!
load_and_authorize_resource :exhibit, class: Spotlight::Exhibit

include Spotlight::Base
include Spotlight::SearchHelper

def alt_text
authorize! :curate, @exhibit

@limit = 5
# Sort by newest except for the homepage, which is always first
pages_with_alt = @exhibit.pages.order(Arel.sql('id = 1 DESC, created_at DESC')).select { |elem| elem.content.any?(&:alt_text?) }
Expand Down
36 changes: 36 additions & 0 deletions spec/controllers/spotlight/accessibility_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

describe Spotlight::AccessibilityController, type: :controller do
routes { Spotlight::Engine.routes }
let(:exhibit) { FactoryBot.create(:exhibit) }
let(:curator) { FactoryBot.create(:exhibit_curator, exhibit:) }
let(:repository) { double }
let(:model1) { double(Spotlight::FeaturePage, id: 1, content: content_list) }
let(:content_list) { [d] }

before do
allow(controller).to receive(:repository).and_return(repository)

FactoryBot.create(:about_page, exhibit:,
content: "{\"data\":[{\"type\":\"solr_documents\",\"data\":{\"show-primary-caption\":\"false\",
\"primary-caption-field\":\"\",\"show-secondary-caption\":\"false\",\"secondary-caption-field\":\"\",
\"format\":\"html\",\"item\":{\"item_0\":{ \"alt_text_backup\":\"\",\"alt_text\":\"\"},
\"item_2\":{\"alt_text_backup\":\"has alt\",\"alt_text\":\"has alt\"},
\"item_3\":{\"decorative\":\"on\",\"alt_text_backup\":\"\"}}}}]}")
FactoryBot.create(:feature_page, exhibit:)
sign_in curator
end

describe 'GET alt_text dashboard' do
it 'filters pages and gets alt_text totals' do
get :alt_text, params: { 'exhibit_id' => exhibit.id }
expect(response).to render_template 'spotlight/accessibility/alt_text'
expect(assigns[:limit]).to eq 5
expect(assigns[:pages].length).to eq 1
expect(assigns[:has_alt_text]).to eq 2
expect(assigns[:total_alt_items]).to eq 3

expect(exhibit.pages.length).to eq 3
end
end
end