Skip to content

Commit

Permalink
Merge pull request #326 from alphagov/add_template_tests
Browse files Browse the repository at this point in the history
Add some integration tests for the existing templates
  • Loading branch information
tombye committed Sep 20, 2013
2 parents 20437d7 + c92bb1a commit cca20b0
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 7 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.9.3-p392
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ group :assets do
end

group :test do
gem 'capybara', '1.1.0'
gem 'capybara', '2.1.0'
gem 'mocha', '0.13.3', :require => false
gem 'shoulda', '2.11.3'
end
Expand Down
13 changes: 7 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ GEM
mime-types
xml-simple
builder (3.0.4)
capybara (1.1.0)
capybara (2.1.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
xpath (~> 2.0)
childprocess (0.3.5)
ffi (~> 1.0, >= 1.0.6)
diff-lcs (1.1.3)
Expand Down Expand Up @@ -79,10 +78,12 @@ GEM
treetop (~> 1.4.8)
metaclass (0.0.1)
mime-types (1.21)
mini_portile (0.5.1)
mocha (0.13.3)
metaclass (~> 0.0.1)
multi_json (1.7.1)
nokogiri (1.5.5)
nokogiri (1.6.0)
mini_portile (~> 0.5.0)
null_logger (0.0.1)
plek (1.3.1)
polyglot (0.3.3)
Expand Down Expand Up @@ -158,15 +159,15 @@ GEM
rack
raindrops (~> 0.7)
xml-simple (1.1.1)
xpath (0.1.4)
xpath (2.0.0)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
aws-ses
capybara (= 1.1.0)
capybara (= 2.1.0)
exception_notification
govuk_frontend_toolkit (= 0.32.2)
jasmine (= 1.1.2)
Expand Down
29 changes: 29 additions & 0 deletions test/integration/templates/chromeless_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require_relative "../../integration_test_helper"

class ChromelessTest < ActionDispatch::IntegrationTest

should "render the template" do
visit "/templates/chromeless.html.erb"

within "head", :visible => :all do
assert page.has_selector?("title", :text => "GOV.UK - The best place to find government services and information", :visible => :all)

assert page.has_selector?("link[href='/static/header-footer-only.css']", :visible => :all)
end

within "body" do
assert page.has_selector?("#global-cookie-message")

assert page.has_selector?("#wrapper")

within "footer" do
refute page.has_selector?(".footer-categories")

assert page.has_selector?(".footer-meta")
end

assert page.has_selector?("script[src='/static/libs/jquery/jquery-1.7.2.js']", :visible => :all)
assert page.has_selector?("script[src='/static/header-footer-only.js']", :visible => :all)
end
end
end
41 changes: 41 additions & 0 deletions test/integration/templates/error_4xx_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require_relative "../../integration_test_helper"

class Error4XXTest < ActionDispatch::IntegrationTest

should "render the 404 template" do
visit "/templates/404.html.erb"

assert page.has_selector?("html.error.error-40X")
within "head", :visible => :all do
assert page.has_selector?("title", :text => "Page not found - 404 - GOV.UK", :visible => :all)

assert page.has_selector?("link[href='/static/application.css']", :visible => :all)

assert page.has_selector?("script[src='/static/libs/jquery/jquery-1.7.2.js']", :visible => :all)
assert page.has_selector?("script[src='/static/application.js']", :visible => :all)
end

within "body.mainstream.error" do
within "header#global-header" do
assert page.has_selector?("form#search")
end

assert page.has_selector?("#global-cookie-message")
assert page.has_selector?("#user-satisfaction-survey")
assert page.has_selector?("#global-breadcrumb")

within "#wrapper" do
assert page.has_selector?("h1", :text => "This page cannot be found")

assert page.has_selector?(".report-a-problem")
end

within "footer" do
assert page.has_selector?(".footer-categories")

assert page.has_selector?(".footer-meta")
end

end
end
end
39 changes: 39 additions & 0 deletions test/integration/templates/error_5xx_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require_relative "../../integration_test_helper"

class Error5XXTest < ActionDispatch::IntegrationTest

should "render the 500 template" do
visit "/templates/500.html.erb"

assert page.has_selector?("html.error.error-50X")
within "head", :visible => :all do
assert page.has_selector?("title", :text => "Sorry, we are experiencing technical difficulties (500 error) - GOV.UK", :visible => :all)

assert page.has_selector?("link[href='/static/application.css']", :visible => :all)

assert page.has_selector?("script[src='/static/libs/jquery/jquery-1.7.2.js']", :visible => :all)
assert page.has_selector?("script[src='/static/application.js']", :visible => :all)
end

within "body.mainstream.error" do
within "header#global-header" do
assert page.has_selector?("form#search")
end

assert page.has_selector?("#global-cookie-message")
assert page.has_selector?("#user-satisfaction-survey")
assert page.has_selector?("#global-breadcrumb")

within "#wrapper" do
assert page.has_selector?("h1", :text => "Sorry, we are experiencing technical difficulties")
end

within "footer" do
assert page.has_selector?(".footer-categories")

assert page.has_selector?(".footer-meta")
end

end
end
end
35 changes: 35 additions & 0 deletions test/integration/templates/header_footer_only_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require_relative "../../integration_test_helper"

class HeaderFooterOnlyTest < ActionDispatch::IntegrationTest

should "render the template" do
visit "/templates/header_footer_only.html.erb"

within "head", :visible => :all do
assert page.has_selector?("title", :text => "GOV.UK - The best place to find government services and information", :visible => :all)

assert page.has_selector?("link[href='/static/header-footer-only.css']", :visible => :all)
end

within "body" do
within "header#global-header" do
assert page.has_selector?("form#search")
end

assert page.has_selector?("#global-cookie-message")
assert page.has_selector?("#user-satisfaction-survey")
assert page.has_selector?("#global-breadcrumb")

assert page.has_selector?("#wrapper")

within "footer" do
assert page.has_selector?(".footer-categories")

assert page.has_selector?(".footer-meta")
end

assert page.has_selector?("script[src='/static/libs/jquery/jquery-1.7.2.js']", :visible => :all)
assert page.has_selector?("script[src='/static/header-footer-only.js']", :visible => :all)
end
end
end
35 changes: 35 additions & 0 deletions test/integration/templates/homepage_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require_relative "../../integration_test_helper"

class HomepageTest < ActionDispatch::IntegrationTest

should "render the template" do
visit "/templates/homepage.html.erb"

within "head", :visible => :all do
assert page.has_selector?("title", :text => "GOV.UK - The best place to find government services and information", :visible => :all)

assert page.has_selector?("link[href='/static/application.css']", :visible => :all)

assert page.has_selector?("script[src='/static/libs/jquery/jquery-1.7.2.js']", :visible => :all)
assert page.has_selector?("script[src='/static/application.js']", :visible => :all)
end

within "body" do
within "header#global-header" do
assert page.has_selector?("form#search")
end

assert page.has_selector?("#global-cookie-message")
assert page.has_selector?("#user-satisfaction-survey")
refute page.has_selector?("#global-breadcrumb")

assert page.has_selector?("#wrapper")

within "footer" do
assert page.has_selector?(".footer-categories")

assert page.has_selector?(".footer-meta")
end
end
end
end
21 changes: 21 additions & 0 deletions test/integration/templates/non_layout_templates_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative "../../integration_test_helper"

class NonLayoutTemplatesTest < ActionDispatch::IntegrationTest
def template_file(name)
Rails.root.join("app", "views", "root", "#{name}.html.erb")
end

%w(
beta_notice
campaign
proposition_menu
related.raw
report_a_problem.raw
).each do |template|
should "not add a layout to the #{template} snippet" do
get "/templates/#{template}.html.erb"

refute_match '<html', last_response.body
end
end
end
36 changes: 36 additions & 0 deletions test/integration/templates/wrapper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require_relative "../../integration_test_helper"

class WrapperTest < ActionDispatch::IntegrationTest

should "render the template" do
visit "/templates/wrapper.html.erb"

within "head", :visible => :all do
assert page.has_selector?("title", :text => "GOV.UK - The best place to find government services and information", :visible => :all)

assert page.has_selector?("link[href='/static/application.css']", :visible => :all)

assert page.has_selector?("script[src='/static/libs/jquery/jquery-1.7.2.js']", :visible => :all)
assert page.has_selector?("script[src='/static/application.js']", :visible => :all)
end

within "body" do
within "header#global-header" do
assert page.has_selector?("form#search")
end

assert page.has_selector?("#global-cookie-message")
assert page.has_selector?("#user-satisfaction-survey")
assert page.has_selector?("#global-breadcrumb")

assert page.has_selector?("#wrapper")

within "footer" do
assert page.has_selector?(".footer-categories")

assert page.has_selector?(".footer-meta")
end

end
end
end
35 changes: 35 additions & 0 deletions test/integration/templates/wrapper_with_js_last.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require_relative "../../integration_test_helper"

class WrapperWithJSLastTest < ActionDispatch::IntegrationTest

should "render the template" do
visit "/templates/wrapper_with_js_last.html.erb"

within "head", :visible => :all do
assert page.has_selector?("title", :text => "GOV.UK - The best place to find government services and information", :visible => :all)

assert page.has_selector?("link[href='/static/application.css']", :visible => :all)
end

within "body" do
within "header#global-header" do
assert page.has_selector?("form#search")
end

assert page.has_selector?("#global-cookie-message")
assert page.has_selector?("#user-satisfaction-survey")
assert page.has_selector?("#global-breadcrumb")

assert page.has_selector?("#wrapper")

within "footer" do
assert page.has_selector?(".footer-categories")

assert page.has_selector?(".footer-meta")
end

assert page.has_selector?("script[src='/static/libs/jquery/jquery-1.7.2.js']", :visible => :all)
assert page.has_selector?("script[src='/static/application.js']", :visible => :all)
end
end
end

0 comments on commit cca20b0

Please sign in to comment.