From d80f37d1aa58cf6e27031c3a3ed0a299a50826cc Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Wed, 7 Feb 2024 17:40:39 +0100 Subject: [PATCH] we can show the "intended outcome" in the test plan. --- .../workflow/state/discovery/testing.rb | 4 ++ test/collaboration_test.rb | 63 +++++++++++-------- test/discovery_testing_json.json | 45 ++++++++----- 3 files changed, 70 insertions(+), 42 deletions(-) diff --git a/lib/trailblazer/workflow/state/discovery/testing.rb b/lib/trailblazer/workflow/state/discovery/testing.rb index c0be805..00a0fbd 100644 --- a/lib/trailblazer/workflow/state/discovery/testing.rb +++ b/lib/trailblazer/workflow/state/discovery/testing.rb @@ -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 @@ -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 diff --git a/test/collaboration_test.rb b/test/collaboration_test.rb index 82cf391..5e6809e 100644 --- a/test/collaboration_test.rb +++ b/test/collaboration_test.rb @@ -216,7 +216,8 @@ def decider(ctx, decision: true, **) [ start_position, extended_initial_lane_positions, - {} # ctx_merge + {}, # ctx_merge + {outcome: :success} # config_payload ] ] @@ -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) @@ -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 @@ -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 @@ -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 @@ -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"}, @@ -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 ☑ ▶#