test_flags.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module TestFlags
  3. def wait_for_test_flag(flag, skip_clearing: false)
  4. begin
  5. wait.until { page.evaluate_script("window.testFlags && window.testFlags.get('#{flag.gsub("'", "\\'")}', #{skip_clearing})") }
  6. rescue Selenium::WebDriver::Error::TimeoutError
  7. raise "Test flag #{flag} not set"
  8. end
  9. end
  10. def wait_for_gql(filename, number: 1, skip_clearing: false)
  11. gql = Rails.root.join("app/frontend/#{filename}").read
  12. operation = %r{^\w+ \w+}.match(gql).to_s
  13. wait_for_test_flag("__gql #{operation} #{number}", skip_clearing: skip_clearing)
  14. end
  15. def wait_for_query(name, number: 1, skip_clearing: false)
  16. wait_for_test_flag("__gql query #{name} #{number}", skip_clearing: skip_clearing)
  17. end
  18. def wait_for_mutation(name, number: 1, skip_clearing: false)
  19. wait_for_test_flag("__gql mutation #{name} #{number}", skip_clearing: skip_clearing)
  20. end
  21. def wait_for_subscription_update(name, number: 1, skip_clearing: false)
  22. wait_for_test_flag("__gql subscription #{name} #{number}", skip_clearing: skip_clearing)
  23. end
  24. def wait_for_subscription_start(name, skip_clearing: true)
  25. wait_for_test_flag("__gql subscription #{name} start", skip_clearing: skip_clearing)
  26. end
  27. def wait_for_form_to_settle(form)
  28. wait_for_test_flag("#{form}.settled")
  29. end
  30. def wait_for_form_updater(form_updater_call_number = 1)
  31. wait_for_gql('shared/components/Form/graphql/queries/formUpdater.graphql', number: form_updater_call_number)
  32. end
  33. def wait_for_form_autofocus(form)
  34. wait_for_test_flag("#{form}.focused")
  35. end
  36. end
  37. RSpec.configure do |config|
  38. config.include TestFlags, type: :system
  39. end