forked from fixin.me/fixin.me
Update tests to use buttons
Add disguise/revert tests
This commit is contained in:
parent
fbb74bd1f8
commit
5e09adeae7
65
public/400.html
Normal file
65
public/400.html
Normal file
@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bad request received (400)</title>
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<style>
|
||||
.rails-default-error-page {
|
||||
background-color: #EFEFEF;
|
||||
color: #2E2F30;
|
||||
text-align: center;
|
||||
font-family: arial, sans-serif;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.rails-default-error-page div.dialog {
|
||||
width: 95%;
|
||||
max-width: 33em;
|
||||
margin: 4em auto 0;
|
||||
}
|
||||
|
||||
.rails-default-error-page div.dialog > div {
|
||||
border: 1px solid #CCC;
|
||||
border-right-color: #999;
|
||||
border-left-color: #999;
|
||||
border-bottom-color: #BBB;
|
||||
border-top: #ff1f5b solid 4px;
|
||||
border-top-left-radius: 9px;
|
||||
border-top-right-radius: 9px;
|
||||
background-color: #ff1f5b;
|
||||
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
||||
}
|
||||
|
||||
.rails-default-error-page h1 {
|
||||
font-size: 100%;
|
||||
color: white;
|
||||
line-height: 1em;
|
||||
}
|
||||
|
||||
.rails-default-error-page div.dialog > p {
|
||||
margin: 0 0 1em;
|
||||
padding: 1em;
|
||||
background-color: #F7F7F7;
|
||||
border: 1px solid #CCC;
|
||||
border-right-color: #999;
|
||||
border-left-color: #999;
|
||||
border-bottom-color: #999;
|
||||
border-bottom-left-radius: 4px;
|
||||
border-bottom-right-radius: 4px;
|
||||
border-top-color: #DADADA;
|
||||
color: #666;
|
||||
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body class="rails-default-error-page">
|
||||
<!-- This file lives in public/403.html -->
|
||||
<div class="dialog">
|
||||
<div>
|
||||
<h1>Server received request it won't process.</h1>
|
||||
</div>
|
||||
<p>If request has been generated by application, you can notify site administrator.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -1,10 +1,18 @@
|
||||
require "test_helper"
|
||||
|
||||
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||||
include ActionView::Helpers::UrlHelper
|
||||
|
||||
# NOTE: remove when capabilities no longer used by Rails
|
||||
Selenium::WebDriver.logger.ignore(:capabilities)
|
||||
Capybara.configure do |config|
|
||||
config.save_path = "#{Rails.root}/tmp/screenshots/"
|
||||
end
|
||||
|
||||
driven_by :selenium, using: :headless_firefox, screen_size: [2400, 1600]
|
||||
driven_by :selenium, using: :headless_firefox, screen_size: [2400, 1600] do |options|
|
||||
options.add_preference('browser.download.folderList', 2)
|
||||
options.add_preference('browser.download.dir', "#{Rails.root}/tmp/")
|
||||
end
|
||||
|
||||
def sign_in(user: users.select(&:confirmed?).sample, password: randomize_user_password!(user))
|
||||
visit new_user_session_url
|
||||
@ -12,4 +20,8 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||||
fill_in User.human_attribute_name(:password).capitalize, with: password
|
||||
click_on t(:sign_in)
|
||||
end
|
||||
|
||||
#def assert_stale(element)
|
||||
# assert_raise(Selenium::WebDriver::Error::StaleElementReferenceError) { element.tag_name }
|
||||
#end
|
||||
end
|
||||
|
@ -18,7 +18,7 @@ class UsersTest < ApplicationSystemTestCase
|
||||
end
|
||||
|
||||
test "sign out" do
|
||||
sign_in user: @admin
|
||||
sign_in
|
||||
visit root_url
|
||||
click_on t(:sign_out)
|
||||
assert_current_path new_user_session_path
|
||||
@ -27,7 +27,7 @@ class UsersTest < ApplicationSystemTestCase
|
||||
|
||||
test "recover password" do
|
||||
visit new_user_session_url
|
||||
click_link t(:recover_password)
|
||||
click_on t(:recover_password)
|
||||
|
||||
fill_in User.human_attribute_name(:email).capitalize,
|
||||
with: users.select(&:confirmed?).sample.email
|
||||
@ -52,7 +52,7 @@ class UsersTest < ApplicationSystemTestCase
|
||||
|
||||
test "register" do
|
||||
visit new_user_session_url
|
||||
click_link t(:register)
|
||||
click_on t(:register)
|
||||
|
||||
fill_in User.human_attribute_name(:email).capitalize, with: random_email
|
||||
password = random_password
|
||||
@ -77,8 +77,8 @@ class UsersTest < ApplicationSystemTestCase
|
||||
|
||||
test "resend confirmation" do
|
||||
visit new_user_session_url
|
||||
click_link t(:register)
|
||||
click_link t(:resend_confirmation)
|
||||
click_on t(:register)
|
||||
click_on t(:resend_confirmation)
|
||||
|
||||
fill_in User.human_attribute_name(:email).capitalize,
|
||||
with: users.reject(&:confirmed?).sample.email
|
||||
@ -95,18 +95,57 @@ class UsersTest < ApplicationSystemTestCase
|
||||
|
||||
test "show profile" do
|
||||
sign_in user: users.select(&:admin?).select(&:confirmed?).sample
|
||||
click_link t('layouts.application.users')
|
||||
email = all('tr').drop(1).sample.first('a').text
|
||||
click_link email
|
||||
assert_current_path user_path(User.find_by_email!(email))
|
||||
click_on t('layouts.application.users')
|
||||
within all('tr').drop(1).sample do |tr|
|
||||
email = first(:link).text
|
||||
click_on email
|
||||
assert_current_path user_path(User.find_by_email!(email))
|
||||
end
|
||||
end
|
||||
|
||||
test "disguise" do
|
||||
user = users.select(&:admin?).select(&:confirmed?).sample
|
||||
sign_in user: user
|
||||
|
||||
click_on t('layouts.application.users')
|
||||
all(:link_or_button, text: t("users.index.disguise")).sample.click
|
||||
assert_current_path edit_user_registration_path
|
||||
# TODO: test for profile app-menu link after root changed to different path
|
||||
# then profile
|
||||
|
||||
click_on t("layouts.application.revert")
|
||||
assert_current_path users_path
|
||||
assert_link user.email
|
||||
end
|
||||
|
||||
test "disguise disallowed" do
|
||||
user = users.select(&:admin?).select(&:confirmed?).sample
|
||||
sign_in user: user
|
||||
|
||||
click_on t('layouts.application.users')
|
||||
text = t('users.index.disguise')
|
||||
undisguisable = all(:xpath, "//tbody//tr[not(descendant::*[contains(text(),\"#{text}\")])]")
|
||||
within undisguisable.sample do |tr|
|
||||
email = first(:link).text
|
||||
button = button_to text, disguise_user_path(User.find_by_email!(email))
|
||||
evaluate_script("arguments[0].insertAdjacentHTML('beforeend', '#{button.html_safe}');",
|
||||
tr.find('td:last-child'))
|
||||
click_on text
|
||||
end
|
||||
assert_title "Bad request received (400)"
|
||||
end
|
||||
|
||||
test "destroy profile" do
|
||||
sign_in user: users.select(&:confirmed?).sample
|
||||
user = users.select(&:confirmed?).sample
|
||||
sign_in user: user
|
||||
# TODO: remove condition after root changed to different path than profile
|
||||
click_link t(:profile) unless has_current_path?(edit_user_registration_path)
|
||||
unless has_current_path?(edit_user_registration_path)
|
||||
first(:link_r_button, user.email).click
|
||||
end
|
||||
assert_difference ->{ User.count }, -1 do
|
||||
accept_confirm { click_link t('users.registrations.edit.delete') }
|
||||
# TODO: accept_confirm when modal dialog is working
|
||||
#accept_confirm { click_on t('users.registrations.edit.delete') }
|
||||
click_on t('users.registrations.edit.delete')
|
||||
end
|
||||
assert_current_path new_user_session_path
|
||||
end
|
||||
@ -114,7 +153,6 @@ class UsersTest < ApplicationSystemTestCase
|
||||
test "index forbidden for non admin" do
|
||||
sign_in user: users.reject(&:admin?).select(&:confirmed?).sample
|
||||
visit users_path
|
||||
assert has_no_link?t('layouts.application.users')
|
||||
assert_title "Access is forbidden to this page (403)"
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user