Skip to content

Commit

Permalink
test plan comment header is coming along nicely.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Feb 7, 2024
1 parent eb60e49 commit be83f93
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 32 deletions.
16 changes: 12 additions & 4 deletions lib/trailblazer/workflow/state/discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,30 @@ def self.render_cli_state_table(discovery_state_table)
) # 186 for laptop 13"
end

def self.readable_name_for_catch_event(position, envelope_icon: false)
def self.readable_name_for_catch_event(position, envelope_icon: false, lane_icons: {})
envelope_icon = "(✉)➔" # TODO: implement {envelope_icon} flag.
envelope_icon = "▶"

"#{position[:tuple][0]}: #{envelope_icon}[#{position[:comment][1]}]"
lane_name = position[:tuple][0]
lane_label = "#{lane_name}:"
lane_label = lane_icons[lane_name] if lane_icons.key?(lane_name)

"#{lane_label} #{envelope_icon}[#{position[:comment][1]}]"
end

def self.readable_name_for_resume_event(position, tuple: false)
def self.readable_name_for_resume_event(position, tuple: false, lane_icons: {})
resume_labels = position[:comment][1]

lane_name = position[:tuple][0]
lane_label = "#{lane_name}:"
lane_label = lane_icons[lane_name] if lane_icons.key?(lane_name)

catch_events = resume_labels.collect { |catch_label| "▶#{catch_label}" }
.join(" ")

return [position[:tuple][0], catch_events] if tuple

"#{position[:tuple][0]}: [#{catch_events}]"
"#{lane_label} [#{catch_events}]"
end

def self.render_cli_event_table(discovery_state_table, render_ids: false, hide_lanes: [])
Expand Down
53 changes: 27 additions & 26 deletions lib/trailblazer/workflow/state/discovery/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,17 @@ def self.render_structure(states, lanes:, additional_state_data:, task_map:)
end

# Render the "test plan" in readable form.
def self.render_comment_header(structure)
def self.render_comment_header(structure, lane_icons:)
cli_rows = structure.collect do |testing_row| # row = :start_position, :start_configuration, :expected_lane_positions
triggered_catch_event_label = Discovery.readable_name_for_catch_event(testing_row[:start_position])

# TODO: remove
start_configuration_cols = testing_row[:start_configuration].collect do |lane_position|
content = Discovery.readable_name_for_resume_event(lane_position)
end.join(", ")
triggered_catch_event_label = Discovery.readable_name_for_catch_event(testing_row[:start_position], lane_icons: lane_icons)

start_configuration = testing_row[:start_configuration].collect do |lane_position|
Discovery.readable_name_for_resume_event(lane_position, tuple: true)
end

expected_lane_positions = testing_row[:expected_lane_positions].collect do |lane_position|
content = "#{readable_name_for_resume_event_or_terminus(lane_position)}"
end.join(", ")
readable_name_for_resume_event_or_terminus(lane_position, lane_icons: lane_icons, tuple: true)
end

Hash[
"triggered catch",
Expand All @@ -76,10 +71,6 @@ def self.render_comment_header(structure)
"input ctx",
nil,

# TODO: remove
"start configuration",
start_configuration_cols,

:start_configuration,
start_configuration,

Expand All @@ -90,26 +81,29 @@ def self.render_comment_header(structure)
end


cli_rows = format_start_positions_for(cli_rows, column_name: :start_configuration)
cli_rows = format_start_positions_for(cli_rows, column_name: :start_configuration, lane_icons: lane_icons, formatted_col_name: :start_configuration_formatted)
cli_rows = format_start_positions_for(cli_rows, column_name: "expected lane positions", lane_icons: lane_icons, formatted_col_name: :expected_lane_positions_formatted)

Hirb::Helpers::Table.render(cli_rows, fields: [
"triggered catch",
:start_configuration_formatted,
"expected lane positions",
:expected_lane_positions_formatted,
],
max_width: 186,
) # 186 for laptop 13"
end

def self.format_start_positions_for(rows, column_name:)
# pp rows

def self.format_start_positions_for(rows, column_name:, formatted_col_name:, lane_icons:)
# Find out the longest entry per lane.
columns = {}

rows.each do |row|
row[column_name].each do |lane_label, catch_label|
columns[lane_label] ||= []
columns[lane_label] << catch_label.length

length = catch_label ? catch_label.length : 0 # DISCUSS: why can {catch_label} be nil?

columns[lane_label] << length
end
end

Expand All @@ -119,13 +113,16 @@ def self.format_start_positions_for(rows, column_name:)
rows = rows.collect do |row|
columns = row[column_name].collect do |lane_label, catch_label|
col_length = columns_2_length[lane_label]
lane_label = lane_icons[lane_label]

catch_label = "" if catch_label.nil? # DISCUSS: why can {catch_label} be nil?

"#{lane_label}: " + catch_label.ljust(col_length, " ")
"#{lane_label} " + catch_label.ljust(col_length, " ")
end

content = columns.join(" | ")
content = columns.join(" ")

row = row.merge(:start_configuration_formatted => content)
row = row.merge(formatted_col_name => content)
end

rows
Expand Down Expand Up @@ -158,13 +155,17 @@ def self.serialize_lane_position(lane_position, lanes:)
}
end

