From 06db3c76c2c1729dd75b55cd3c0f80e29fbc787a Mon Sep 17 00:00:00 2001 From: Maciej Barelkowski Date: Thu, 14 Nov 2024 11:18:47 +0100 Subject: [PATCH] test: verify componentsToPath --- test/spec/util/RenderUtilSpec.js | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/test/spec/util/RenderUtilSpec.js b/test/spec/util/RenderUtilSpec.js index 6c5be3ffa..c200f3736 100644 --- a/test/spec/util/RenderUtilSpec.js +++ b/test/spec/util/RenderUtilSpec.js @@ -1,4 +1,5 @@ import { + componentsToPath, createLine, updateLine } from 'lib/util/RenderUtil'; @@ -113,4 +114,72 @@ describe('util/RenderUtil', function() { }); + + describe('#componentsToPath', function() { + + // test cases derived from bpmn-js BpmnRenderUtil + const testCases = [ + { + name: 'circle', + components: [ + [ 'M', 0, 0 ], + [ 'm', 0, -20 ], + [ 'a', 20, 20, 0, 1, 1, 0, 2 * 20 ], + [ 'a', 20, 20, 0, 1, 1, 0, -2 * 20 ], + [ 'z' ] + ], + expected: 'M0,0m0,-20a20,20,0,1,1,0,40a20,20,0,1,1,0,-40z' + }, + { + name: 'roundRect', + components: [ + [ 'M', 100 + 5, 10 ], + [ 'l', 100 - 5 * 2, 0 ], + [ 'a', 5, 5, 0, 0, 1, 5, 5 ], + [ 'l', 0, 80 - 5 * 2 ], + [ 'a', 5, 5, 0, 0, 1, -5, 5 ], + [ 'l', 5 * 2 - 100, 0 ], + [ 'a', 5, 5, 0, 0, 1, -5, -5 ], + [ 'l', 0, 5 * 2 - 80 ], + [ 'a', 5, 5, 0, 0, 1, 5, -5 ], + [ 'z' ] + ], + expected: 'M105,10l90,0a5,5,0,0,1,5,5l0,70a5,5,0,0,1,-5,5l-90,0a5,5,0,0,1,-5,-5l0,-70a5,5,0,0,1,5,-5z' + }, + { + name: 'diamond', + components: [ + [ 'M', 100, 0 ], + [ 'l', 100, 100 ], + [ 'l', -100, 100 ], + [ 'l', -100, -100 ], + [ 'z' ] + ], + expected: 'M100,0l100,100l-100,100l-100,-100z' + }, + { + name: 'rect', + components: [ + [ 'M', 100, 0 ], + [ 'l', 100, 0 ], + [ 'l', 0, 100 ], + [ 'l', -100, 0 ], + [ 'z' ] + ], + expected: 'M100,0l100,0l0,100l-100,0z' + } + ]; + + for (const testCase of testCases) { + + it(`should handle ${testCase.name}`, function() { + + // when + const output = componentsToPath(testCase.components); + + // then + expect(output).to.eql(testCase.expected); + }); + } + }); });