From 32aa2197e1329e1fc93b82f697d250e364d50a6f Mon Sep 17 00:00:00 2001 From: Nick Sutterer Date: Tue, 13 Feb 2024 12:30:13 +0100 Subject: [PATCH] first tests with `#assert_advance` running! :muscle: --- lib/trailblazer/workflow/test/plan.rb | 8 ++-- test/collaboration_test.rb | 58 +++++++++++++-------------- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/lib/trailblazer/workflow/test/plan.rb b/lib/trailblazer/workflow/test/plan.rb index 474d0a9..0d9649f 100644 --- a/lib/trailblazer/workflow/test/plan.rb +++ b/lib/trailblazer/workflow/test/plan.rb @@ -23,7 +23,7 @@ def assert_positions(asserted_positions, expected_tuples, lanes:) end # Compile error message when the expected lane position doesn't match the actual one. - def self.error_message_for(position, expected_position, lanes:) + def self.error_message_for(position, expected_position, lanes:) # TODO: test me. # TODO: make the labels use UTF8 icons etc, as in the CLI rendering code. expected_label = State::Discovery::Testing.serialize_lane_position(position, lanes: lanes)[:comment] actual_label = State::Discovery::Testing.serialize_lane_position(expected_position, lanes: lanes)[:comment] @@ -33,7 +33,7 @@ def self.error_message_for(position, expected_position, lanes:) # Grab the start_position and expected_lane_positions from the discovered plan, run # the collaboration from there and check if it actually reached the expected configuration. - def assert_advance(event_label, test_plan:, lanes:, schema:, message_flow:, expected_ctx:, **) # TODO: allow {ctx} + def assert_advance(event_label, test_plan:, lanes:, schema:, message_flow:, expected_ctx:, ctx: {seq: []}, **) # TODO: allow {ctx} testing_row = test_plan.find { |row| row[:event_label] == event_label } start_position = testing_row[:start_position] @@ -48,9 +48,11 @@ def assert_advance(event_label, test_plan:, lanes:, schema:, message_flow:, expe lane_positions = Trailblazer::Workflow::Collaboration::Positions.new(lane_positions) + ctx_for_advance = ctx + configuration, (ctx, flow) = Trailblazer::Workflow::Collaboration::Synchronous.advance( schema, - [{seq: []}, {throw: []}], + [ctx_for_advance, {throw: []}], {}, # circuit_options start_position: start_position, diff --git a/test/collaboration_test.rb b/test/collaboration_test.rb index 977a38a..8aa9a69 100644 --- a/test/collaboration_test.rb +++ b/test/collaboration_test.rb @@ -597,10 +597,6 @@ def render_states(states, lanes:, additional_state_data:, task_map:) lanes = ___lanes___.invert -# test: ☝ ▶Revise -ctx = assert_advance "☝ ▶Revise", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] - # +----------------------+--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+ # | triggered catch | start_configuration_formatted | expected_lane_positions_formatted | # +----------------------+--------------------------------------------------------------------------------+--------------------------------------------------------------------------------+ @@ -623,63 +619,63 @@ def render_states(states, lanes:, additional_state_data:, task_map:) # 15 rows in set # test: ☝ ▶Create form -ctx = assert_advance "☝ ▶Create form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow +ctx = assert_advance "☝ ▶Create form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow assert_exposes ctx, seq: [:create_form], reader: :[] # test: ☝ ▶Create -ctx = assert_advance "☝ ▶Create", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow +ctx = assert_advance "☝ ▶Create", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow assert_exposes ctx, seq: [:ui_create, :create], reader: :[] # test: ☝ ▶Create ⛞ -ctx = assert_advance "☝ ▶Create ⛞", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Create ⛞", ctx: {seq: [], create: false}, expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:ui_create, :create, :create_form_with_errors], reader: :[] # test: ☝ ▶Update form -ctx = assert_advance "☝ ▶Update form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Update form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:update_form], reader: :[] # test: ☝ ▶Notify approver -ctx = assert_advance "☝ ▶Notify approver", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Notify approver", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:notify_approver, :notify_approver, :approve], reader: :[] # test: ☝ ▶Update -ctx = assert_advance "☝ ▶Update", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Update", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:ui_update, :update], reader: :[] # test: ☝ ▶Notify approver ⛞ -ctx = assert_advance "☝ ▶Notify approver ⛞", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Notify approver ⛞", ctx: {seq: [], decision: false}, expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:notify_approver, :notify_approver, :reject], reader: :[] # test: ☝ ▶Delete? form -ctx = assert_advance "☝ ▶Delete? form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Delete? form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:delete_form], reader: :[] # test: ☝ ▶Publish -ctx = assert_advance "☝ ▶Publish", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Publish", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:publish, :publish], reader: :[] # test: ☝ ▶Update ⛞ -ctx = assert_advance "☝ ▶Update ⛞", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Update ⛞", ctx: {seq: [], update: false}, expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:ui_update, :update, :update_form_with_errors], reader: :[] # test: ☝ ▶Revise form -ctx = assert_advance "☝ ▶Revise form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Revise form", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:revise_form], reader: :[] # test: ☝ ▶Delete -ctx = assert_advance "☝ ▶Delete", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Delete", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:delete, :delete], reader: :[] # test: ☝ ▶Cancel -ctx = assert_advance "☝ ▶Cancel", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Cancel", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:cancel], reader: :[] # test: ☝ ▶Archive -ctx = assert_advance "☝ ▶Archive", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow -assert_exposes ctx, seq: [:revise, :revise], reader: :[] +ctx = assert_advance "☝ ▶Archive", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow +assert_exposes ctx, seq: [:archive, :archive], reader: :[] # test: ☝ ▶Revise -ctx = assert_advance "☝ ▶Revise", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: message_flow +ctx = assert_advance "☝ ▶Revise", expected_ctx: {}, test_plan: testing_structure, lanes: lanes, schema: schema, message_flow: extended_message_flow assert_exposes ctx, seq: [:revise, :revise], reader: :[]