def self.readable_name_for_resume_event_or_terminus(position)
def self.readable_name_for_resume_event_or_terminus(position, lane_icons:, tuple: false)
if position[:comment][0] == :terminus
terminus_label = "End.#{position[:comment][1]}"
return "#{position[:tuple][0]}: ◉#{terminus_label}"

terminus_label = "◉End.#{position[:comment][1]}"
lane_label = lane_icons[position[:tuple][0]]

return [position[:tuple][0], terminus_label] if tuple
return "#{lane_label} #{terminus_label}"
end

Discovery.readable_name_for_resume_event(position)
Discovery.readable_name_for_resume_event(position, lane_icons: lane_icons, tuple: tuple)
end

end # Testing
Expand Down
23 changes: 21 additions & 2 deletions test/collaboration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,29 @@ def render_states(states, lanes:, additional_state_data:, task_map:)
# File.write "test/discovery_testing_json.json", testing_json
assert_equal testing_json, File.read("test/discovery_testing_json.json")

testing_comment_header = Trailblazer::Workflow::State::Discovery::Testing.render_comment_header(testing_structure)
testing_comment_header = Trailblazer::Workflow::State::Discovery::Testing.render_comment_header(testing_structure, lane_icons: {"UI" => "☝", "lifecycle" => "⛾", "approver" => "☑"})
puts testing_comment_header
assert_equal testing_comment_header,
%()
%(+----------------------+--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+
| triggered catch | start_configuration_formatted | expected_lane_positions_formatted |
+----------------------+--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+
| ☝ ▶[Create form] | ⛾ ▶Create ☝ ▶Create form ☑ ▶#<Trail... | ⛾ ▶Create ☝ ▶Create ☑ ▶#<Trail... |
| ☝ ▶[Create] | ⛾ ▶Create ☝ ▶Create ☑ ▶#<Trail... | ⛾ ▶Update ▶Notify approver ☝ ▶Update form ▶Notify approver ☑ ▶#<Trail... |
| ☝ ▶[Create] | ⛾ ▶Create ☝ ▶Create ☑ ▶#<Trail... | ⛾ ▶Create ☝ ▶Create ☑ ▶#<Trail... |
| ☝ ▶[Update form] | ⛾ ▶Update ▶Notify approver ☝ ▶Update form ▶Notify approver ☑ ▶#<Trail... | ⛾ ▶Update ▶Notify approver ☝ ▶Update ☑ ▶#<Trail... |
| ☝ ▶[Notify approver] | ⛾ ▶Update ▶Notify approver ☝ ▶Update form ▶Notify approver ☑ ▶#<Trail... | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Update form ▶Delete? form ▶Publish ☑ ◉End.fai... |
| ☝ ▶[Update] | ⛾ ▶Update ▶Notify approver ☝ ▶Update ☑ ▶#<Trail... | ⛾ ▶Notify approver ▶Update ☝ ▶Update form ▶Notify approver ☑ ▶#<Trail... |
| ☝ ▶[Notify approver] | ⛾ ▶Update ▶Notify approver ☝ ▶Update form ▶Notify approver ☑ ▶#<Trail... | ⛾ ▶Revise ☝ ▶Revise form ☑ ◉End.suc... |
| ☝ ▶[Delete? form] | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Update form ▶Delete? form ▶Publish | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Delete ▶Cancel ☑ ◉End.fai... |
| ☝ ▶[Publish] | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Update form ▶Delete? form ▶Publish | ⛾ ▶Archive ☝ ▶Archive ☑ ◉End.fai... |
| ☝ ▶[Update] | ⛾ ▶Update ▶Notify approver ☝ ▶Update ☑ ▶#<Trail... | ⛾ ▶Update ▶Notify approver ☝ ▶Update ☑ ▶#<Trail... |
| ☝ ▶[Revise form] | ⛾ ▶Revise ☝ ▶Revise form | ⛾ ▶Revise ☝ ▶Revise ☑ ◉End.suc... |
| ☝ ▶[Delete] | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Delete ▶Cancel | ⛾ ◉End.success ☝ ◉End.success ☑ ◉End.fai... |
| ☝ ▶[Cancel] | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Delete ▶Cancel | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Update form ▶Delete? form ▶Publish ☑ ◉End.fai... |
| ☝ ▶[Archive] | ⛾ ▶Archive ☝ ▶Archive | ⛾ ◉End.success ☝ ◉End.success ☑ ◉End.fai... |
| ☝ ▶[Revise] | ⛾ ▶Revise ☝ ▶Revise | ⛾ ▶Revise ▶Notify approver ☝ ▶Update form ▶Notify approver ☑ ◉End.suc... |
+----------------------+--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+
15 rows in set)



Expand Down

0 comments on commit be83f93

Please sign in to comment.