Commit 7ff19f72 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'mo-fix-accessibility-report-comparer' into 'master'

Fix existing_errors for AccessibilityReportsComparer

See merge request gitlab-org/gitlab!49245
parents 2d6272be bd24f3ab
......@@ -9,46 +9,44 @@ module Gitlab
STATUS_SUCCESS = 'success'
STATUS_FAILED = 'failed'
attr_reader :base_reports, :head_reports
attr_reader :base_report, :head_report
def initialize(base_reports, head_reports)
@base_reports = base_reports || AccessibilityReports.new
@head_reports = head_reports
def initialize(base_report, head_report)
@base_report = base_report || AccessibilityReports.new
@head_report = head_report
end
def status
head_reports.errors_count > 0 ? STATUS_FAILED : STATUS_SUCCESS
head_report.errors_count > 0 ? STATUS_FAILED : STATUS_SUCCESS
end
def existing_errors
strong_memoize(:existing_errors) do
base_reports.all_errors
base_report.all_errors & head_report.all_errors
end
end
def new_errors
strong_memoize(:new_errors) do
head_reports.all_errors - base_reports.all_errors
head_report.all_errors - base_report.all_errors
end
end
def resolved_errors
strong_memoize(:resolved_errors) do
base_reports.all_errors - head_reports.all_errors
base_report.all_errors - head_report.all_errors
end
end
def errors_count
head_reports.errors_count
end
def resolved_count
resolved_errors.size
end
def total_count
existing_errors.size + new_errors.size
head_report.errors_count
end
alias_method :errors_count, :total_count
end
end
end
......
......@@ -51,8 +51,8 @@ RSpec.describe AccessibilityReportsComparerEntity do
expect(subject[:status]).to eq(Gitlab::Ci::Reports::AccessibilityReportsComparer::STATUS_FAILED)
expect(subject[:resolved_errors].first).to include(:code, :type, :type_code, :message, :context, :selector, :runner, :runner_extras)
expect(subject[:new_errors].first).to include(:code, :type, :type_code, :message, :context, :selector, :runner, :runner_extras)
expect(subject[:existing_errors].first).to include(:code, :type, :type_code, :message, :context, :selector, :runner, :runner_extras)
expect(subject[:summary]).to include(total: 2, resolved: 1, errored: 1)
expect(subject[:existing_errors]).to be_empty
expect(subject[:summary]).to include(total: 1, resolved: 1, errored: 1)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment