-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an integration test helper for use in integration tests for pages that have been transitioned to the GOV.UK Design System. Has a minimal implementation for now, which is copied from the legacy integration test helper.
- Loading branch information
1 parent
6325b26
commit 7c43814
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require "test_helper" | ||
require "capybara/rails" | ||
require "capybara-select-2" | ||
require "support/govuk_test" | ||
|
||
class PublisherIntegrationTest < ActionDispatch::IntegrationTest | ||
include Capybara::DSL | ||
include CapybaraSelect2 | ||
include CapybaraSelect2::Helpers | ||
include Warden::Test::Helpers | ||
|
||
teardown do | ||
Capybara.reset_sessions! # Forget the (simulated) browser state | ||
Capybara.use_default_driver # Revert Capybara.current_driver to Capybara.default_driver | ||
GDS::SSO.test_user = nil | ||
end | ||
|
||
def setup_users | ||
# This may not be the right way to do things. We rely on the gds-sso | ||
# having a strategy that uses the first user. We probably want some | ||
# tests that cover the oauth interaction properly | ||
@author = FactoryBot.create(:user, :govuk_editor, name: "Author", email: "[email protected]") | ||
@reviewer = FactoryBot.create(:user, :govuk_editor, name: "Reviewer", email: "[email protected]") | ||
end | ||
|
||
def login_as(user) | ||
GDS::SSO.test_user = user | ||
super(user) | ||
end | ||
end | ||
|
||
class JavascriptIntegrationTest < PublisherIntegrationTest | ||
setup do | ||
Capybara.current_driver = Capybara.javascript_driver | ||
end | ||
|
||
# Get a single user by their name. If the user doesn't exist, return nil. | ||
def get_user(name) | ||
User.where(name:).first | ||
end | ||
|
||
# Set the given user to be the current user | ||
# Accepts either a User object or a user's name | ||
def login_as(user) | ||
unless user.is_a?(User) | ||
user = get_user(user) | ||
end | ||
clear_cookies | ||
GDS::SSO.test_user = user | ||
end | ||
|
||
def clear_cookies | ||
browser = Capybara.current_session.driver.browser | ||
if browser.respond_to?(:clear_cookies) | ||
# Rack::MockSession | ||
browser.clear_cookies | ||
elsif browser.respond_to?(:manage) && browser.manage.respond_to?(:delete_all_cookies) | ||
# Selenium::WebDriver | ||
browser.manage.delete_all_cookies | ||
end | ||
end | ||
end |