import { test, expect } from 'vitest'; import parse, { reSpace } from '../parse'; import { TestData } from '../type'; const data: TestData = { "input": { "nodes": [{ "id": "5afa445d-5aea-4c19-af44-2b4439731ecc", "type": "ID", "x": 200, "y": 300, "properties": { "name": "n2", "nodeId": "n2" } }, { "id": "0a87a02c-9fd3-4ad2-988f-4925cc1ce89b", "type": "ID", "x": 540, "y": 220, "properties": { "name": "n4", "nodeId": "n4" } }, { "id": "1e8eacde-f2b8-43a3-8437-ec0d1533ad6a", "type": "ID", "x": 540, "y": 380, "properties": { "name": "n5", "nodeId": "n5" } }, { "id": "408427c7-7bd2-4b4d-a329-16797823df02", "type": "SWITCH", "x": 360, "y": 300, "properties": { "name": "n6", "nodeId": "n6" } }, { "id": "a8a952dd-e617-4303-9238-8ddeaa4743d1", "type": "SWITCH", "x": 680, "y": 220, "properties": { "name": "n7", "nodeId": "n7" } }, { "id": "6ce69b03-6f9b-4962-816b-507c247b9a13", "type": "ID", "x": 820, "y": 220, "properties": { "name": "n8", "nodeId": "n8" } }, { "id": "7e434114-1eb1-442c-ba61-7f84c299cc58", "type": "SWITCH", "x": 940, "y": 220, "properties": { "name": "n9", "nodeId": "n9" } }, { "id": "445e0c7e-fc33-4a39-bd35-d08ae7fb094c", "type": "ID", "x": 680, "y": 380, "properties": { "name": "n10", "nodeId": "n10" } }, { "id": "a828b205-9a01-4597-99eb-db700ff3c187", "type": "ID", "x": 820, "y": 380, "properties": { "name": "n11", "nodeId": "n11" } }, { "id": "5aed03aa-b97c-411c-9923-2c19e75c9c29", "type": "ID", "x": 940, "y": 380, "properties": { "name": "n12", "nodeId": "n12" } }, { "id": "8b20b2bc-b9f0-4fc4-bacc-c176e6609964", "type": "ID", "x": 1120, "y": 300, "properties": { "name": "n13", "nodeId": "n13" } }], "edges": [{ "id": "cd99ce6f-8d92-49e4-aa66-b5ea07403ae9", "type": "bezier", "sourceNodeId": "5afa445d-5aea-4c19-af44-2b4439731ecc", "targetNodeId": "408427c7-7bd2-4b4d-a329-16797823df02", "startPoint": { "x": 245, "y": 300 }, "endPoint": { "x": 315, "y": 300 }, "properties": {}, "pointsList": [{ "x": 245, "y": 300 }, { "x": 345, "y": 300 }, { "x": 215, "y": 300 }, { "x": 315, "y": 300 }] }, { "id": "45b1f3ac-9b33-4f0c-b1cd-f4bb1c407e13", "type": "bezier", "sourceNodeId": "0a87a02c-9fd3-4ad2-988f-4925cc1ce89b", "targetNodeId": "a8a952dd-e617-4303-9238-8ddeaa4743d1", "startPoint": { "x": 585, "y": 220 }, "endPoint": { "x": 635, "y": 220 }, "properties": {}, "pointsList": [{ "x": 585, "y": 220 }, { "x": 685, "y": 220 }, { "x": 535, "y": 220 }, { "x": 635, "y": 220 }] }, { "id": "0567f197-2a97-4852-94cf-2bbc8b0ea70f", "type": "bezier", "sourceNodeId": "6ce69b03-6f9b-4962-816b-507c247b9a13", "targetNodeId": "7e434114-1eb1-442c-ba61-7f84c299cc58", "startPoint": { "x": 865, "y": 220 }, "endPoint": { "x": 895, "y": 220 }, "properties": {}, "pointsList": [{ "x": 865, "y": 220 }, { "x": 965, "y": 220 }, { "x": 795, "y": 220 }, { "x": 895, "y": 220 }] }, { "id": "14b112fa-3612-4814-856f-d910329f4eb2", "type": "bezier", "sourceNodeId": "1e8eacde-f2b8-43a3-8437-ec0d1533ad6a", "targetNodeId": "445e0c7e-fc33-4a39-bd35-d08ae7fb094c", "startPoint": { "x": 585, "y": 380 }, "endPoint": { "x": 635, "y": 380 }, "properties": {}, "pointsList": [{ "x": 585, "y": 380 }, { "x": 685, "y": 380 }, { "x": 535, "y": 380 }, { "x": 635, "y": 380 }] }, { "id": "2097abac-0f25-4224-a146-02cdadc44d31", "type": "bezier", "sourceNodeId": "445e0c7e-fc33-4a39-bd35-d08ae7fb094c", "targetNodeId": "a828b205-9a01-4597-99eb-db700ff3c187", "startPoint": { "x": 725, "y": 380 }, "endPoint": { "x": 775, "y": 380 }, "properties": {}, "pointsList": [{ "x": 725, "y": 380 }, { "x": 825, "y": 380 }, { "x": 675, "y": 380 }, { "x": 775, "y": 380 }] }, { "id": "3001b7ed-1e2b-423a-8940-a2609582c384", "type": "bezier", "sourceNodeId": "a828b205-9a01-4597-99eb-db700ff3c187", "targetNodeId": "5aed03aa-b97c-411c-9923-2c19e75c9c29", "startPoint": { "x": 865, "y": 380 }, "endPoint": { "x": 895, "y": 380 }, "properties": {}, "pointsList": [{ "x": 865, "y": 380 }, { "x": 965, "y": 380 }, { "x": 795, "y": 380 }, { "x": 895, "y": 380 }] }, { "id": "6a1b5bdd-3f26-409c-aca8-b8e067417212", "type": "bezier", "sourceNodeId": "5aed03aa-b97c-411c-9923-2c19e75c9c29", "targetNodeId": "8b20b2bc-b9f0-4fc4-bacc-c176e6609964", "startPoint": { "x": 985, "y": 380 }, "endPoint": { "x": 1075, "y": 300 }, "properties": {}, "pointsList": [{ "x": 985, "y": 380 }, { "x": 1085, "y": 380 }, { "x": 975, "y": 300 }, { "x": 1075, "y": 300 }] }, { "id": "31a4805b-57e7-4c32-b253-c25d26e13942", "type": "bezier", "sourceNodeId": "408427c7-7bd2-4b4d-a329-16797823df02", "targetNodeId": "1e8eacde-f2b8-43a3-8437-ec0d1533ad6a", "startPoint": { "x": 405, "y": 300 }, "endPoint": { "x": 495, "y": 380 }, "properties": {}, "text": { "x": 450, "y": 340, "value": "1" }, "pointsList": [{ "x": 405, "y": 300 }, { "x": 505, "y": 300 }, { "x": 395, "y": 380 }, { "x": 495, "y": 380 }] }, { "id": "db9faadc-7935-4018-911b-472092a21c78", "type": "bezier", "sourceNodeId": "408427c7-7bd2-4b4d-a329-16797823df02", "targetNodeId": "0a87a02c-9fd3-4ad2-988f-4925cc1ce89b", "startPoint": { "x": 405, "y": 300 }, "endPoint": { "x": 495, "y": 220 }, "properties": {}, "text": { "x": 450, "y": 260, "value": "2" }, "pointsList": [{ "x": 405, "y": 300 }, { "x": 505, "y": 300 }, { "x": 395, "y": 220 }, { "x": 495, "y": 220 }] }, { "id": "2f795c22-5709-4312-a526-7f5333d24cf0", "type": "bezier", "sourceNodeId": "a8a952dd-e617-4303-9238-8ddeaa4743d1", "targetNodeId": "445e0c7e-fc33-4a39-bd35-d08ae7fb094c", "startPoint": { "x": 680, "y": 250 }, "endPoint": { "x": 680, "y": 350 }, "properties": {}, "text": { "x": 680, "y": 300, "value": "3" }, "pointsList": [{ "x": 680, "y": 250 }, { "x": 680, "y": 350 }, { "x": 680, "y": 250 }, { "x": 680, "y": 350 }] }, { "id": "695b0866-5a5b-4202-9d53-052a86d0a3f2", "type": "bezier", "sourceNodeId": "a8a952dd-e617-4303-9238-8ddeaa4743d1", "targetNodeId": "6ce69b03-6f9b-4962-816b-507c247b9a13", "startPoint": { "x": 725, "y": 220 }, "endPoint": { "x": 775, "y": 220 }, "properties": {}, "text": { "x": 750, "y": 220, "value": "4" }, "pointsList": [{ "x": 725, "y": 220 }, { "x": 825, "y": 220 }, { "x": 675, "y": 220 }, { "x": 775, "y": 220 }] }, { "id": "b4ef7c0c-07d4-4375-878c-280e908a2cb7", "type": "bezier", "sourceNodeId": "7e434114-1eb1-442c-ba61-7f84c299cc58", "targetNodeId": "5aed03aa-b97c-411c-9923-2c19e75c9c29", "startPoint": { "x": 940, "y": 250 }, "endPoint": { "x": 940, "y": 350 }, "properties": {}, "text": { "x": 940, "y": 300, "value": "5" }, "pointsList": [{ "x": 940, "y": 250 }, { "x": 940, "y": 350 }, { "x": 940, "y": 250 }, { "x": 940, "y": 350 }] }, { "id": "79044265-590a-4f20-9867-ab44120fadd5", "type": "bezier", "sourceNodeId": "7e434114-1eb1-442c-ba61-7f84c299cc58", "targetNodeId": "8b20b2bc-b9f0-4fc4-bacc-c176e6609964", "startPoint": { "x": 985, "y": 220 }, "endPoint": { "x": 1075, "y": 300 }, "properties": {}, "text": { "x": 1030, "y": 260, "value": "6" }, "pointsList": [{ "x": 985, "y": 220 }, { "x": 1085, "y": 220 }, { "x": 975, "y": 300 }, { "x": 1075, "y": 300 }] }] }, output: `THEN( n2, SWITCH(n6).to( THEN(n5,n10,n11,n12,n13).id("1"), THEN( n4, SWITCH(n7).to( THEN(n10,n11,n12,n13).id("3"), THEN( n8, SWITCH(n9).to( THEN(n12,n13).id("5"), THEN(n13).id("6") ) ).id("4") ) ).id("2") ) )` } test("witch_more", () => { expect( reSpace(parse(data.input)) ).toBe(reSpace(data.output)); })