q_unit_spec.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'QUnit', time_zone: 'Europe/London', type: :system do
  4. matcher :pass_qunit_test do
  5. match do
  6. actual.has_css?('.total', wait: 120)
  7. actual.has_css? '.result .failed', text: '0', wait: 0
  8. end
  9. failure_message do
  10. messages = actual
  11. .all('.qunit-assert-list li.fail')
  12. .map { |elem| "> #{failure_name(elem)}\n#{failure_source(elem)}" }
  13. .join("\n")
  14. "Failed #{failed_count} out of #{total_count}:\n#{messages}"
  15. end
  16. def failure_source(row)
  17. row
  18. .find('.test-source pre')
  19. .text
  20. .strip
  21. .lines[0, 2]
  22. .reject { |line| line.include? 'qunit-' }
  23. .join
  24. end
  25. def failure_name(row)
  26. row
  27. .find('.test-message')
  28. .text
  29. .strip
  30. end
  31. def failed_count
  32. actual.find('.result .failed').text
  33. end
  34. def total_count
  35. actual.find('.result .total').text
  36. end
  37. end
  38. files = if (basename = ENV['QUNIT_TEST'])
  39. [basename]
  40. else
  41. Pathname
  42. .glob('public/assets/tests/qunit/*.js')
  43. .map { |elem| elem.basename(elem.extname).to_s }
  44. .sort
  45. end
  46. files.each do |elem|
  47. context "when testing #{elem.humanize}", authenticated_as: :user do
  48. # Some tests require an authenticated session.
  49. let(:needs_user) { elem.include?('form') || elem.include?('taskbar') }
  50. let(:user) { needs_user ? create(:agent) : false }
  51. it "#{elem.humanize} qunit tests" do
  52. visit "/tests_#{elem}"
  53. expect(page).to pass_qunit_test
  54. end
  55. end
  56. end
  57. end