Skip to content

Commit

Permalink
Replace schedule helpers with table helpers
Browse files Browse the repository at this point in the history
Schedule helpers helped well, but table helpers are more flexible.
  • Loading branch information
cbliard committed Dec 9, 2024
1 parent a82d72f commit 7f8da75
Show file tree
Hide file tree
Showing 23 changed files with 409 additions and 2,120 deletions.
32 changes: 17 additions & 15 deletions spec/features/admin/working_days_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
shared_let(:week_days) { week_with_saturday_and_sunday_as_weekend }
shared_let(:admin) { create(:admin) }

let_schedule(<<~CHART)
days | MTWTFSSmtwtfss |
earliest_work_package | XXXXX |
second_work_package | XX..XX |
follower | XXX | follows earliest_work_package, follows second_work_package
CHART
let_work_packages(<<~TABLE)
subject | MTWTFSSmtwtfss | scheduling mode | properties
earliest_work_package | XXXXX | manual |
second_work_package | XX..XX | manual |
follower | XXX | automatic | follows earliest_work_package, follows second_work_package
TABLE

let(:dialog) { Components::ConfirmationDialog.new }
let(:datepicker) { Components::DatepickerModal.new }
Expand All @@ -48,6 +48,8 @@

before do
visit admin_settings_working_days_and_hours_path
# wait for "holidays and closures" calendar to load
find(".fc-next-button")
end

describe "week days" do
Expand Down Expand Up @@ -81,12 +83,12 @@ def working_days_setting

expect(working_days_setting).to eq([1, 2, 3, 4, 5])

expect_schedule(WorkPackage.all, <<~CHART)
days | MTWTFSSmtwtfss |
expect_work_packages(WorkPackage.all, <<~TABLE)
subject | MTWTFSSmtwtfss |
earliest_work_package | XXXXX |
second_work_package | XX..XX |
follower | XXX |
CHART
TABLE
end

it "updates the values and saves the settings" do
Expand All @@ -112,12 +114,12 @@ def working_days_setting

expect(working_days_setting).to eq([2, 3, 4])

expect_schedule(WorkPackage.all, <<~CHART)
days | MTWTFSSmtwtfssmtwt |
expect_work_packages(WorkPackage.all, <<~TABLE)
subject | MTWTFSSmtwtfssmtwt |
earliest_work_package | XXX....XX |
second_work_package | X....XXX |
follower | XXX |
CHART
TABLE

# The updated work packages will have a journal entry informing about the change
wp_page = Pages::FullWorkPackage.new(earliest_work_package)
Expand Down Expand Up @@ -152,12 +154,12 @@ def working_days_setting
expect(page).to have_unchecked_field "Sunday"
expect(working_days_setting).to eq([1, 2, 3, 4, 5])

expect_schedule(WorkPackage.all, <<~CHART)
days | MTWTFSSmtwtfss |
expect_work_packages(WorkPackage.all, <<~TABLE)
subject | MTWTFSSmtwtfss |
earliest_work_package | XXXXX |
second_work_package | XX..XX |
follower | XXX |
CHART
TABLE
end

it "shows an error when a previous change to the working days configuration isn't processed yet" do
Expand Down
108 changes: 57 additions & 51 deletions spec/models/relation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,38 +131,44 @@
end

describe "#successor_soonest_start" do
let(:monday) { Date.current.next_occurring(:monday) }
let(:tuesday) { monday + 1.day }
let(:wednesday) { monday + 2.days }
let(:thursday) { monday + 3.days }
let(:friday) { monday + 4.days }

context "with a follows relation" do
let_schedule(<<~CHART)
days | MTWTFSS |
let_work_packages(<<~TABLE)
subject | MTWTFSS | properties
main | ] |
follower | | follows main
CHART
TABLE

it "returns predecessor due_date + 1" do
relation = schedule.follows_relation(from: "follower", to: "main")
expect(relation.successor_soonest_start).to eq(schedule.tuesday)
relation = _table.relation(successor: "follower")
expect(relation.successor_soonest_start).to eq(tuesday)
end
end

