Skip to content

Commit e59ae78

Browse files
committed
Improve hit-testing tests for guides.
1 parent dca049c commit e59ae78

1 file changed

Lines changed: 18 additions & 27 deletions

File tree

test/tests/HitResult.js

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -371,39 +371,27 @@ test('hitting path bounding box', function() {
371371
});
372372

373373
test('hitting guides', function() {
374-
var path = new Path.Circle(new Point(100, 100), 50);
375-
path.fillColor = 'red';
376-
374+
var path = new Path.Circle({
375+
center: [100, 100],
376+
radius: 50,
377+
fillColor: 'red'
378+
});
377379
var copy = path.clone();
378380

379-
var hitResult = paper.project.hitTest(path.position);
381+
var result = paper.project.hitTest(path.position);
380382

381-
equals(function() {
382-
return !!hitResult;
383-
}, true, 'A HitResult should be returned (1)');
384-
385-
if (hitResult) {
386-
equals(function() {
387-
return hitResult.item == copy;
388-
}, true, 'The copy is returned, because it is on top.');
389-
}
383+
equals(result && result.item, copy,
384+
'The copy should be returned, because it is on top.');
390385

391386
path.guide = true;
392387

393-
var hitResult = paper.project.hitTest(path.position, {
388+
var result = paper.project.hitTest(path.position, {
394389
guides: true,
395390
fill: true
396391
});
397392

398-
equals(function() {
399-
return !!hitResult;
400-
}, true, 'A HitResult should be returned (2)');
401-
402-
if (hitResult) {
403-
equals(function() {
404-
return hitResult.item == path;
405-
}, true, 'The path is returned, because it is a guide.');
406-
}
393+
equals(result && result.item, path,
394+
'The path should be returned, because it is a guide.');
407395
});
408396

409397
test('hitting raster items', function() {
@@ -578,7 +566,7 @@ test('Hit testing guides.', function() {
578566
fillColor: 'blue'
579567
});
580568

581-
var strokePoint = circle2.bounds.rightCenter;
569+
var strokePoint = circle2.bounds.leftCenter;
582570

583571
equals(function() {
584572
return paper.project.hitTest(strokePoint).item === circle2;
@@ -587,12 +575,15 @@ test('Hit testing guides.', function() {
587575
circle2.guide = true;
588576

589577
equals(function() {
590-
var result = paper.project.hitTest(strokePoint, { guides: true });
591-
return result && result.item === circle1;
578+
return paper.project.hitTest(strokePoint).item === circle1;
592579
}, true);
593580

594581
equals(function() {
595-
return paper.project.hitTest(point).item === circle1;
582+
var result = paper.project.hitTest(strokePoint, {
583+
guides: true,
584+
fill: true
585+
});
586+
return result && result.item === circle2;
596587
}, true);
597588
});
598589

0 commit comments

Comments
 (0)