forked from fixin.me/fixin.me
Use [disabled] attribute only on tags that support it
Add Capybara selector for disabled links.
This commit is contained in:
@@ -67,21 +67,11 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
||||
ActiveRecord::Base.establish_connection(TEST_CONFIGS[name.to_sym])
|
||||
end
|
||||
|
||||
#def assert_stale(element)
|
||||
# assert_raises(Selenium::WebDriver::Error::StaleElementReferenceError) { element.tag_name }
|
||||
#end
|
||||
Capybara.modify_selector(:link) do
|
||||
expression_filter(:disabled) do |xpath, value|
|
||||
builder(xpath).add_attribute_conditions('aria-disabled': value)
|
||||
end
|
||||
end
|
||||
|
||||
# HTML does not allow [disabled] attribute on <a> tag, so it's not possible to
|
||||
# easily find them using e.g. :link selector
|
||||
#Capybara.add_selector(:disabled_link) do
|
||||
# label "<a> tag with [disabled] attribute"
|
||||
#end
|
||||
|
||||
#test "click disabled link" do
|
||||
# Link should be unclickable
|
||||
# assert_raises(Selenium::WebDriver::Error::ElementClickInterceptedError) do
|
||||
# # Use custom selector for disabled links
|
||||
# find('a[disabled]').click
|
||||
# end
|
||||
#end
|
||||
end
|
||||
|
||||
@@ -41,9 +41,10 @@ class UnitsTest < ApplicationSystemTestCase
|
||||
sign_in
|
||||
link_labels.slice!(:new_unit, :new_subunit)
|
||||
type, label = link_labels.to_a.sample
|
||||
new_link = all(:link, exact_text: label).sample
|
||||
new_link.click
|
||||
assert_equal 'disabled', new_link[:disabled]
|
||||
all(:link, exact_text: label).sample.then do |link|
|
||||
link.click
|
||||
link.assert_matches_selector :link, disabled: true
|
||||
end
|
||||
|
||||
values = nil
|
||||
within 'tbody > tr:has(input[type=text], textarea)' do
|
||||
@@ -74,7 +75,7 @@ class UnitsTest < ApplicationSystemTestCase
|
||||
assert_no_selector :fillable_field
|
||||
assert_selector 'tr', count: @user.units.count
|
||||
end
|
||||
assert_no_selector :element, :a, 'disabled': 'disabled',
|
||||
assert_no_selector :link, disabled: true,
|
||||
exact_text: Regexp.union(link_labels.values)
|
||||
assert_equal values, Unit.last.attributes.slice(*values.keys)
|
||||
end
|
||||
@@ -126,7 +127,7 @@ class UnitsTest < ApplicationSystemTestCase
|
||||
if type == :edit
|
||||
assert_no_selector :link, exact_text: link[:text]
|
||||
else
|
||||
assert_equal 'disabled', link[:disabled]
|
||||
link.assert_matches_selector :link, disabled: true
|
||||
end
|
||||
|
||||
within 'tbody > tr:has(input[type=text])' do
|
||||
@@ -159,7 +160,7 @@ class UnitsTest < ApplicationSystemTestCase
|
||||
refute subunit_link&.visible?
|
||||
links[:new_subunit].delete(subunit_link)
|
||||
else
|
||||
assert link[:disabled]
|
||||
link.assert_matches_selector :link, disabled: true
|
||||
end
|
||||
|
||||
type, link = random_link[]
|
||||
|
||||
@@ -8,7 +8,7 @@ class UsersTest < ApplicationSystemTestCase
|
||||
|
||||
test 'sign in' do
|
||||
visit root_url
|
||||
assert find_link(href: new_user_session_path)[:disabled]
|
||||
assert_selector :link, text: t(:sign_in), disabled: true
|
||||
|
||||
sign_in
|
||||
assert_no_current_path new_user_session_path
|
||||
@@ -27,7 +27,7 @@ class UsersTest < ApplicationSystemTestCase
|
||||
|
||||
assert_current_path new_user_session_path
|
||||
assert_text t('devise.failure.invalid', authentication_keys: label.downcase_first)
|
||||
assert find_link(href: new_user_session_path)[:disabled]
|
||||
assert_selector :link, text: t(:sign_in), disabled: true
|
||||
assert has_field?(label, with: email)
|
||||
end
|
||||
|
||||
@@ -89,7 +89,7 @@ class UsersTest < ApplicationSystemTestCase
|
||||
test 'register' do
|
||||
visit root_url
|
||||
click_on t(:register)
|
||||
assert find_link(href: new_user_registration_path)[:disabled]
|
||||
assert_selector :link, text: t(:register), disabled: true
|
||||
|
||||
fill_in User.human_attribute_name(:email), with: random_email
|
||||
password = random_password
|
||||
|
||||
Reference in New Issue
Block a user