diff --git a/src/store/__snapshots__/thunks.test.ts.snap b/src/store/__snapshots__/thunks.test.ts.snap index 193096f72..981ef541f 100644 --- a/src/store/__snapshots__/thunks.test.ts.snap +++ b/src/store/__snapshots__/thunks.test.ts.snap @@ -28443,7 +28443,16 @@ que é uma string com caracteres utilizados para dividir o texto em palavras.", }, }, }, - "stickies": {}, + "stickies": { + "sticky0": { + "body": "The body for sticky0", + "position": { + "left": 100, + "top": 100, + }, + "title": "sticky0", + }, + }, }, "language": "eng", "localization": {}, @@ -42012,7 +42021,16 @@ que é uma string com caracteres utilizados para dividir o texto em palavras.", }, }, }, - "stickies": {}, + "stickies": { + "sticky0": { + "body": "The body for sticky0", + "position": { + "left": 100, + "top": 100, + }, + "title": "sticky0", + }, + }, }, "language": "eng", "localization": {}, @@ -48470,7 +48488,16 @@ que é uma string com caracteres utilizados para dividir o texto em palavras.", }, }, }, - "stickies": {}, + "stickies": { + "sticky0": { + "body": "The body for sticky0", + "position": { + "left": 100, + "top": 100, + }, + "title": "sticky0", + }, + }, }, "language": "eng", "localization": {}, @@ -52572,73 +52599,1918 @@ exports[`Flow Manipulation > nodes > should store a pending connection when star ] `; -exports[`Flow Manipulation > routers > should add random routers after an add action 1`] = ` -{ - "inboundConnections": {}, - "node": { - "actions": [], - "exits": [ - { - "destination_uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", - "name": null, - "uuid": "node0_exit0", +exports[`Flow Manipulation > on update canvas positions > should update positions 1`] = ` +[ + { + "payload": { + "nodes": { + "node0": { + "inboundConnections": {}, + "node": { + "actions": [], + "exits": [ + { + "destination_uuid": "node1", + "name": null, + "uuid": "node0_exit0", + }, + ], + "uuid": "node0", + }, + "ui": { + "position": { + "left": 100, + "top": 100, + }, + }, + }, + "node1": { + "inboundConnections": { + "node0_exit0": "node0", + }, + "node": { + "actions": [], + "exits": [ + { + "destination_uuid": "node2", + "uuid": "node1_exit0", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit1", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit2", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "red", + ], + "category_uuid": "node1_cat0", + "type": "has_any_word", + "uuid": "node1_case0", + }, + { + "arguments": [ + "green", + ], + "category_uuid": "node1_cat1", + "type": "has_any_word", + "uuid": "node1_case1", + }, + ], + "categories": [ + { + "exit_uuid": "node1_exit0", + "name": "Red", + "uuid": "node1_cat0", + }, + { + "exit_uuid": "node1_exit1", + "name": "Green", + "uuid": "node1_cat1", + }, + { + "exit_uuid": "node1_exit2", + "name": "Other", + "uuid": "node1_cat2", + }, + ], + "default_exit_uuid": "node1_exit2", + "operand": "@run.input", + "result_name": "color", + "type": "switch", + "wait": { + "type": "msg", + }, + }, + "uuid": "node1", + }, + "ui": { + "position": { + "left": 200, + "top": 200, + }, + "type": "wait_for_response", + }, + }, + "node2": { + "inboundConnections": { + "node1_exit0": "node1", + "node1_exit1": "node1", + "node1_exit2": "node1", + }, + "node": { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + "ui": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + }, + "node3": { + "inboundConnections": { + "node2_exit0": "node2", + }, + "node": { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + "ui": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, }, - ], - "uuid": "node0", - }, - "ui": { - "position": { - "bottom": 254, - "left": 0, - "right": 220, - "top": 10, }, + "type": "UPDATE_NODES", }, -} +] `; -exports[`Flow Manipulation > routers > should add random routers after an add action 2`] = ` -{ - "inboundConnections": { - "node0_exit0": "node0", - }, - "node": { - "actions": [], - "exits": [ - { - "destination_uuid": null, - "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", - }, - { - "destination_uuid": null, - "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", - }, - ], - "router": { - "categories": [ - { - "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", - "name": "Bucket 1", - "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", - }, - { - "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", - "name": "Bucket 2", - "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", +exports[`Flow Manipulation > on update canvas positions > should update positions 2`] = ` +[ + { + "payload": { + "nodes": { + "node0": { + "inboundConnections": {}, + "node": { + "actions": [], + "exits": [ + { + "destination_uuid": "node1", + "name": null, + "uuid": "node0_exit0", + }, + ], + "uuid": "node0", + }, + "ui": { + "position": { + "left": 100, + "top": 100, + }, + }, }, - ], - "type": "random", - }, - "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", - }, - "ui": { - "position": { - "bottom": 254, - "left": 0, - "right": 220, - "top": 10, - }, - "type": "split_by_random", - }, -} + "node1": { + "inboundConnections": { + "node0_exit0": "node0", + }, + "node": { + "actions": [], + "exits": [ + { + "destination_uuid": "node2", + "uuid": "node1_exit0", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit1", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit2", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "red", + ], + "category_uuid": "node1_cat0", + "type": "has_any_word", + "uuid": "node1_case0", + }, + { + "arguments": [ + "green", + ], + "category_uuid": "node1_cat1", + "type": "has_any_word", + "uuid": "node1_case1", + }, + ], + "categories": [ + { + "exit_uuid": "node1_exit0", + "name": "Red", + "uuid": "node1_cat0", + }, + { + "exit_uuid": "node1_exit1", + "name": "Green", + "uuid": "node1_cat1", + }, + { + "exit_uuid": "node1_exit2", + "name": "Other", + "uuid": "node1_cat2", + }, + ], + "default_exit_uuid": "node1_exit2", + "operand": "@run.input", + "result_name": "color", + "type": "switch", + "wait": { + "type": "msg", + }, + }, + "uuid": "node1", + }, + "ui": { + "position": { + "left": 200, + "top": 200, + }, + "type": "wait_for_response", + }, + }, + "node2": { + "inboundConnections": { + "node1_exit0": "node1", + "node1_exit1": "node1", + "node1_exit2": "node1", + }, + "node": { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + "ui": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + }, + "node3": { + "inboundConnections": { + "node2_exit0": "node2", + }, + "node": { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + "ui": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + }, + }, + "type": "UPDATE_NODES", + }, + { + "payload": { + "definition": { + "_ui": { + "languages": [], + "nodes": { + "node0": { + "position": { + "bottom": 254, + "left": 0, + "right": 220, + "top": 10, + }, + }, + "node1": { + "position": { + "bottom": 370, + "left": 0, + "right": 220, + "top": 280, + }, + "type": "wait_for_response", + }, + "node2": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + "node3": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + "stickies": { + "sticky0": { + "body": "The body for sticky0", + "position": { + "bottom": NaN, + "left": 300, + "right": NaN, + "top": 300, + }, + "title": "sticky0", + }, + }, + }, + "language": "eng", + "localization": {}, + "name": "Boring Flow", + "nodes": [ + { + "actions": [], + "exits": [ + { + "destination_uuid": "node1", + "name": null, + "uuid": "node0_exit0", + }, + ], + "uuid": "node0", + }, + { + "actions": [], + "exits": [ + { + "destination_uuid": "node2", + "uuid": "node1_exit0", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit1", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit2", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "red", + ], + "category_uuid": "node1_cat0", + "type": "has_any_word", + "uuid": "node1_case0", + }, + { + "arguments": [ + "green", + ], + "category_uuid": "node1_cat1", + "type": "has_any_word", + "uuid": "node1_case1", + }, + ], + "categories": [ + { + "exit_uuid": "node1_exit0", + "name": "Red", + "uuid": "node1_cat0", + }, + { + "exit_uuid": "node1_exit1", + "name": "Green", + "uuid": "node1_cat1", + }, + { + "exit_uuid": "node1_exit2", + "name": "Other", + "uuid": "node1_cat2", + }, + ], + "default_exit_uuid": "node1_exit2", + "operand": "@run.input", + "result_name": "color", + "type": "switch", + "wait": { + "type": "msg", + }, + }, + "uuid": "node1", + }, + { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + ], + "spec_version": "13.1", + "uuid": "boring", + }, + }, + "type": "UPDATE_DEFINITION", + }, +] +`; + +exports[`Flow Manipulation > on update canvas positions > should update positions 3`] = ` +[ + { + "payload": { + "nodes": { + "node0": { + "inboundConnections": {}, + "node": { + "actions": [], + "exits": [ + { + "destination_uuid": "node1", + "name": null, + "uuid": "node0_exit0", + }, + ], + "uuid": "node0", + }, + "ui": { + "position": { + "left": 100, + "top": 100, + }, + }, + }, + "node1": { + "inboundConnections": { + "node0_exit0": "node0", + }, + "node": { + "actions": [], + "exits": [ + { + "destination_uuid": "node2", + "uuid": "node1_exit0", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit1", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit2", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "red", + ], + "category_uuid": "node1_cat0", + "type": "has_any_word", + "uuid": "node1_case0", + }, + { + "arguments": [ + "green", + ], + "category_uuid": "node1_cat1", + "type": "has_any_word", + "uuid": "node1_case1", + }, + ], + "categories": [ + { + "exit_uuid": "node1_exit0", + "name": "Red", + "uuid": "node1_cat0", + }, + { + "exit_uuid": "node1_exit1", + "name": "Green", + "uuid": "node1_cat1", + }, + { + "exit_uuid": "node1_exit2", + "name": "Other", + "uuid": "node1_cat2", + }, + ], + "default_exit_uuid": "node1_exit2", + "operand": "@run.input", + "result_name": "color", + "type": "switch", + "wait": { + "type": "msg", + }, + }, + "uuid": "node1", + }, + "ui": { + "position": { + "left": 200, + "top": 200, + }, + "type": "wait_for_response", + }, + }, + "node2": { + "inboundConnections": { + "node1_exit0": "node1", + "node1_exit1": "node1", + "node1_exit2": "node1", + }, + "node": { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + "ui": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + }, + "node3": { + "inboundConnections": { + "node2_exit0": "node2", + }, + "node": { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + "ui": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + }, + }, + "type": "UPDATE_NODES", + }, + { + "payload": { + "definition": { + "_ui": { + "languages": [], + "nodes": { + "node0": { + "position": { + "bottom": 254, + "left": 0, + "right": 220, + "top": 10, + }, + }, + "node1": { + "position": { + "bottom": 370, + "left": 0, + "right": 220, + "top": 280, + }, + "type": "wait_for_response", + }, + "node2": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + "node3": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + "stickies": { + "sticky0": { + "body": "The body for sticky0", + "position": { + "bottom": NaN, + "left": 300, + "right": NaN, + "top": 300, + }, + "title": "sticky0", + }, + }, + }, + "language": "eng", + "localization": {}, + "name": "Boring Flow", + "nodes": [ + { + "actions": [], + "exits": [ + { + "destination_uuid": "node1", + "name": null, + "uuid": "node0_exit0", + }, + ], + "uuid": "node0", + }, + { + "actions": [], + "exits": [ + { + "destination_uuid": "node2", + "uuid": "node1_exit0", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit1", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit2", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "red", + ], + "category_uuid": "node1_cat0", + "type": "has_any_word", + "uuid": "node1_case0", + }, + { + "arguments": [ + "green", + ], + "category_uuid": "node1_cat1", + "type": "has_any_word", + "uuid": "node1_case1", + }, + ], + "categories": [ + { + "exit_uuid": "node1_exit0", + "name": "Red", + "uuid": "node1_cat0", + }, + { + "exit_uuid": "node1_exit1", + "name": "Green", + "uuid": "node1_cat1", + }, + { + "exit_uuid": "node1_exit2", + "name": "Other", + "uuid": "node1_cat2", + }, + ], + "default_exit_uuid": "node1_exit2", + "operand": "@run.input", + "result_name": "color", + "type": "switch", + "wait": { + "type": "msg", + }, + }, + "uuid": "node1", + }, + { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + ], + "spec_version": "13.1", + "uuid": "boring", + }, + }, + "type": "UPDATE_DEFINITION", + }, +] +`; + +exports[`Flow Manipulation > remove nodes > should return correct nodes 1`] = ` +[ + { + "payload": { + "nodes": { + "node2": { + "inboundConnections": {}, + "node": { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + "ui": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + }, + "node3": { + "inboundConnections": { + "node2_exit0": "node2", + }, + "node": { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + "ui": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + }, + }, + "type": "UPDATE_NODES", + }, +] +`; + +exports[`Flow Manipulation > remove nodes > should return correct nodes 2`] = ` +[ + { + "payload": { + "nodes": { + "node2": { + "inboundConnections": {}, + "node": { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + "ui": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + }, + "node3": { + "inboundConnections": { + "node2_exit0": "node2", + }, + "node": { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + "ui": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + }, + }, + "type": "UPDATE_NODES", + }, + { + "payload": { + "nodes": { + "node1": { + "inboundConnections": {}, + "node": { + "actions": [], + "exits": [ + { + "destination_uuid": "node2", + "uuid": "node1_exit0", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit1", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit2", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "red", + ], + "category_uuid": "node1_cat0", + "type": "has_any_word", + "uuid": "node1_case0", + }, + { + "arguments": [ + "green", + ], + "category_uuid": "node1_cat1", + "type": "has_any_word", + "uuid": "node1_case1", + }, + ], + "categories": [ + { + "exit_uuid": "node1_exit0", + "name": "Red", + "uuid": "node1_cat0", + }, + { + "exit_uuid": "node1_exit1", + "name": "Green", + "uuid": "node1_cat1", + }, + { + "exit_uuid": "node1_exit2", + "name": "Other", + "uuid": "node1_cat2", + }, + ], + "default_exit_uuid": "node1_exit2", + "operand": "@run.input", + "result_name": "color", + "type": "switch", + "wait": { + "type": "msg", + }, + }, + "uuid": "node1", + }, + "ui": { + "position": { + "bottom": 370, + "left": 0, + "right": 220, + "top": 280, + }, + "type": "wait_for_response", + }, + }, + "node2": { + "inboundConnections": { + "node1_exit0": "node1", + "node1_exit1": "node1", + "node1_exit2": "node1", + }, + "node": { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + "ui": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + }, + "node3": { + "inboundConnections": { + "node2_exit0": "node2", + }, + "node": { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + "ui": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + }, + }, + "type": "UPDATE_NODES", + }, + { + "payload": { + "definition": { + "_ui": { + "languages": [], + "nodes": { + "node0": { + "position": { + "bottom": 254, + "left": 0, + "right": 220, + "top": 10, + }, + }, + "node1": { + "position": { + "bottom": 370, + "left": 0, + "right": 220, + "top": 280, + }, + "type": "wait_for_response", + }, + "node2": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + "node3": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + "stickies": {}, + }, + "language": "eng", + "localization": {}, + "name": "Boring Flow", + "nodes": [ + { + "actions": [], + "exits": [ + { + "destination_uuid": "node1", + "name": null, + "uuid": "node0_exit0", + }, + ], + "uuid": "node0", + }, + { + "actions": [], + "exits": [ + { + "destination_uuid": "node2", + "uuid": "node1_exit0", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit1", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit2", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "red", + ], + "category_uuid": "node1_cat0", + "type": "has_any_word", + "uuid": "node1_case0", + }, + { + "arguments": [ + "green", + ], + "category_uuid": "node1_cat1", + "type": "has_any_word", + "uuid": "node1_case1", + }, + ], + "categories": [ + { + "exit_uuid": "node1_exit0", + "name": "Red", + "uuid": "node1_cat0", + }, + { + "exit_uuid": "node1_exit1", + "name": "Green", + "uuid": "node1_cat1", + }, + { + "exit_uuid": "node1_exit2", + "name": "Other", + "uuid": "node1_cat2", + }, + ], + "default_exit_uuid": "node1_exit2", + "operand": "@run.input", + "result_name": "color", + "type": "switch", + "wait": { + "type": "msg", + }, + }, + "uuid": "node1", + }, + { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + ], + "spec_version": "13.1", + "uuid": "boring", + }, + }, + "type": "UPDATE_DEFINITION", + }, +] +`; + +exports[`Flow Manipulation > remove nodes > should return correct nodes 3`] = ` +[ + { + "payload": { + "nodes": { + "node2": { + "inboundConnections": {}, + "node": { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + "ui": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + }, + "node3": { + "inboundConnections": { + "node2_exit0": "node2", + }, + "node": { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + "ui": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + }, + }, + "type": "UPDATE_NODES", + }, + { + "payload": { + "nodes": { + "node1": { + "inboundConnections": {}, + "node": { + "actions": [], + "exits": [ + { + "destination_uuid": "node2", + "uuid": "node1_exit0", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit1", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit2", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "red", + ], + "category_uuid": "node1_cat0", + "type": "has_any_word", + "uuid": "node1_case0", + }, + { + "arguments": [ + "green", + ], + "category_uuid": "node1_cat1", + "type": "has_any_word", + "uuid": "node1_case1", + }, + ], + "categories": [ + { + "exit_uuid": "node1_exit0", + "name": "Red", + "uuid": "node1_cat0", + }, + { + "exit_uuid": "node1_exit1", + "name": "Green", + "uuid": "node1_cat1", + }, + { + "exit_uuid": "node1_exit2", + "name": "Other", + "uuid": "node1_cat2", + }, + ], + "default_exit_uuid": "node1_exit2", + "operand": "@run.input", + "result_name": "color", + "type": "switch", + "wait": { + "type": "msg", + }, + }, + "uuid": "node1", + }, + "ui": { + "position": { + "bottom": 370, + "left": 0, + "right": 220, + "top": 280, + }, + "type": "wait_for_response", + }, + }, + "node2": { + "inboundConnections": { + "node1_exit0": "node1", + "node1_exit1": "node1", + "node1_exit2": "node1", + }, + "node": { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + "ui": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + }, + "node3": { + "inboundConnections": { + "node2_exit0": "node2", + }, + "node": { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + "ui": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + }, + }, + "type": "UPDATE_NODES", + }, + { + "payload": { + "definition": { + "_ui": { + "languages": [], + "nodes": { + "node0": { + "position": { + "bottom": 254, + "left": 0, + "right": 220, + "top": 10, + }, + }, + "node1": { + "position": { + "bottom": 370, + "left": 0, + "right": 220, + "top": 280, + }, + "type": "wait_for_response", + }, + "node2": { + "position": { + "bottom": 498, + "left": 0, + "right": 220, + "top": 400, + }, + }, + "node3": { + "position": { + "bottom": 598, + "left": 0, + "right": 220, + "top": 520, + }, + }, + }, + "stickies": {}, + }, + "language": "eng", + "localization": {}, + "name": "Boring Flow", + "nodes": [ + { + "actions": [], + "exits": [ + { + "destination_uuid": "node1", + "name": null, + "uuid": "node0_exit0", + }, + ], + "uuid": "node0", + }, + { + "actions": [], + "exits": [ + { + "destination_uuid": "node2", + "uuid": "node1_exit0", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit1", + }, + { + "destination_uuid": "node2", + "uuid": "node1_exit2", + }, + ], + "router": { + "cases": [ + { + "arguments": [ + "red", + ], + "category_uuid": "node1_cat0", + "type": "has_any_word", + "uuid": "node1_case0", + }, + { + "arguments": [ + "green", + ], + "category_uuid": "node1_cat1", + "type": "has_any_word", + "uuid": "node1_case1", + }, + ], + "categories": [ + { + "exit_uuid": "node1_exit0", + "name": "Red", + "uuid": "node1_cat0", + }, + { + "exit_uuid": "node1_exit1", + "name": "Green", + "uuid": "node1_cat1", + }, + { + "exit_uuid": "node1_exit2", + "name": "Other", + "uuid": "node1_cat2", + }, + ], + "default_exit_uuid": "node1_exit2", + "operand": "@run.input", + "result_name": "color", + "type": "switch", + "wait": { + "type": "msg", + }, + }, + "uuid": "node1", + }, + { + "actions": [ + { + "text": "This has been really great.", + "type": "send_msg", + "uuid": "node2_action0", + }, + { + "field": { + "key": "unknown_field", + "name": "Unknown Field", + }, + "type": "set_contact_field", + "uuid": "node2_action1", + "value": "Some Value", + }, + ], + "exits": [ + { + "destination_uuid": "node3", + "name": null, + "uuid": "node2_exit0", + }, + ], + "uuid": "node2", + }, + { + "actions": [ + { + "text": "Thanks for playing!", + "type": "send_msg", + "uuid": "node3_action0", + }, + ], + "exits": [ + { + "destination_uuid": null, + "name": null, + "uuid": "node3_exit0", + }, + ], + "uuid": "node3", + }, + ], + "spec_version": "13.1", + "uuid": "boring", + }, + }, + "type": "UPDATE_DEFINITION", + }, +] +`; + +exports[`Flow Manipulation > routers > should add random routers after an add action 1`] = ` +{ + "inboundConnections": {}, + "node": { + "actions": [], + "exits": [ + { + "destination_uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + "name": null, + "uuid": "node0_exit0", + }, + ], + "uuid": "node0", + }, + "ui": { + "position": { + "bottom": 254, + "left": 0, + "right": 220, + "top": 10, + }, + }, +} +`; + +exports[`Flow Manipulation > routers > should add random routers after an add action 2`] = ` +{ + "inboundConnections": { + "node0_exit0": "node0", + }, + "node": { + "actions": [], + "exits": [ + { + "destination_uuid": null, + "uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + }, + { + "destination_uuid": null, + "uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + }, + ], + "router": { + "categories": [ + { + "exit_uuid": "061fc171-8b79-4636-b892-bd0ea5aa9b42", + "name": "Bucket 1", + "uuid": "763e4844-3e1b-407a-a1b5-5fdfcd308b41", + }, + { + "exit_uuid": "1dce2b34-9aab-4e20-81c4-3f0408dcb671", + "name": "Bucket 2", + "uuid": "477ac8b4-25e2-483a-8686-2d1332c4da1c", + }, + ], + "type": "random", + }, + "uuid": "132de855-4042-4dc1-a18f-cc2e6a8f790a", + }, + "ui": { + "position": { + "bottom": 254, + "left": 0, + "right": 220, + "top": 10, + }, + "type": "split_by_random", + }, +} +`; + +exports[`Language > should handle language changes 1`] = ` +[ + { + "payload": { + "editorState": { + "language": { + "id": "eng", + "name": "English", + "type": "language", + }, + "translating": true, + }, + }, + "type": "UPDATE_EDITOR_STATE", + }, + { + "payload": { + "editorState": { + "language": { + "id": "spa", + "name": "Spanish", + "type": "language", + }, + "translating": false, + }, + }, + "type": "UPDATE_EDITOR_STATE", + }, +] +`; + +exports[`Language > should handle language changes 2`] = ` +[ + { + "payload": { + "editorState": { + "language": { + "id": "eng", + "name": "English", + "type": "language", + }, + "translating": true, + }, + }, + "type": "UPDATE_EDITOR_STATE", + }, + { + "payload": { + "editorState": { + "language": { + "id": "spa", + "name": "Spanish", + "type": "language", + }, + "translating": false, + }, + }, + "type": "UPDATE_EDITOR_STATE", + }, + { + "payload": { + "editorState": { + "language": { + "id": "eng", + "name": "English", + "type": "language", + }, + "translating": false, + }, + }, + "type": "UPDATE_EDITOR_STATE", + }, +] `; diff --git a/src/store/thunks.test.ts b/src/store/thunks.test.ts index aeae5704e..cc683453b 100644 --- a/src/store/thunks.test.ts +++ b/src/store/thunks.test.ts @@ -44,12 +44,17 @@ import { updateExitDestination, updateSticky, fetchFlow, + onRemoveNodes, + onUpdateCanvasPositions, + handleLanguageChange, } from 'store/thunks'; import { createMockStore, mock, prepMockDuxState } from 'testUtils'; import { createAddGroupsAction, createRandomNode, createSendMsgAction, + Spanish, + English, } from 'testUtils/assetCreators'; import * as utils from 'utils'; import { act } from '../test/utils'; @@ -885,6 +890,108 @@ describe('Flow Manipulation', () => { expect(newNode).toMatchSnapshot(); }); }); + + describe('remove nodes', () => { + it('should return correct nodes', () => { + boring._ui.stickies = { + sticky0: { + title: 'sticky0', + body: 'The body for sticky0', + position: { left: 100, top: 100 }, + }, + }; + + store = createMockStore( + mutate(initialState, { + flowContext: { + definition: { $set: boring }, + nodes: { $set: testNodes }, + }, + nodeEditor: { + settings: { + $set: { + originalNode: testNodes.node0, + originalAction: createSendMsgAction(), + }, + }, + }, + }), + ); + + // remove the first node + store.dispatch( + onRemoveNodes([testNodes.node0.node.uuid, testNodes.node1.node.uuid]), + ); + + expect(store.getActions()).toMatchSnapshot(); + + // remove a sticky + store.dispatch(onRemoveNodes([testNodes.node0.node.uuid, 'sticky0'])); + + expect(store.getActions()).toMatchSnapshot(); + + // remove an unknown + store.dispatch(onRemoveNodes(['unknown'])); + expect(store.getActions()).toMatchSnapshot(); + }); + }); + + describe('on update canvas positions', () => { + it('should update positions', () => { + boring._ui.stickies = { + sticky0: { + title: 'sticky0', + body: 'The body for sticky0', + position: { left: 100, top: 100 }, + }, + }; + + store = createMockStore( + mutate(initialState, { + flowContext: { + definition: { $set: boring }, + nodes: { $set: testNodes }, + }, + nodeEditor: { + settings: { + $set: { + originalNode: testNodes.node0, + originalAction: createSendMsgAction(), + }, + }, + }, + }), + ); + + // move nodes positions + store.dispatch( + onUpdateCanvasPositions({ + [testNodes.node0.node.uuid]: { left: 100, top: 100 }, + [testNodes.node1.node.uuid]: { left: 200, top: 200 }, + }), + ); + + expect(store.getActions()).toMatchSnapshot(); + + // move sticky position + store.dispatch( + onUpdateCanvasPositions({ + sticky0: { left: 300, top: 300 }, + }), + ); + + expect(store.getActions()).toMatchSnapshot(); + + // move unknown + store.dispatch( + onUpdateCanvasPositions({ + unknown: { left: 400, top: 400 }, + }), + ); + + expect(store.getActions()).toMatchSnapshot(); + }); + }); }); describe('Flow Fetch', () => { @@ -940,3 +1047,20 @@ describe('Flow Fetch', () => { expect(store.getActions()).toMatchSnapshot(); }); }); + +describe('Language', () => { + it('should handle language changes', () => { + const store = createMockStore({ + flowContext: { baseLanguage: English }, + editorState: { language: English, translating: false }, + }); + + store.dispatch(handleLanguageChange(Spanish)); + + expect(store.getActions()).toMatchSnapshot(); + + store.dispatch(handleLanguageChange(English)); + + expect(store.getActions()).toMatchSnapshot(); + }); +});