From cb6539906332dad7dcf3d7fa006dcf58d0be5538 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Thu, 14 Jul 2011 14:24:32 +0200 Subject: [PATCH] Add 2 more HitResult tests, which test hitting selected paths and guides. --- test/tests/HitResult.js | 60 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/test/tests/HitResult.js b/test/tests/HitResult.js index 2f8bf2c8..330e98f9 100644 --- a/test/tests/HitResult.js +++ b/test/tests/HitResult.js @@ -69,6 +69,27 @@ test('hitting a stroked path', function() { }, true); }); +test('hitting a selected path', function() { + var path = new Path.Circle([50, 50], 50); + path.fillColor = 'red'; + + var hitResult = paper.project.hitTest([75, 75], { + selected: true + }); + equals(function() { + return hitResult == null; + }, true, 'Since the path is not selected, the hit-test should return null'); + + path.selected = true; + hitResult = paper.project.hitTest([75, 75]); + equals(function() { + return hitResult.type == 'fill'; + }, true); + equals(function() { + return hitResult.item == path; + }, true); +}); + test('hitting path segments', function() { var path = new Path([0, 0], [10, 10], [20, 0]); @@ -297,4 +318,41 @@ test('hitting path bounding box', function() { return hitResult.point.toString(); },path.bounds.topLeft.toString()); } -}); \ No newline at end of file +}); + +test('hitting guides', function() { + var path = new Path.Circle(new Point(100, 100), 50); + path.fillColor = 'red'; + + var copy = path.clone(); + + var hitResult = paper.project.hitTest(path.position); + + equals(function() { + return !!hitResult; + }, true, 'A HitResult should be returned (1)'); + + if (hitResult) { + equals(function() { + return hitResult.item == copy; + }, true, 'The copy is returned, because it is on top.'); + } + + path.guide = true; + + var hitResult = paper.project.hitTest(path.position, { + guides: true + }); + + equals(function() { + return !!hitResult; + }, true, 'A HitResult should be returned (2)'); + + if (hitResult) { + equals(function() { + return hitResult.item == path; + }, true, 'The path is returned, because it is a guide.'); + } +}); + +// TODO: project.hitTest(point, {type: AnItemType}); \ No newline at end of file