Skip to content

Commit

Permalink
Javascript specs.
Browse files Browse the repository at this point in the history
Co-authored-by: GriffinJ <jrgriffiniii@gmail.com>
  • Loading branch information
2 people authored and christinach committed Feb 16, 2019
1 parent 17f28fd commit aa6cd07
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 18 deletions.
8 changes: 6 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ group :development, :test do
gem 'capistrano-passenger'
gem 'capistrano-rails'
gem 'capistrano-rails-console'
gem 'capybara'
gem 'capybara', '~> 2.0'
gem 'capybara-screenshot'
gem 'capybara-selenium'
gem 'coveralls', require: false
gem 'database_cleaner'
gem 'factory_bot_rails', require: false
gem 'pry-byebug'
gem 'pry-rails'
gem 'rails-controller-testing'
gem 'rspec-rails'
gem "selenium-webdriver"
gem 'simplecov', require: false
gem 'sqlite3'
gem 'sshkit', '~> 1.18'
gem 'vcr'
gem 'webmock', require: false
end

group :test do
gem "chromedriver-helper"
end

group :development do
gem 'foreman'
gem 'puma'
Expand Down
30 changes: 17 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ GEM
almond-rails (0.1.0)
rails (>= 4.2, < 6)
amq-protocol (2.3.0)
archive-zip (0.11.0)
io-like (~> 0.3.0)
arel (7.1.4)
ast (2.4.0)
autoprefixer-rails (6.7.6)
Expand Down Expand Up @@ -179,25 +181,25 @@ GEM
capistrano-rails-console (2.1.1)
capistrano (>= 3.5.0, < 4.0.0)
sshkit-interactive (~> 0.2.0)
capybara (2.10.1)
capybara (2.18.0)
addressable
mime-types (>= 1.16)
mini_mime (>= 0.1.3)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
xpath (>= 2.0, < 4.0)
capybara-screenshot (1.0.22)
capybara (>= 1.0, < 4)
launchy
capybara-selenium (0.0.6)
capybara
selenium-webdriver
carrierwave (1.2.2)
activemodel (>= 4.0.0)
activesupport (>= 4.0.0)
mime-types (>= 1.16)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
chromedriver-helper (2.1.0)
archive-zip (~> 0.10)
nokogiri (~> 1.8)
clipboard-rails (1.7.1)
coderay (1.1.1)
coffee-rails (4.1.1)
Expand Down Expand Up @@ -252,7 +254,7 @@ GEM
multipart-post (>= 1.2, < 3)
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
ffi (1.9.25)
ffi (1.10.0)
foreman (0.85.0)
thor (~> 0.19.1)
github-markup (2.0.0)
Expand All @@ -275,6 +277,7 @@ GEM
iiif_manifest (0.1.2)
activesupport (>= 4)
iiif-presentation (~> 0.1.0)
io-like (0.3.0)
iso-639 (0.2.8)
jbuilder (2.6.0)
activesupport (>= 3.0.0, < 5.1)
Expand Down Expand Up @@ -475,9 +478,9 @@ GEM
sdoc (0.4.2)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
selenium-webdriver (3.12.0)
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2)
rubyzip (~> 1.2, >= 1.2.2)
serverengine (2.0.6)
sigdump (~> 0.2.2)
sidekiq (4.2.2)
Expand Down Expand Up @@ -584,8 +587,8 @@ GEM
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.3)
xpath (2.0.0)
nokogiri (~> 1.3)
xpath (3.2.0)
nokogiri (~> 1.8)

PLATFORMS
ruby
Expand All @@ -601,9 +604,9 @@ DEPENDENCIES
capistrano-passenger
capistrano-rails
capistrano-rails-console
capybara
capybara (~> 2.0)
capybara-screenshot
capybara-selenium
chromedriver-helper
coffee-rails
coveralls
dalli
Expand Down Expand Up @@ -644,6 +647,7 @@ DEPENDENCIES
rubyzip (>= 1.2.2)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
selenium-webdriver
sidekiq
simplecov
sitemap_generator
Expand Down
54 changes: 54 additions & 0 deletions spec/features/catalog_show_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'rails_helper'

