Skip to content

Commit cb65399

Browse files
committed
Add 2 more HitResult tests, which test hitting selected paths and guides.
1 parent 738573e commit cb65399

1 file changed

Lines changed: 59 additions & 1 deletion

File tree

test/tests/HitResult.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ test('hitting a stroked path', function() {
6969
}, true);
7070
});
7171

72+
test('hitting a selected path', function() {
73+
var path = new Path.Circle([50, 50], 50);
74+
path.fillColor = 'red';
75+
76+
var hitResult = paper.project.hitTest([75, 75], {
77+
selected: true
78+
});
79+
equals(function() {
80+
return hitResult == null;
81+
}, true, 'Since the path is not selected, the hit-test should return null');
82+
83+
path.selected = true;
84+
hitResult = paper.project.hitTest([75, 75]);
85+
equals(function() {
86+
return hitResult.type == 'fill';
87+
}, true);
88+
equals(function() {
89+
return hitResult.item == path;
90+
}, true);
91+
});
92+
7293
test('hitting path segments', function() {
7394
var path = new Path([0, 0], [10, 10], [20, 0]);
7495

@@ -297,4 +318,41 @@ test('hitting path bounding box', function() {
297318
return hitResult.point.toString();
298319
},path.bounds.topLeft.toString());
299320
}
300-
});
321+
});
322+
323+
test('hitting guides', function() {
324+
var path = new Path.Circle(new Point(100, 100), 50);
325+
path.fillColor = 'red';
326+
327+
var copy = path.clone();
328+
329+
var hitResult = paper.project.hitTest(path.position);
330+
331+
equals(function() {
332+
return !!hitResult;
333+
}, true, 'A HitResult should be returned (1)');
334+
335+
if (hitResult) {
336+
equals(function() {
337+
return hitResult.item == copy;
338+
}, true, 'The copy is returned, because it is on top.');
339+
}
340+
341+
path.guide = true;
342+
343+
var hitResult = paper.project.hitTest(path.position, {
344+
guides: true
345+
});
346+
347+
equals(function() {
348+
return !!hitResult;
349+
}, true, 'A HitResult should be returned (2)');
350+
351+
if (hitResult) {
352+
equals(function() {
353+
return hitResult.item == path;
354+
}, true, 'The path is returned, because it is a guide.');
355+
}
356+
});
357+
358+
// TODO: project.hitTest(point, {type: AnItemType});

0 commit comments

Comments
 (0)