forked from fixin.me/fixin.me
		
	Merging from main master to my repo master. #4
@ -1,6 +1,7 @@
 | 
				
			|||||||
require "test_helper"
 | 
					require "test_helper"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
 | 
					class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
 | 
				
			||||||
 | 
					  extend ActionView::Helpers::TranslationHelper
 | 
				
			||||||
  include ActionView::Helpers::UrlHelper
 | 
					  include ActionView::Helpers::UrlHelper
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # NOTE: geckodriver installed with Firefox, ignore incompatibility warning
 | 
					  # NOTE: geckodriver installed with Firefox, ignore incompatibility warning
 | 
				
			||||||
@ -32,4 +33,12 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
 | 
				
			|||||||
  #def assert_stale(element)
 | 
					  #def assert_stale(element)
 | 
				
			||||||
  #  assert_raises(Selenium::WebDriver::Error::StaleElementReferenceError) { element.tag_name }
 | 
					  #  assert_raises(Selenium::WebDriver::Error::StaleElementReferenceError) { element.tag_name }
 | 
				
			||||||
  #end
 | 
					  #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
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -1,6 +1,8 @@
 | 
				
			|||||||
require "application_system_test_case"
 | 
					require "application_system_test_case"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class UnitsTest < ApplicationSystemTestCase
 | 
					class UnitsTest < ApplicationSystemTestCase
 | 
				
			||||||
 | 
					  ADD_UNIT_LABELS = [t('units.index.add_unit'), t('units.unit.add_subunit')]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  setup do
 | 
					  setup do
 | 
				
			||||||
    @user = sign_in
 | 
					    @user = sign_in
 | 
				
			||||||
    visit units_path
 | 
					    visit units_path
 | 
				
			||||||
@ -49,36 +51,28 @@ class UnitsTest < ApplicationSystemTestCase
 | 
				
			|||||||
  test "add unit on validation error" do
 | 
					  test "add unit on validation error" do
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  # TODO: add non-empty form closing warning
 | 
				
			||||||
  test "add and edit disallow opening multiple forms" do
 | 
					  test "add and edit disallow opening multiple forms" do
 | 
				
			||||||
    # Once new/edit form is open, other actions on the same page either replace
 | 
					    # Once new/edit form is open, attempt to open another one will close it
 | 
				
			||||||
    # the form or leave it untouched
 | 
					 | 
				
			||||||
    # TODO: add non-empty form closing warning
 | 
					 | 
				
			||||||
    links = {}
 | 
					    links = {}
 | 
				
			||||||
    link_labels = {1 => [t('units.index.add_unit'), t('units.unit.add_subunit')],
 | 
					    # Define tr count change depending on link clicked
 | 
				
			||||||
                   0 => units.map(&:symbol)}
 | 
					    link_labels = {1 => ADD_UNIT_LABELS, 0 => units.map(&:symbol)}
 | 
				
			||||||
    link_labels.each_pair do |row_change, labels|
 | 
					    link_labels.each_pair do |row_change, labels|
 | 
				
			||||||
      all(:link_or_button, exact_text: Regexp.union(labels)).map { |l| links[l] = row_change }
 | 
					      all(:link_or_button, exact_text: Regexp.union(labels)).map { |l| links[l] = row_change }
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    link, rows = links.assoc(links.keys.sample).tap { |l, _| links.delete(l) }
 | 
					    link, rows = links.assoc(links.keys.sample).tap { |l, _| links.delete(l) }
 | 
				
			||||||
    assert_difference ->{ all('tbody tr').count }, rows do
 | 
					    assert_difference ->{ all('tbody tr').count }, rows do
 | 
				
			||||||
      link.click
 | 
					      link.click
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    find 'tbody tr:has(input[type=text]:focus)'
 | 
					    find('tbody tr:has(input[type=text])').assert_selector ':focus'
 | 
				
			||||||
 | 
					    assert !link.visible? || link[:disabled]
 | 
				
			||||||
    # Link should be now unavailable or unclickable
 | 
					 | 
				
			||||||
    begin
 | 
					 | 
				
			||||||
      assert_raises(Selenium::WebDriver::Error::ElementClickInterceptedError) do
 | 
					 | 
				
			||||||
        link.click
 | 
					 | 
				
			||||||
      end if link.visible?
 | 
					 | 
				
			||||||
    rescue Selenium::WebDriver::Error::StaleElementReferenceError
 | 
					 | 
				
			||||||
      link = nil
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    link = links.keys.select(&:visible?).sample
 | 
					    link = links.keys.select(&:visible?).sample
 | 
				
			||||||
    assert_difference ->{ all('tbody tr').count }, links[link] - rows do
 | 
					    assert_difference ->{ all('tbody tr').count }, links[link] - rows do
 | 
				
			||||||
      link.click
 | 
					      link.click
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
    assert_selector 'tbody tr:has(input[type=text]:focus)', count: 1
 | 
					    find('tbody tr:has(input[type=text])').assert_selector ':focus'
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # NOTE: extend with any add/edit link
 | 
					  # NOTE: extend with any add/edit link
 | 
				
			||||||
 | 
				
			|||||||
@ -9,8 +9,8 @@ class ActiveSupport::TestCase
 | 
				
			|||||||
  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
 | 
					  # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
 | 
				
			||||||
  fixtures :all
 | 
					  fixtures :all
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  include AbstractController::Translation
 | 
					 | 
				
			||||||
  include ActionMailer::TestHelper
 | 
					  include ActionMailer::TestHelper
 | 
				
			||||||
 | 
					  include ActionView::Helpers::TranslationHelper
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  # NOTE: use public #alphanumeric(chars: ...) from Ruby 3.3 onwards
 | 
					  # NOTE: use public #alphanumeric(chars: ...) from Ruby 3.3 onwards
 | 
				
			||||||
  SecureRandom.class_eval do
 | 
					  SecureRandom.class_eval do
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user