1 | import {
|
2 | pick
|
3 | } from 'min-dash';
|
4 |
|
5 | var POSITION_ATTRS = [ 'x', 'y' ];
|
6 |
|
7 | function extractPoints(point) {
|
8 | return pick(point, POSITION_ATTRS);
|
9 | }
|
10 |
|
11 |
|
12 | export default function(chai, utils) {
|
13 |
|
14 | var Assertion = chai.Assertion;
|
15 |
|
16 | function inspect(obj) {
|
17 | return utils.inspect(obj).replace(/\n /g, '');
|
18 | }
|
19 |
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | Assertion.addMethod('waypoints', function(exp) {
|
33 | var obj = this._obj;
|
34 |
|
35 | var strippedWaypoints = obj.waypoints.map(extractPoints),
|
36 | strippedExpectedWaypoints = exp.map(extractPoints);
|
37 |
|
38 | var matches = utils.eql(strippedWaypoints, strippedExpectedWaypoints);
|
39 |
|
40 | var strippedWaypointsStr = inspect(strippedWaypoints),
|
41 | strippedExpectedWaypointsStr = inspect(strippedExpectedWaypoints);
|
42 |
|
43 | var theAssert = new Assertion(strippedWaypoints);
|
44 |
|
45 |
|
46 | utils.transferFlags(this, theAssert, false);
|
47 |
|
48 | theAssert.assert(
|
49 | matches,
|
50 | 'expected <' + obj.id + '#waypoints> ' +
|
51 | 'to equal \n ' + strippedExpectedWaypointsStr +
|
52 | '\nbut got\n ' + strippedWaypointsStr,
|
53 | 'expected <' + obj.id + '#waypoints> ' +
|
54 | 'not to equal \n ' + strippedExpectedWaypoints
|
55 | );
|
56 | });
|
57 |
|
58 | |
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | Assertion.addMethod('startDocking', function(exp) {
|
69 | var obj = this._obj;
|
70 |
|
71 | var startPoint = obj.waypoints[0],
|
72 | startDocking = startPoint && startPoint.original;
|
73 |
|
74 | var matches = utils.eql(startDocking, exp);
|
75 |
|
76 | var startDockingStr = inspect(startDocking),
|
77 | expectedStartDockingStr = inspect(exp);
|
78 |
|
79 | var theAssert = new Assertion(startDocking);
|
80 |
|
81 |
|
82 | utils.transferFlags(this, theAssert, false);
|
83 |
|
84 | theAssert.assert(
|
85 | matches,
|
86 | 'expected <' + obj.id + '> to have startDocking ' +
|
87 | expectedStartDockingStr + ' but got ' + startDockingStr
|
88 | );
|
89 | });
|
90 |
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 | Assertion.addMethod('endDocking', function(exp) {
|
102 | var obj = this._obj;
|
103 |
|
104 | var endPoint = obj.waypoints[obj.waypoints.length - 1],
|
105 | endDocking = endPoint && endPoint.original;
|
106 |
|
107 | var matches = utils.eql(endDocking, exp);
|
108 |
|
109 | var endDockingStr = inspect(endDocking),
|
110 | expectedEndDockingStr = inspect(exp);
|
111 |
|
112 | var theAssert = new Assertion(endDocking);
|
113 |
|
114 |
|
115 | utils.transferFlags(this, theAssert, false);
|
116 |
|
117 | theAssert.assert(
|
118 | matches,
|
119 | 'expected <' + obj.id + '> to have endDocking ' +
|
120 | expectedEndDockingStr + ' but got ' + endDockingStr
|
121 | );
|
122 | });
|
123 |
|
124 | }
|