mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Fix broken test
Make expect_schedule helper smarter by deriving the ignore_non_working_days information from the actual chart if not yet defined. This gives more accurate diffable information.
This commit is contained in:
@@ -31,6 +31,7 @@ module ScheduleHelpers
|
||||
LINE = "%<id>s | %<days>s |".freeze
|
||||
|
||||
def self.normalized_to_s(expected_chart, actual_chart)
|
||||
normalize_ignore_non_working_days_information(expected_chart, actual_chart)
|
||||
order = expected_chart.work_package_names
|
||||
id_column_size = [expected_chart, actual_chart].map(&:id_column_size).max
|
||||
first_day = [expected_chart, actual_chart].map(&:first_day).min
|
||||
@@ -40,6 +41,20 @@ module ScheduleHelpers
|
||||
.map(&:to_s)
|
||||
end
|
||||
|
||||
# Define ignore_non_working_days attribute from +actual_chart+ when not
|
||||
# explicitly set in +expected_chart+.
|
||||
def self.normalize_ignore_non_working_days_information(expected_chart, actual_chart)
|
||||
expected_chart.work_packages_attributes.each do |work_package_attributes|
|
||||
next if work_package_attributes.has_key?(:ignore_non_working_days)
|
||||
|
||||
name = work_package_attributes[:name]
|
||||
actual_attributes = actual_chart.work_package_attributes(name)
|
||||
next if actual_attributes.nil? || !actual_attributes.has_key?(:ignore_non_working_days)
|
||||
|
||||
work_package_attributes[:ignore_non_working_days] = actual_attributes[:ignore_non_working_days]
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(id_column_size:, days_column_size:)
|
||||
@id_column_size = id_column_size
|
||||
@days_column_size = days_column_size
|
||||
|
||||
@@ -29,15 +29,6 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe ScheduleHelpers::ChartRepresenter do
|
||||
let(:fake_today) { Date.new(2022, 6, 16) } # Thursday 16 June 2022
|
||||
let(:monday) { Date.new(2022, 6, 20) } # Monday 20 June
|
||||
let(:tuesday) { Date.new(2022, 6, 21) }
|
||||
let(:wednesday) { Date.new(2022, 6, 22) }
|
||||
let(:thursday) { Date.new(2022, 6, 23) }
|
||||
let(:friday) { Date.new(2022, 6, 24) }
|
||||
let(:saturday) { Date.new(2022, 6, 25) }
|
||||
let(:sunday) { Date.new(2022, 6, 26) }
|
||||
|
||||
describe '#normalized_to_s' do
|
||||
shared_let(:week_days) { week_with_saturday_and_sunday_as_weekend }
|
||||
|
||||
@@ -188,5 +179,91 @@ describe ScheduleHelpers::ChartRepresenter do
|
||||
expect(first_header).to eq(second_header)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when expected chart does not have working days information' do
|
||||
def to_headers(charts)
|
||||
charts.map { _1.split("\n").first }
|
||||
end
|
||||
|
||||
it 'gets it from actual chart information' do
|
||||
# in real tests, actual will probably be created from WorkPackage instances
|
||||
actual_chart =
|
||||
ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)
|
||||
days | MTWTFSS |
|
||||
main | XXXXX | working days include weekends
|
||||
other | X..X | working days work week
|
||||
CHART
|
||||
expected_chart =
|
||||
ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)
|
||||
days | MTWTFSS |
|
||||
main | XXXXX |
|
||||
other | X..X |
|
||||
CHART
|
||||
|
||||
normalized_expected, normalized_actual =
|
||||
described_class
|
||||
.normalized_to_s(expected_chart, actual_chart)
|
||||
|
||||
expect(normalized_actual).to eq(normalized_expected)
|
||||
end
|
||||
|
||||
it 'ignores working days information for extra work packages not defined in actual' do
|
||||
initial_actual_chart =
|
||||
ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)
|
||||
days | MTWTFSS |
|
||||
main | X..X |
|
||||
CHART
|
||||
initial_expected_chart =
|
||||
ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)
|
||||
days | MTWTFSS |
|
||||
main | X..X |
|
||||
extra | |
|
||||
CHART
|
||||
|
||||
expect { described_class.normalized_to_s(initial_expected_chart, initial_actual_chart) }
|
||||
.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context 'when expected chart has different working days information from actual' do
|
||||
def to_headers(charts)
|
||||
charts.map { _1.split("\n").first }
|
||||
end
|
||||
|
||||
it 'use each information from each side' do
|
||||
# in real tests, actual will probably be created from WorkPackage instances
|
||||
actual_chart =
|
||||
ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)
|
||||
days | MTWTFSS |
|
||||
main | XXXXXXXX | working days include weekends
|
||||
other | X..X | working days work week
|
||||
foo | X..X |
|
||||
CHART
|
||||
expected_chart =
|
||||
ScheduleHelpers::ChartBuilder.new.parse(<<~CHART)
|
||||
days | MTWTFSS |
|
||||
main | XXXXX..X | working days work week
|
||||
other | XXXX | working days include weekends
|
||||
foo | X..X |
|
||||
CHART
|
||||
|
||||
normalized_expected, normalized_actual =
|
||||
described_class
|
||||
.normalized_to_s(expected_chart, actual_chart)
|
||||
|
||||
expect(normalized_actual).to eq(<<~CHART.strip)
|
||||
days | MTWTFSS |
|
||||
main | XXXXXXXX |
|
||||
other | X..X |
|
||||
foo | X..X |
|
||||
CHART
|
||||
expect(normalized_expected).to eq(<<~CHART.strip)
|
||||
days | MTWTFSS |
|
||||
main | XXXXX..X |
|
||||
other | XXXX |
|
||||
foo | X..X |
|
||||
CHART
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -168,8 +168,8 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
|
||||
job.perform_now(user_id: user.id, previous_working_days:)
|
||||
expect(WorkPackage.all).to match_schedule(<<~CHART)
|
||||
days | MTWTFSS |
|
||||
predecessor | X▓X ░░ | working days work week
|
||||
follower | ░ XXX | working days include weekends
|
||||
predecessor | X▓X ░░ |
|
||||
follower | ░ XXX |
|
||||
CHART
|
||||
end
|
||||
|
||||
@@ -343,7 +343,7 @@ RSpec.describe WorkPackages::ApplyWorkingDaysChangeJob do
|
||||
job.perform_now(user_id: user.id, previous_working_days:)
|
||||
expect(WorkPackage.all).to match_schedule(<<~CHART)
|
||||
days | MTWTFSS |
|
||||
work_package | XXXX ░░ | working days include weekends
|
||||
work_package | XXXX ░░ |
|
||||
CHART
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user