2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2018-12-19 14:47:15 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
RSpec.describe 'QUnit', type: :system, authenticated_as: false, set_up: true, websocket: false, time_zone: 'Europe/London' do
|
|
|
|
matcher :pass_qunit_test do
|
|
|
|
match do
|
|
|
|
actual.has_css?('.total', wait: 120)
|
2018-12-19 14:47:15 +00:00
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
actual.has_css? '.result .failed', text: '0', wait: 0
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
failure_message do
|
|
|
|
messages = actual
|
|
|
|
.all('.qunit-assert-list li.fail')
|
|
|
|
.map { |elem| "> #{failure_name(elem)}\n#{failure_source(elem)}" }
|
|
|
|
.join("\n")
|
2019-06-07 11:28:58 +00:00
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
"Failed #{failed_count} out of #{total_count}:\n#{messages}"
|
2020-07-06 15:03:28 +00:00
|
|
|
end
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
def failure_source(row)
|
|
|
|
row
|
|
|
|
.find('.test-source pre')
|
|
|
|
.text
|
|
|
|
.strip
|
|
|
|
.lines[0, 2]
|
|
|
|
.reject { |line| line.include? 'qunit-' }
|
|
|
|
.join
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|
2020-05-25 10:01:49 +00:00
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
def failure_name(row)
|
|
|
|
row
|
|
|
|
.find('.test-message')
|
|
|
|
.text
|
|
|
|
.strip
|
2020-05-25 10:01:49 +00:00
|
|
|
end
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
def failed_count
|
|
|
|
actual.find('.result .failed').text
|
2020-05-25 10:01:49 +00:00
|
|
|
end
|
2020-08-17 10:03:40 +00:00
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
def total_count
|
|
|
|
actual.find('.result .total').text
|
2020-09-24 11:34:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
files = if (basename = ENV['QUNIT_TEST'])
|
|
|
|
[basename]
|
|
|
|
else
|
|
|
|
Pathname
|
|
|
|
.glob('public/assets/tests/qunit/*.js')
|
|
|
|
.map { |elem| elem.basename(elem.extname).to_s }
|
|
|
|
.sort
|
|
|
|
end
|
2020-04-27 22:43:33 +00:00
|
|
|
|
2021-10-14 14:35:12 +00:00
|
|
|
files.each do |elem|
|
|
|
|
it elem.humanize do
|
|
|
|
visit "/tests_#{elem}"
|
|
|
|
expect(page).to pass_qunit_test
|
2020-04-27 22:43:33 +00:00
|
|
|
end
|
|
|
|
end
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|