Skip to content

Commit

Permalink
all tests run for discovery.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Feb 20, 2024
1 parent 63bdc3a commit c6f0897
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 90 deletions.
3 changes: 1 addition & 2 deletions lib/trailblazer/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ module Workflow
require "trailblazer/workflow/test/assertions"

require "trailblazer/workflow/discovery"
require "trailblazer/workflow/discovery/present/event_table"
require "terminal-table" # TODO: only require when discovery is "loaded".

require "trailblazer/workflow/introspect"
require "trailblazer/workflow/introspect/iteration"
require "trailblazer/workflow/introspect/state_table"
require "trailblazer/workflow/introspect/event_table"
87 changes: 0 additions & 87 deletions lib/trailblazer/workflow/discovery/present/event_table.rb

This file was deleted.

85 changes: 85 additions & 0 deletions lib/trailblazer/workflow/introspect/event_table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
module Trailblazer
module Workflow
module Introspect
module EventTable
module_function

def call(iteration_set, render_ids: true, hide_lanes: [], lanes_cfg:, **)
rows = iteration_set.to_a.flat_map do |iteration|
start_positions = iteration.start_positions
start_task_position = iteration.start_task_position

lane_positions = render_lane_position_columns(start_positions, lanes_cfg: lanes_cfg)

# The resulting hash represents one row.
state_row = Hash[
"triggered event",
Present.readable_name_for_catch_event(*start_task_position.to_a, lanes_cfg: lanes_cfg),

*lane_positions
]

rows = [
state_row,
]

# FIXME: use developer for coloring.
# def bg_gray(str); "\e[47m#{str}\e[0m" end
if render_ids
triggered_event_id_column = {"triggered event" => Present.id_for_task(start_task_position)}

rows << render_lane_position_id_columns(start_positions, lanes_cfg: lanes_cfg)
.merge(triggered_event_id_column)
end

rows
end


lane_labels = lanes_cfg.collect { |id, cfg| cfg[:label] }

lane_labels = lane_labels - hide_lanes # TODO: extract, new feature.

columns = ["triggered event", *lane_labels]
Present::Table.render(columns, rows)
end

# @private
def render_lane_position_columns(start_positions, **options)
lane_positions = start_positions.to_a.flat_map do |lane_position|
lane_label = Present.lane_options_for(*lane_position.to_a, **options)[:label]

readable_lane_position = Present.readable_name_for_suspend_or_terminus(*lane_position.to_a, **options)

[
lane_label,
readable_lane_position
]
end
end

def render_lane_position_id_columns(start_positions, **options)
lane_position_ids = start_positions.to_a.flat_map do |lane_position|
# Present.readable_id_label(*lane_position.to_a, **options)
lane_label = lane_label_for(lane_position, **options) # FIXME: redundant in {#render_lane_position_columns}
id = Present.id_for_task(lane_position)

[
lane_label, # column name
id
]
end

_id_row = Hash[
*lane_position_ids, # TODO: this adds the remaining IDs.
]
end


def lane_label_for(lane_position, **options)
Present.lane_options_for(*lane_position.to_a, **options)[:label]
end
end
end # Introspect
end
end
4 changes: 3 additions & 1 deletion test/discovery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ def assert_position_after(actual_configuration, expected_ids, lanes:)
it "{Present::EventTable.call}" do
states, lanes_sorted, lanes_cfg = self.class.states()

cli_state_table_with_ids = Trailblazer::Workflow::Discovery::Present::EventTable.(states, render_ids: true, hide_lanes: ["approver"], lanes_cfg: lanes_cfg)
iteration_set = Trailblazer::Workflow::Introspect::Iteration::Set.from_discovered_states(states, lanes_cfg: lanes_cfg)

cli_state_table_with_ids = Trailblazer::Workflow::Introspect::EventTable.(iteration_set, render_ids: true, hide_lanes: ["approver"], lanes_cfg: lanes_cfg)
puts cli_state_table_with_ids
assert_equal cli_state_table_with_ids,
%(+-------------------------------+---------------------------------------------+---------------------------------------------+
Expand Down

0 comments on commit c6f0897

Please sign in to comment.