context "with a follows relation with predecessor having only start date" do
let_schedule(<<~CHART)
days | MTWTFSS |
let_work_packages(<<~TABLE)
subject | MTWTFSS | properties
main | [ |
follower | | follows main
CHART
TABLE

it "returns predecessor start_date + 1" do
relation = schedule.follows_relation(from: "follower", to: "main")
expect(relation.successor_soonest_start).to eq(schedule.tuesday)
relation = _table.relation(successor: "follower")
expect(relation.successor_soonest_start).to eq(tuesday)
end
end

context "with a non-follows relation" do
let_schedule(<<~CHART)
days | MTWTFSS |
let_work_packages(<<~TABLE)
subject | MTWTFSS |
main | X |
related | |
CHART
TABLE
let(:relation) { create(:relation, from: main, to: related) }

it "returns nil" do
Expand All @@ -171,77 +177,77 @@
end

context "with a follows relation with a lag" do
let_schedule(<<~CHART)
days | MTWTFSS |
let_work_packages(<<~TABLE)
subject | MTWTFSS | properties
main | X |
follower_a | | follows main with lag 0
follower_b | | follows main with lag 1
follower_c | | follows main with lag 3
CHART
TABLE

it "returns predecessor due_date + lag + 1" do
relation_a = schedule.follows_relation(from: "follower_a", to: "main")
expect(relation_a.successor_soonest_start).to eq(schedule.tuesday)
relation_a = _table.relation(successor: "follower_a")
expect(relation_a.successor_soonest_start).to eq(tuesday)

relation_b = schedule.follows_relation(from: "follower_b", to: "main")
expect(relation_b.successor_soonest_start).to eq(schedule.wednesday)
relation_b = _table.relation(successor: "follower_b")
expect(relation_b.successor_soonest_start).to eq(wednesday)

relation_c = schedule.follows_relation(from: "follower_c", to: "main")
expect(relation_c.successor_soonest_start).to eq(schedule.friday)
relation_c = _table.relation(successor: "follower_c")
expect(relation_c.successor_soonest_start).to eq(friday)
end
end

context "with a follows relation with a lag and with non-working days in the lag period" do
let_schedule(<<~CHART)
days | MTWTFSSmtw |
main | X░ ░ ░░ ░ |
let_work_packages(<<~TABLE)
subject | MTWTFSSmtw | properties
main | X░ ░ ░░ ░ |
follower_lag0 | ░ ░ ░░ ░ | follows main with lag 0
follower_lag1 | ░ ░ ░░ ░ | follows main with lag 1
follower_lag2 | ░ ░ ░░ ░ | follows main with lag 2
follower_lag3 | ░ ░ ░░ ░ | follows main with lag 3
CHART
TABLE

it "returns a date such as the number of working days between both work package is equal to the lag" do
set_work_week("monday", "wednesday", "friday")

relation_lag0 = schedule.follows_relation(from: "follower_lag0", to: "main")
expect(relation_lag0.successor_soonest_start).to eq(schedule.wednesday)
relation_lag0 = _table.relation(successor: "follower_lag0")
expect(relation_lag0.successor_soonest_start).to eq(wednesday)

relation_lag1 = schedule.follows_relation(from: "follower_lag1", to: "main")
expect(relation_lag1.successor_soonest_start).to eq(schedule.friday)
relation_lag1 = _table.relation(successor: "follower_lag1")
expect(relation_lag1.successor_soonest_start).to eq(friday)

relation_lag2 = schedule.follows_relation(from: "follower_lag2", to: "main")
expect(relation_lag2.successor_soonest_start).to eq(schedule.monday + 7.days)
relation_lag2 = _table.relation(successor: "follower_lag2")
expect(relation_lag2.successor_soonest_start).to eq(monday + 7.days)

relation_lag3 = schedule.follows_relation(from: "follower_lag3", to: "main")
expect(relation_lag3.successor_soonest_start).to eq(schedule.wednesday + 7.days)
relation_lag3 = _table.relation(successor: "follower_lag3")
expect(relation_lag3.successor_soonest_start).to eq(wednesday + 7.days)
end
end

context "with a follows relation with a lag, non-working days, and follower ignoring non-working days" do
let_schedule(<<~CHART)
days | MTWTFSSmtw |
main | X░ ░ ░░ ░ |
follower_lag0 | ░ ░ ░░ ░ | follows main with lag 0, working days include weekends
follower_lag1 | ░ ░ ░░ ░ | follows main with lag 1, working days include weekends
follower_lag2 | ░ ░ ░░ ░ | follows main with lag 2, working days include weekends
follower_lag3 | ░ ░ ░░ ░ | follows main with lag 3, working days include weekends
CHART
context "with a follows relation with a lag, non-working days, and followers ignoring non-working days" do
let_work_packages(<<~TABLE)
subject | MTWTFSSmtw | days counting | properties
main | X░ ░ ░░ ░ | working days only |
follower_lag0 | ░ ░ ░░ ░ | all days | follows main with lag 0
follower_lag1 | ░ ░ ░░ ░ | all days | follows main with lag 1
follower_lag2 | ░ ░ ░░ ░ | all days | follows main with lag 2
follower_lag3 | ░ ░ ░░ ░ | all days | follows main with lag 3
TABLE

it "returns predecessor due_date + lag + 1 (like without non-working days)" do
set_work_week("monday", "wednesday", "friday")

relation_lag0 = schedule.follows_relation(from: "follower_lag0", to: "main")
expect(relation_lag0.successor_soonest_start).to eq(schedule.tuesday)
relation_lag0 = _table.relation(successor: "follower_lag0")
expect(relation_lag0.successor_soonest_start).to eq(tuesday)

relation_lag1 = schedule.follows_relation(from: "follower_lag1", to: "main")
expect(relation_lag1.successor_soonest_start).to eq(schedule.wednesday)
relation_lag1 = _table.relation(successor: "follower_lag1")
expect(relation_lag1.successor_soonest_start).to eq(wednesday)

relation_lag2 = schedule.follows_relation(from: "follower_lag2", to: "main")
expect(relation_lag2.successor_soonest_start).to eq(schedule.thursday)
relation_lag2 = _table.relation(successor: "follower_lag2")
expect(relation_lag2.successor_soonest_start).to eq(thursday)

relation_lag3 = schedule.follows_relation(from: "follower_lag3", to: "main")
expect(relation_lag3.successor_soonest_start).to eq(schedule.friday)
relation_lag3 = _table.relation(successor: "follower_lag3")
expect(relation_lag3.successor_soonest_start).to eq(friday)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
end

it "returns work packages having start date or due date being in the given days of week" do
schedule =
create_schedule(<<~CHART)
days | MTWTFSS |
table =
create_table(<<~TABLE)
subject | MTWTFSS |
covered1 | XX |
covered2 | XX |
covered3 | X |
Expand All @@ -62,89 +62,89 @@
not_covered2 | X |
not_covered3 | XX |
not_covered4 | |
CHART
TABLE

expect(WorkPackage.covering_dates_and_days_of_week(**day_args[:tuesday]))
.to contain_exactly(
schedule.work_package("covered1"),
schedule.work_package("covered2"),
schedule.work_package("covered3"),
schedule.work_package("covered4"),
schedule.work_package("covered5")
table.work_package("covered1"),
table.work_package("covered2"),
table.work_package("covered3"),
table.work_package("covered4"),
table.work_package("covered5")
)
end

it "returns work packages having days between start date and due date being in the given days of week" do
schedule =
create_schedule(<<~CHART)
days | MTWTFSS |
table =
create_table(<<~TABLE)
subject | MTWTFSS |
covered1 | XXXX |
covered2 | XXX |
not_covered1 | XX |
not_covered2 | X |
CHART
TABLE

expect(WorkPackage.covering_dates_and_days_of_week(**day_args[:tuesday, :wednesday]))
.to contain_exactly(
schedule.work_package("covered1"),
schedule.work_package("covered2")
table.work_package("covered1"),
table.work_package("covered2")
)
end

context "if work package ignores non working days" do
it "does not returns it" do
create_schedule(<<~CHART)
days | MTWTFSS |
not_covered | XXXXXXX | working days include weekends
CHART
create_table(<<~TABLE)
subject | MTWTFSS | days counting
not_covered | XXXXXXX | all days
TABLE

expect(WorkPackage.covering_dates_and_days_of_week(**day_args[:wednesday]))
.to eq([])
end
end

it "does not return work packages having follows relation covering the given days of week" do
create_schedule(<<~CHART)
days | MTWTFSS |
create_table(<<~TABLE)
subject | MTWTFSS | properties
not_covered1 | X |
follower1 | X | follows not_covered1
not_covered2 | X |
follower2 | X | follows not_covered2
CHART
TABLE

expect(WorkPackage.covering_dates_and_days_of_week(**day_args[:tuesday, :thursday]))
.to eq([])
end

it "does not return work packages having follows relation with lag covering the given days of week" do
create_schedule(<<~CHART)
days | MTWTFSS |
create_table(<<~TABLE)
subject | MTWTFSS | properties
not_covered1 | X |
follower1 | X | follows not_covered1 with lag 3
not_covered2 | X |
follower2 | X | follows not_covered2 with lag 1
CHART
TABLE

expect(WorkPackage.covering_dates_and_days_of_week(**day_args[:tuesday, :thursday]))
.to eq([])
end

it "accepts a single day of week or an array of days" do
schedule =
create_schedule(<<~CHART)
days | MTWTFSS |
table =
create_table(<<~TABLE)
subject | MTWTFSS |
covered | X |
not_covered | X |
CHART
TABLE

single_value = day_args[:tuesday].transform_values { |v| Array(v).first }

expect(WorkPackage.covering_dates_and_days_of_week(**single_value))
.to eq([schedule.work_package("covered")])
.to eq([table.work_package("covered")])
expect(WorkPackage.covering_dates_and_days_of_week(**day_args[:tuesday]))
.to eq([schedule.work_package("covered")])
.to eq([table.work_package("covered")])
expect(WorkPackage.covering_dates_and_days_of_week(**day_args[:tuesday, :wednesday]))
.to eq([schedule.work_package("covered")])
.to eq([table.work_package("covered")])
end
end

Expand Down
Loading

0 comments on commit 7f8da75

Please sign in to comment.