Skip to content

Commit

Permalink
test: verify componentsToPath
Browse files Browse the repository at this point in the history
  • Loading branch information
barmac committed Nov 14, 2024
1 parent 18781c9 commit 06db3c7
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/spec/util/RenderUtilSpec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
componentsToPath,
createLine,
updateLine
} from 'lib/util/RenderUtil';
Expand Down Expand Up @@ -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);
});
}
});
});

0 comments on commit 06db3c7

Please sign in to comment.