Browse Source

Spec show and hide conditional behaviour

pull/29/head
baarkerlounger 4 years ago
parent
commit
5d23bf0584
  1. 2
      Gemfile
  2. 7
      Gemfile.lock
  3. 10
      spec/features/case_log_spec.rb
  4. 8
      spec/rails_helper.rb

2
Gemfile

@ -29,7 +29,7 @@ group :development, :test do
gem "dotenv-rails"
gem "factory_bot_rails"
gem "pry-byebug"
# gem "selenium-webdriver", require: false
gem "selenium-webdriver", require: false
gem "simplecov", require: false
%w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
gem lib, git: "https://github.com/rspec/#{lib}.git", branch: "main", require: false

7
Gemfile.lock

@ -175,8 +175,6 @@ GEM
minitest (5.14.4)
msgpack (1.4.2)
nio4r (2.5.8)
nokogiri (1.12.4-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.12.4-x86_64-linux)
racc (~> 1.4)
overcommit (0.58.0)
@ -267,6 +265,7 @@ GEM
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.11.0)
rubyzip (2.3.2)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
@ -276,6 +275,9 @@ GEM
sass (~> 3.5, >= 3.5.5)
scss_lint-govuk (0.2.0)
scss_lint
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
semantic_range (3.0.0)
simplecov (0.21.2)
docile (~> 1.1)
@ -349,6 +351,7 @@ DEPENDENCIES
rubocop-performance
rubocop-rails
scss_lint-govuk
selenium-webdriver
simplecov
tzinfo-data
web-console (>= 4.1.0)

10
spec/features/case_log_spec.rb

@ -223,7 +223,15 @@ RSpec.describe "Test Features" do
context "given a page where some questions are only conditionally shown, depending on how you answer the first question" do
it "initially hides conditional questions" do
visit("/case_logs/#{id}/armed_forces")
expect(page).to have_selector("#armed_forces_injured_div", visible: :hidden)
expect(page).not_to have_selector("#armed_forces_injured_div")
end
it "shows conditional questions if the required answer is selected and hides it again when a different answer option is selected", js: true do
visit("/case_logs/#{id}/armed_forces")
find(:xpath, "//label[@for='armed-forces-0-field']").click
expect(page).to have_selector("#armed_forces_injured_div")
find(:xpath, "//label[@for='armed-forces-2-field']").click
expect(page).not_to have_selector("#armed_forces_injured_div")
end
end
end

8
spec/rails_helper.rb

@ -6,6 +6,10 @@ require File.expand_path("../config/environment", __dir__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require "rspec/rails"
require "capybara/rspec"
# Uncomment to run `js: true specs` with visible browser interaction
Capybara.javascript_driver = :selenium_headless
# Add additional requires below this line. Rails is not loaded until this point!
# Requires supporting ruby files with custom matchers and macros, etc, in
@ -62,4 +66,8 @@ RSpec.configure do |config|
config.filter_rails_from_backtrace!
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")
# Silence capybara logging puma start up messages to stdout on first js: true
# spec
Capybara.server = :puma, { Silent: true }
end

Loading…
Cancel
Save