Skip to content

Commit

Permalink
we can show the "intended outcome" in the test plan.
Browse files Browse the repository at this point in the history
  • Loading branch information
apotonick committed Feb 7, 2024
1 parent 72fb0ed commit d80f37d
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 42 deletions.
4 changes: 4 additions & 0 deletions lib/trailblazer/workflow/state/discovery/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def self.render_structure(states, lanes:, additional_state_data:, task_map:)
},
start_configuration: serialized_start_configuration,
expected_lane_positions: expected_lane_positions,

expected_outcome: additional_state_data[[state.state_from_discovery_fixme.object_id, :outcome]],
}
end
end
Expand All @@ -56,6 +58,8 @@ 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], lane_icons: lane_icons)

triggered_catch_event_label += " ⛞" if testing_row[:expected_outcome] == :failure # FIXME: what happens to :symbol after serialization?

start_configuration = testing_row[:start_configuration].collect do |lane_position|
Discovery.readable_name_for_resume_event(lane_position, tuple: true)
end
Expand Down
63 changes: 36 additions & 27 deletions test/collaboration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ def decider(ctx, decision: true, **)
[
start_position,
extended_initial_lane_positions,
{} # ctx_merge
{}, # ctx_merge
{outcome: :success} # config_payload
]
]

Expand All @@ -231,17 +232,17 @@ def decider(ctx, decision: true, **)
run_multiple_times = {
# suspend after Notify approver in lifecycle
# We're "clicking" the [Notify_approver] button again, this time to get rejected.
Trailblazer::Activity::Introspect.Nodes(lane_activity_ui, id: "catch-before-#{ui_notify_approver}").task => {ctx_merge: {decision: false}},
Trailblazer::Activity::Introspect.Nodes(lane_activity_ui, id: "catch-before-#{ui_notify_approver}").task => {ctx_merge: {decision: false}, config_payload: {outcome: :failure}},

# Click [UI Create] again, with invalid data.
Trailblazer::Activity::Introspect.Nodes(lane_activity_ui, id: "catch-before-#{ui_create}").task => {ctx_merge: {create: false}}, # lifecycle create is supposed to fail.
Trailblazer::Activity::Introspect.Nodes(lane_activity_ui, id: "catch-before-#{ui_create}").task => {ctx_merge: {create: false}, config_payload: {outcome: :failure}}, # lifecycle create is supposed to fail.

# Click [UI Update] again, with invalid data.
Trailblazer::Activity::Introspect.Nodes(lane_activity_ui, id: "catch-before-#{ui_update}").task => {ctx_merge: {update: false}}, # lifecycle create is supposed to fail.
Trailblazer::Activity::Introspect.Nodes(lane_activity_ui, id: "catch-before-#{ui_update}").task => {ctx_merge: {update: false}, config_payload: {outcome: :failure}}, # lifecycle create is supposed to fail.
}

while resumes_to_invoke.any?
(start_position, lane_positions, ctx_merge) = resumes_to_invoke.shift
(start_position, lane_positions, ctx_merge, config_payload) = resumes_to_invoke.shift
puts "~~~~~~~~~"

ctx = {seq: []}.merge(ctx_merge)
Expand All @@ -251,7 +252,8 @@ def decider(ctx, decision: true, **)
resumes_to_invoke << [
start_position,
lane_positions, # same positions as the original situation.
do_again_config[:ctx_merge]
do_again_config[:ctx_merge],
do_again_config[:config_payload]
]

already_visited_catch_events_again[start_task] = true
Expand All @@ -274,9 +276,13 @@ def decider(ctx, decision: true, **)
message_flow: extended_message_flow,
)

# 3. optional feature: outcome marking
additional_state_data[[state.object_id, :outcome]] = config_payload[:outcome]


# 1. optional feature: tracing
state_data << ctx.inspect # context after. DISCUSS: use tracing?
additional_state_data[state.object_id] = state_data
additional_state_data[[state.object_id, :ctx]] = state_data

# 2. optional feature: remember stop configuration so we can use that in a test.
# raise configuration.inspect
Expand All @@ -300,7 +306,8 @@ def decider(ctx, decision: true, **)
resumes_to_invoke << [
Trailblazer::Workflow::Collaboration::Position.new(last_lane, resume_event),
configuration.lane_positions,
{}
{},
{outcome: :success}
]
end

Expand Down Expand Up @@ -519,6 +526,8 @@ def render_states(states, lanes:, additional_state_data:, task_map:)
This event is possible because process_model is in configuration ABC ("state")
=end
# pp additional_state_data