RSpec.describe 'Catalog', type: :feature, js: true do
let(:exhibit) { FactoryBot.create(:exhibit, title: 'Exhibit Title 1') }
let(:curator) { FactoryBot.create(:exhibit_curator, exhibit: exhibit) }
let(:admin) { FactoryBot.create(:exhibit_admin, exhibit: exhibit) }
let(:document_id) { '1r66j4408' }
let(:id) { Digest::MD5.hexdigest("#{exhibit.id}-#{document_id}") }
let(:document) do
SolrDocument.new(
id: id
)
end

before do
sign_in admin
Spotlight::SolrDocumentSidecar.create!(
document: document, exhibit: exhibit,
data: {
full_title_tesim: [
'test item'
],
access_identifier_ssim: [
"1r66j4408"
],
'readonly_description_ssim': [
"panoramic" * 50
],
'exhibit_exhibit-title-1_readonly_description_ssim': [
"panoramic" * 50
],
'content_metadata_iiif_manifest_field_ssi': [
'http://images.institution.edu'
]
}
)

document.make_public! exhibit
document.reindex
Blacklight.default_index.connection.commit

Spotlight::CustomField.create!(exhibit: exhibit, slug: 'description', field: 'readonly_description_ssim', configuration: { "label" => "Description" }, field_type: 'vocab', readonly_field: true)
end

it 'will add a ... More link in the field' do
visit spotlight.exhibit_solr_document_path(exhibit, document_id)
expect(page).to have_content 'panoramic'
expect(page).to have_selector "a.morelink"
end

def index
Blacklight.default_index.connection
end
end
23 changes: 23 additions & 0 deletions spec/support/capybara_selenium.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'capybara/rspec'
require 'selenium-webdriver'

# there's a bug in capybara-screenshot that requires us to name
# the driver ":selenium" so we changed it from :headless_chrome"
Capybara.register_driver(:selenium) do |app|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w[headless disable-gpu disable-setuid-sandbox window-size=7680,4320] }
)

http_client = Selenium::WebDriver::Remote::Http::Default.new
http_client.read_timeout = 120
http_client.open_timeout = 120
Capybara::Selenium::Driver.new(app,
browser: :chrome,
desired_capabilities: capabilities,
http_client: http_client)
end

Capybara.javascript_driver = :selenium
Capybara.default_max_wait_time = 15
7 changes: 6 additions & 1 deletion spec/support/devise_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# frozen_string_literal: true

require_relative 'request_spec_helper'
RSpec.configure do |config|
config.include Devise::Test::ControllerHelpers, type: :controller
config.include Devise::Test::ControllerHelpers, type: :view
config.include Devise::Test::ControllerHelpers, type: :controller
config.include RequestSpecHelper, type: :request
config.include RequestSpecHelper, type: :feature, js: true
end
8 changes: 6 additions & 2 deletions spec/support/features/session_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ module SessionHelpers
# Use this in feature tests
def sign_in(who = :user)
user = if who.instance_of?(User)
who.username
who.uid
else
FactoryBot.create(:user).username
FactoryBot.create(:user).uid
end
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:cas, uid: user)
visit user_cas_omniauth_authorize_path
end
end
end
RSpec.configure do |config|
config.include Features::SessionHelpers, type: :feature
end
24 changes: 24 additions & 0 deletions spec/support/request_spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module RequestSpecHelper
include Warden::Test::Helpers

def self.included(base)
base.before { Warden.test_mode! }
base.after { Warden.test_reset! }
end

def sign_in(resource)
login_as(resource, scope: warden_scope(resource))
end

def sign_out(resource)
logout(warden_scope(resource))
end

private

def warden_scope(resource)
resource.class.name.underscore.to_sym
end
end

0 comments on commit aa6cd07

Please sign in to comment.