Skip to content

Commit

Permalink
[#59184] specs for ordering life cycle gates
Browse files Browse the repository at this point in the history
  • Loading branch information
EinLama committed Jan 6, 2025
1 parent 8f3f7c7 commit 73a8642
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def joins
def order(scope)
with_raise_on_invalid do
scope.where("steps.def_id = :def_id OR steps.def_id IS NULL", def_id: life_cycle_step_definition.id)
# TODO: do not attempt to order by end_date for gates
# Note that a gate does not define an end_date. This code still works.
.order("steps.start_date #{direction}, steps.end_date #{direction}")
end
end
Expand Down
133 changes: 91 additions & 42 deletions spec/features/projects/lists/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,54 +277,103 @@
end

context "when sorting by life cycle", with_flag: { stages_and_gates: true } do
let(:stage_def) { create(:project_stage_definition) }
let(:stage) do
create(:project_stage,
project:,
definition: stage_def,
start_date: Date.new(2025, 1, 1),
end_date: Date.new(2025, 1, 13))
end
let!(:other_stage) do
create(:project_stage,
project: public_project,
definition: stage_def,
start_date: Date.new(2025, 2, 12),
end_date: Date.new(2025, 2, 20))
end
let!(:last_stage) do
create(:project_stage,
project: development_project,
definition: stage_def,
start_date: other_stage.start_date,
end_date: other_stage.end_date + 1.day)
end
context "when sorting by life cycle stage definition" do
let(:stage_def) { create(:project_stage_definition) }
let(:stage) do
create(:project_stage,
project:,
definition: stage_def,
start_date: Date.new(2025, 1, 1),
end_date: Date.new(2025, 1, 13))
end
let!(:other_stage) do
create(:project_stage,
project: public_project,
definition: stage_def,
start_date: Date.new(2025, 2, 12),
end_date: Date.new(2025, 2, 20))
end
let!(:last_stage) do
create(:project_stage,
project: development_project,
definition: stage_def,
start_date: other_stage.start_date,
end_date: other_stage.end_date + 1.day)
end

before do
Setting.enabled_projects_columns += [stage.column_name]
visit projects_path
end
before do
Setting.enabled_projects_columns += [stage.column_name]
visit projects_path
end

it "sorts projects by life cycle stage asc" do
projects_page.click_table_header_to_open_action_menu(stage.column_name)
projects_page.sort_via_action_menu(stage.column_name, direction: :asc)
wait_for_reload
it "sorts projects by life cycle stage asc" do
projects_page.click_table_header_to_open_action_menu(stage.column_name)
projects_page.sort_via_action_menu(stage.column_name, direction: :asc)
wait_for_reload

projects_page.expect_project_at_place(project, 1)
# For the next two projects, the start date is the same, but the end date differs.
# Ensure the end date is used as a secondary sorting criterion:
projects_page.expect_project_at_place(public_project, 2)
projects_page.expect_project_at_place(development_project, 3)
end

it "sorts projects by life cycle stage desc" do
projects_page.click_table_header_to_open_action_menu(stage.column_name)
projects_page.sort_via_action_menu(stage.column_name, direction: :desc)
wait_for_reload

projects_page.expect_project_at_place(project, 1)
# For the next two projects, the start date is the same, but the end date differs.
# Ensure the end date is used as a secondary sorting criterion:
projects_page.expect_project_at_place(public_project, 2)
projects_page.expect_project_at_place(development_project, 3)
projects_page.expect_project_at_place(development_project, 4)
projects_page.expect_project_at_place(public_project, 5)
projects_page.expect_project_at_place(project, 6)
end
end

it "sorts projects by life cycle stage desc" do
projects_page.click_table_header_to_open_action_menu(stage.column_name)
projects_page.sort_via_action_menu(stage.column_name, direction: :desc)
wait_for_reload
context "when sorting by life cycle gate definition" do
let(:gate_def) { create(:project_gate_definition) }
let(:gate) do
create(:project_gate,
project:,
definition: gate_def,
date: Date.new(2025, 1, 1))
end
let!(:other_gate) do
create(:project_gate,
project: public_project,
definition: gate_def,
date: Date.new(2025, 2, 12))
end
let!(:last_gate) do
create(:project_gate,
project: development_project,
definition: gate_def,
date: other_gate.date + 1.day)
end

before do
Setting.enabled_projects_columns += [gate.column_name]
visit projects_path
end

it "sorts projects by life cycle gate asc" do
projects_page.click_table_header_to_open_action_menu(gate.column_name)
projects_page.sort_via_action_menu(gate.column_name, direction: :asc)
wait_for_reload

projects_page.expect_project_at_place(project, 1)
projects_page.expect_project_at_place(public_project, 2)
projects_page.expect_project_at_place(development_project, 3)
end

it "sorts projects by life cycle gate desc" do
projects_page.click_table_header_to_open_action_menu(gate.column_name)
projects_page.sort_via_action_menu(gate.column_name, direction: :desc)
wait_for_reload

projects_page.expect_project_at_place(development_project, 4)
projects_page.expect_project_at_place(public_project, 5)
projects_page.expect_project_at_place(project, 6)
projects_page.expect_project_at_place(development_project, 4)
projects_page.expect_project_at_place(public_project, 5)
projects_page.expect_project_at_place(project, 6)
end
end
end
end

0 comments on commit 73a8642

Please sign in to comment.