Skip to content

Commit

Permalink
Render start and end dates for predecessor relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-contreras committed Nov 7, 2024
1 parent 9f32e9b commit 4a23389
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@
if should_display_start_and_end_dates?
flex.with_row(flex_layout: true, justify_content: :flex_start, align_items: :center, style: "gap: 0.25rem;") do |start_and_end_dates_row|
start_and_end_dates_row.with_column do
render(Primer::Beta::Octicon.new(icon: :calendar, color: :muted))
icon = if follows?
:calendar
elsif precedes?
:pin
end

render(Primer::Beta::Octicon.new(icon:, color: :muted))
end
start_and_end_dates_row.with_column do
render(Primer::Beta::Text.new(color: :muted)) do
format_date(related_work_package.start_date) + " - " + format_date(related_work_package.due_date)
"#{format_date(related_work_package.start_date)} - #{format_date(related_work_package.due_date)}"
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def should_display_start_and_end_dates?
relation.follows? || relation.precedes?
end

def follows?
relation.relation_type_for(work_package) == Relation::TYPE_FOLLOWS
end

def precedes?
relation.relation_type_for(work_package) == Relation::TYPE_PRECEDES
end

def edit_path
if parent_child_relationship?
raise NotImplementedError, "Children relationships are not editable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
let(:type1) { create(:type) }
let(:type2) { create(:type) }

let(:to1) { create(:work_package, type: type1, project:) }
let(:to1) { create(:work_package, type: type1, project:, start_date: Date.current, due_date: Date.current + 1.week) }
let(:to2) { create(:work_package, type: type2, project:) }
let(:to3) { create(:work_package, type: type1, project:) }
let(:from1) { create(:work_package, type: type1, project:) }
Expand Down Expand Up @@ -104,36 +104,62 @@ def label_for_relation_type(relation_type)
scroll_to_element relations_panel
expect(page).to have_css(relations_panel_selector)

[relation1, relation2].each do |relation|
target = relation.to == work_package ? "from" : "to"
target_relation_type = target == "from" ? relation.reverse_type : relation.relation_type

within(relations_panel) do
expect(page).to have_text(relation.to.type.name.upcase)
expect(page).to have_text(relation.to.id)
expect(page).to have_text(relation.to.status.name)
expect(page).to have_text(relation.to.subject)
# We reference the reverse type as the "from" node of the relation
# is the currently visited work package, and the "to" node is the
# relation target. From the current user's perspective on the work package's
# page, this is the "reverse" relation.
expect(page).to have_text(label_for_relation_type(target_relation_type))
end
target = relation1.to == work_package ? "from" : "to"
target_relation_type = target == "from" ? relation1.reverse_type : relation1.relation_type

relation_row = relations_panel.find("[data-test-selector='op-relation-row-#{relation1.id}']")

within(relations_panel) do
# We reference the reverse type as the "from" node of the relation
# is the currently visited work package, and the "to" node is the
# relation target. From the current user's perspective on the work package's
# page, this is the "reverse" relation.
expect(page).to have_text(label_for_relation_type(target_relation_type))
end
within(relation_row) do
expect(page).to have_text(relation1.to.type.name.upcase)
expect(page).to have_text(relation1.to.id)
expect(page).to have_text(relation1.to.status.name)
expect(page).to have_text(relation1.to.subject)
expect(page).to have_text(I18n.l(relation1.to.start_date))
expect(page).to have_text(I18n.l(relation1.to.due_date))
end

relation_row = relations_panel.find("[data-test-selector='op-relation-row-#{relation2.id}']")

within(relations_panel) do
# We reference the reverse type as the "from" node of the relation
# is the currently visited work package, and the "to" node is the
# relation target. From the current user's perspective on the work package's
# page, this is the "reverse" relation.
expect(page).to have_text(label_for_relation_type(target_relation_type))
end

within(relation_row) do
expect(page).to have_text(relation2.to.type.name.upcase)
expect(page).to have_text(relation2.to.id)
expect(page).to have_text(relation2.to.status.name)
expect(page).to have_text(relation2.to.subject)
end

target = relation3.to == work_package ? "from" : "to"
target_relation_type = target == "from" ? relation3.reverse_type : relation3.relation_type

relation_row = relations_panel.find("[data-test-selector='op-relation-row-#{relation3.id}']")

within(relations_panel) do
expect(page).to have_text(relation3.to.type.name.upcase)
expect(page).to have_text(relation3.to.id)
expect(page).to have_text(relation3.to.status.name)
expect(page).to have_text(relation3.to.subject)
# We reference the relation type as the "from" node of the relation
# is not the currently visited work package. From the current user's
# perspective on the work package's page, this is the "forward" relation.
expect(page).to have_text(label_for_relation_type(target_relation_type))
end

within(relation_row) do
expect(page).to have_text(relation3.to.type.name.upcase)
expect(page).to have_text(relation3.to.id)
expect(page).to have_text(relation3.to.status.name)
expect(page).to have_text(relation3.to.subject)
end
end
end

Expand Down

0 comments on commit 4a23389

Please sign in to comment.