testing_structure = Trailblazer::Workflow::State::Discovery::Testing.render_structure(
states,
lanes: {lane_activity => "lifecycle", lane_activity_ui => "UI", approver_activity => "approver"},
Expand All @@ -533,25 +542,25 @@ def render_states(states, lanes:, additional_state_data:, task_map:)
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 ☑ ▶#<Trailb... | ⛾ ▶Create ☝ ▶Create ☑ ▶#<Trailb... |
| ☝ ▶Create | ⛾ ▶Create ☝ ▶Create ☑ ▶#<Trailb... | ⛾ ▶Update ▶Notify approver ☝ ▶Update form ▶Notify approver ☑ ▶#<Trailb... |
| ☝ ▶Create | ⛾ ▶Create ☝ ▶Create ☑ ▶#<Trailb... | ⛾ ▶Create ☝ ▶Create ☑ ▶#<Trailb... |
| ☝ ▶Update form | ⛾ ▶Update ▶Notify approver ☝ ▶Update form ▶Notify approver ☑ ▶#<Trailb... | ⛾ ▶Update ▶Notify approver ☝ ▶Update ☑ ▶#<Trailb... |
| ☝ ▶Notify approver | ⛾ ▶Update ▶Notify approver ☝ ▶Update form ▶Notify approver ☑ ▶#<Trailb... | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Update form ▶Delete? form ▶Publish ☑ ◉End.fail... |
| ☝ ▶Update | ⛾ ▶Update ▶Notify approver ☝ ▶Update ☑ ▶#<Trailb... | ⛾ ▶Notify approver ▶Update ☝ ▶Update form ▶Notify approver ☑ ▶#<Trailb... |
| ☝ ▶Notify approver | ⛾ ▶Update ▶Notify approver ☝ ▶Update form ▶Notify approver ☑ ▶#<Trailb... | ⛾ ▶Revise ☝ ▶Revise form ☑ ◉End.succ... |
| ☝ ▶Delete? form | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Update form ▶Delete? form ▶Publish | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Delete ▶Cancel ☑ ◉End.fail... |
| ☝ ▶Publish | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Update form ▶Delete? form ▶Publish | ⛾ ▶Archive ☝ ▶Archive ☑ ◉End.fail... |
| ☝ ▶Update | ⛾ ▶Update ▶Notify approver ☝ ▶Update ☑ ▶#<Trailb... | ⛾ ▶Update ▶Notify approver ☝ ▶Update ☑ ▶#<Trailb... |
| ☝ ▶Revise form | ⛾ ▶Revise ☝ ▶Revise form | ⛾ ▶Revise ☝ ▶Revise ☑ ◉End.succ... |
| ☝ ▶Delete | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Delete ▶Cancel | ⛾ ◉End.success ☝ ◉End.success ☑ ◉End.fail... |
| ☝ ▶Cancel | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Delete ▶Cancel | ⛾ ▶Publish ▶Delete ▶Update ☝ ▶Update form ▶Delete? form ▶Publish ☑ ◉End.fail... |
| ☝ ▶Archive | ⛾ ▶Archive ☝ ▶Archive | ⛾ ◉End.success ☝ ◉End.success ☑ ◉End.fail... |
| ☝ ▶Revise | ⛾ ▶Revise ☝ ▶Revise | ⛾ ▶Revise ▶Notify approver ☝ ▶Update form ▶Notify approver ☑ ◉End.succ... |
+--------------------+---------------------------------------------------------------------------------+---------------------------------------------------------------------------------+
%(+----------------------+--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+
| 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
45 changes: 30 additions & 15 deletions test/discovery_testing_json.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
]
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -175,7 +176,8 @@
]
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -263,7 +265,8 @@
]
]
}
]
],
"expected_outcome": "failure"
},
{
"start_position": {
Expand Down Expand Up @@ -354,7 +357,8 @@
]
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -446,7 +450,8 @@
"failure"
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -537,7 +542,8 @@
]
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -625,7 +631,8 @@
"success"
]
}
]
],
"expected_outcome": "failure"
},
{
"start_position": {
Expand Down Expand Up @@ -706,7 +713,8 @@
"failure"
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -784,7 +792,8 @@
"failure"
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -874,7 +883,8 @@
]
]
}
]
],
"expected_outcome": "failure"
},
{
"start_position": {
Expand Down Expand Up @@ -948,7 +958,8 @@
"success"
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -1021,7 +1032,8 @@
"failure"
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -1102,7 +1114,8 @@
"failure"
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -1172,7 +1185,8 @@
"failure"
]
}
]
],
"expected_outcome": "success"
},
{
"start_position": {
Expand Down Expand Up @@ -1248,6 +1262,7 @@
"success"
]
}
]
],
"expected_outcome": "success"
}
]

0 comments on commit d80f37d

Please sign in to comment.