Commit bd24f3ab authored by Maxime Orefice's avatar Maxime Orefice Committed by Shinya Maeda

Fix existing_errors for AccessibilityReportsComparer

This commit fixes how we calculate our existing_errors between
2 accessibility reports. Instead of returning all existing errors
from the base report we are now getting the intersection between
the base and the head report.
parent b4c3ebcd
...@@ -9,46 +9,44 @@ module Gitlab ...@@ -9,46 +9,44 @@ module Gitlab
STATUS_SUCCESS = 'success' STATUS_SUCCESS = 'success'
STATUS_FAILED = 'failed' STATUS_FAILED = 'failed'
attr_reader :base_reports, :head_reports attr_reader :base_report, :head_report
def initialize(base_reports, head_reports) def initialize(base_report, head_report)
@base_reports = base_reports || AccessibilityReports.new @base_report = base_report || AccessibilityReports.new
@head_reports = head_reports @head_report = head_report
end end
def status def status
head_reports.errors_count > 0 ? STATUS_FAILED : STATUS_SUCCESS head_report.errors_count > 0 ? STATUS_FAILED : STATUS_SUCCESS
end end
def existing_errors def existing_errors
strong_memoize(:existing_errors) do strong_memoize(:existing_errors) do
base_reports.all_errors base_report.all_errors & head_report.all_errors
end end
end end
def new_errors def new_errors
strong_memoize(:new_errors) do strong_memoize(:new_errors) do
head_reports.all_errors - base_reports.all_errors head_report.all_errors - base_report.all_errors
end end
end end
def resolved_errors def resolved_errors
strong_memoize(:resolved_errors) do strong_memoize(:resolved_errors) do
base_reports.all_errors - head_reports.all_errors base_report.all_errors - head_report.all_errors
end end
end end
def errors_count
head_reports.errors_count
end
def resolved_count def resolved_count
resolved_errors.size resolved_errors.size
end end
def total_count def total_count
existing_errors.size + new_errors.size head_report.errors_count
end end
alias_method :errors_count, :total_count
end end
end end
end end
......
...@@ -51,8 +51,8 @@ RSpec.describe AccessibilityReportsComparerEntity do ...@@ -51,8 +51,8 @@ RSpec.describe AccessibilityReportsComparerEntity do
expect(subject[:status]).to eq(Gitlab::Ci::Reports::AccessibilityReportsComparer::STATUS_FAILED) 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[: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[: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[:existing_errors]).to be_empty
expect(subject[:summary]).to include(total: 2, resolved: 1, errored: 1) expect(subject[:summary]).to include(total: 1, resolved: 1, errored: 1)
end end
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