jam-cloud/admin/spec/features/menu_click_spec.rb

59 lines
1.8 KiB
Ruby

require 'spec_helper'
describe 'Admin Menu', :type => :feature do
before do
# Ensure dependencies for factory are present
unless JamRuby::Instrument.exists?('electric guitar')
JamRuby::Instrument.create(id: 'electric guitar', description: 'Electric Guitar')
end
end
let(:admin) { FactoryBot.create(:admin) }
before do
sign_in(admin)
end
it 'allows clicking through all menu items' do
visit root_path
# Collect links
links = []
# ActiveAdmin menu structure selectors
# Top level links
all('#header ul#tabs > li > a', visible: :all).each do |a|
href = a[:href]
links << href if href && href != '#' && !href.start_with?('javascript:')
end
# Submenu links
all('#header ul#tabs > li > ul > li > a', visible: :all).each do |a|
href = a[:href]
links << href if href && href != '#' && !href.start_with?('javascript:')
end
links.uniq!
# Remove logout to avoid ending session
links.reject! { |l| l.include?('logout') || l.include?('sign_out') }
# Ignore pages referring to Gift Cards, Lessons, Students, or Teachers
links.reject! { |l| l =~ /gift_card|lesson|student|teacher|slow_responses|jam_class|jamclass|posa|onboarder|schooluserupload/i }
puts "Testing #{links.size} menu links: #{links.inspect}"
links.each do |link|
visit link
# Check for common Rails/ActiveAdmin error indicators
if page.has_content?("We're sorry, but something went wrong") ||
page.has_content?("Exception") ||
(page.respond_to?(:status_code) && page.status_code == 500)
fail "Failed to load #{link}"
end
expect(page.status_code).to eq(200) if page.respond_to?(:status_code)
end
end
end