2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
pick
|
|
|
|
} from 'min-dash';
|
2017-10-11 13:19:36 +00:00
|
|
|
|
2020-01-20 10:50:03 +00:00
|
|
|
import {
|
2021-08-06 08:49:45 +00:00
|
|
|
getDi
|
2020-01-20 10:50:03 +00:00
|
|
|
} from 'lib/util/ModelUtil';
|
|
|
|
|
2017-10-11 13:19:36 +00:00
|
|
|
var POSITION_ATTRS = [ 'x', 'y' ];
|
|
|
|
|
2020-01-20 10:50:03 +00:00
|
|
|
function getPoint(point) {
|
2017-10-11 13:19:36 +00:00
|
|
|
return pick(point, POSITION_ATTRS);
|
|
|
|
}
|
|
|
|
|
2020-01-20 10:50:03 +00:00
|
|
|
function getPoints(waypoints) {
|
|
|
|
return waypoints.map(getPoint);
|
|
|
|
}
|
|
|
|
|
2017-10-11 13:19:36 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
export default function(chai, utils) {
|
2017-10-11 13:19:36 +00:00
|
|
|
|
|
|
|
var Assertion = chai.Assertion;
|
|
|
|
|
|
|
|
function inspect(obj) {
|
|
|
|
return utils.inspect(obj).replace(/\n /g, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A simple waypoints matcher, that verifies a connection
|
|
|
|
* consists of the correct connection points.
|
|
|
|
*
|
|
|
|
* Does not take the original docking into account.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* expect(connection).to.have.waypoints([ { x: 100, y: 100 }, { x: 0, y: 0 } ]);
|
|
|
|
*
|
|
|
|
* @param {Connection|Array<Point>} exp
|
|
|
|
*/
|
|
|
|
Assertion.addMethod('waypoints', function(exp) {
|
|
|
|
var obj = this._obj;
|
|
|
|
|
2020-01-20 10:50:03 +00:00
|
|
|
expect(obj).to.have.property('waypoints');
|
2017-10-11 13:19:36 +00:00
|
|
|
|
2020-01-20 10:50:03 +00:00
|
|
|
assertWaypoints(this, obj.id + '#waypoints', getPoints(obj.waypoints), getPoints(exp));
|
|
|
|
});
|
2017-10-11 13:19:36 +00:00
|
|
|
|
|
|
|
|
2020-01-20 10:50:03 +00:00
|
|
|
/**
|
|
|
|
* A simple waypoints matcher, that verifies a connection
|
|
|
|
* consists of the correct DI waypoints.
|
|
|
|
*
|
|
|
|
* Does not take the original docking into account.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* expect(connection).to.have.diWaypoints([ { x: 100, y: 100 }, { x: 0, y: 0 } ]);
|
|
|
|
*
|
|
|
|
* @param {Connection|Array<Point>} exp
|
|
|
|
*/
|
|
|
|
Assertion.addMethod('diWaypoints', function(exp) {
|
|
|
|
var obj = this._obj;
|
2017-10-11 13:19:36 +00:00
|
|
|
|
2021-08-06 08:49:45 +00:00
|
|
|
var di = getDi(obj);
|
2017-10-11 13:19:36 +00:00
|
|
|
|
2021-08-06 08:49:45 +00:00
|
|
|
expect(di).to.exist;
|
2020-01-20 10:50:03 +00:00
|
|
|
|
2021-08-06 08:49:45 +00:00
|
|
|
expect(di).to.have.property('waypoint');
|
2020-01-20 10:50:03 +00:00
|
|
|
|
2021-08-06 08:49:45 +00:00
|
|
|
assertWaypoints(this, di + '#waypoint', getPoints(di.waypoint), getPoints(exp));
|
2017-10-11 13:19:36 +00:00
|
|
|
});
|
|
|
|
|
2020-01-20 10:50:03 +00:00
|
|
|
|
2017-10-11 13:19:36 +00:00
|
|
|
/**
|
|
|
|
* A simple waypoints matcher, that verifies a connection
|
|
|
|
* has the given start docking.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* expect(connection).to.have.startDocking({ x: 100, y: 100 });
|
|
|
|
*
|
|
|
|
* @param {Point} exp
|
|
|
|
*/
|
|
|
|
Assertion.addMethod('startDocking', function(exp) {
|
|
|
|
var obj = this._obj;
|
|
|
|
|
|
|
|
var startPoint = obj.waypoints[0],
|
|
|
|
startDocking = startPoint && startPoint.original;
|
|
|
|
|
|
|
|
var matches = utils.eql(startDocking, exp);
|
|
|
|
|
|
|
|
var startDockingStr = inspect(startDocking),
|
|
|
|
expectedStartDockingStr = inspect(exp);
|
|
|
|
|
|
|
|
var theAssert = new Assertion(startDocking);
|
|
|
|
|
|
|
|
// transfer negate status
|
|
|
|
utils.transferFlags(this, theAssert, false);
|
|
|
|
|
|
|
|
theAssert.assert(
|
|
|
|
matches,
|
|
|
|
'expected <' + obj.id + '> to have startDocking ' +
|
|
|
|
expectedStartDockingStr + ' but got ' + startDockingStr
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A simple waypoints matcher, that verifies a connection
|
|
|
|
* has the given start docking.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
*
|
|
|
|
* expect(connection).to.have.endDocking({ x: 100, y: 100 });
|
|
|
|
*
|
|
|
|
* @param {Point} exp
|
|
|
|
*/
|
|
|
|
Assertion.addMethod('endDocking', function(exp) {
|
|
|
|
var obj = this._obj;
|
|
|
|
|
|
|
|
var endPoint = obj.waypoints[obj.waypoints.length - 1],
|
|
|
|
endDocking = endPoint && endPoint.original;
|
|
|
|
|
|
|
|
var matches = utils.eql(endDocking, exp);
|
|
|
|
|
|
|
|
var endDockingStr = inspect(endDocking),
|
|
|
|
expectedEndDockingStr = inspect(exp);
|
|
|
|
|
|
|
|
var theAssert = new Assertion(endDocking);
|
|
|
|
|
|
|
|
// transfer negate status
|
|
|
|
utils.transferFlags(this, theAssert, false);
|
|
|
|
|
|
|
|
theAssert.assert(
|
|
|
|
matches,
|
|
|
|
'expected <' + obj.id + '> to have endDocking ' +
|
|
|
|
expectedEndDockingStr + ' but got ' + endDockingStr
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-01-20 10:50:03 +00:00
|
|
|
|
|
|
|
// helpers ////////////////
|
|
|
|
|
|
|
|
function assertWaypoints(self, desc, waypoints, expectedWaypoints) {
|
|
|
|
|
|
|
|
var matches = utils.eql(waypoints, expectedWaypoints);
|
|
|
|
|
|
|
|
var waypointsStr = inspect(waypoints),
|
|
|
|
expectedWaypointsStr = inspect(expectedWaypoints);
|
|
|
|
|
|
|
|
var theAssert = new Assertion(waypoints);
|
|
|
|
|
|
|
|
// transfer negate status
|
|
|
|
utils.transferFlags(self, theAssert, false);
|
|
|
|
|
|
|
|
theAssert.assert(
|
|
|
|
matches,
|
|
|
|
'expected <' + desc + '> ' +
|
|
|
|
'to equal \n ' + expectedWaypointsStr +
|
|
|
|
'\nbut got\n ' + waypointsStr,
|
|
|
|
'expected <' + desc + '> ' +
|
2020-01-20 13:40:04 +00:00
|
|
|
'not to equal \n ' + expectedWaypoints,
|
|
|
|
expectedWaypoints
|
2020-01-20 10:50:03 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|