From: Robert Konigsberg Date: Wed, 13 Jun 2012 18:17:57 +0000 (-0400) Subject: Add assertion that gets all the drawn lines. X-Git-Tag: v1.0.0~238^2^2~27 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=8337da0a01d325f50c5b5f12d6d1dcedb42ed7c2;p=dygraphs.git Add assertion that gets all the drawn lines. --- diff --git a/auto_tests/tests/CanvasAssertions.js b/auto_tests/tests/CanvasAssertions.js index 6481c60..4059a0a 100644 --- a/auto_tests/tests/CanvasAssertions.js +++ b/auto_tests/tests/CanvasAssertions.js @@ -86,6 +86,35 @@ CanvasAssertions.assertLineDrawn = function(proxy, p1, p2, attrs) { }; /** + * Return the lines drawn with specific attributes. + * + * This merely looks for one of these four possibilities: + * moveTo(p1) -> lineTo(p2) + * moveTo(p2) -> lineTo(p1) + * lineTo(p1) -> lineTo(p2) + * lineTo(p2) -> lineTo(p1) + * + * attrs is meant to be used when you want to track things like + * color and stroke width. + */ +CanvasAssertions.getLinesDrawn = function(proxy) { + var lastCall; + var lines = []; + for (var i = 0; i < proxy.calls__.length; i++) { + var call = proxy.calls__[i]; + + if (call.name == "lineTo") { + if (lastCall != null) { + lines.push([lastCall, call]); + } + } + + lastCall = (call.name === "lineTo" || call.name === "moveTo") ? call : null; + } + return lines; +}; + +/** * Verifies that every call to context.save() has a matching call to * context.restore(). */