diff --git a/.babelrc b/.babelrc index 21739e918..858d464c5 100644 --- a/.babelrc +++ b/.babelrc @@ -2,10 +2,8 @@ "presets": ["react", "es2015"], "plugins": [ "syntax-async-functions", - ["transform-async-to-module-method", { - "module": "bluebird", - "method": "coroutine" - }], + "transform-regenerator", "transform-class-properties" ], + "sourceMaps": true } diff --git a/__prelude.js b/__prelude.js index e60816267..0b177ce98 100644 --- a/__prelude.js +++ b/__prelude.js @@ -1,5 +1,4 @@ 'use strict'; -require('babel/polyfill'); const _ = require('lodash'); const Promise = (global || window).Promise = require('bluebird'); diff --git a/app/index.html b/app/index.html index 93a53acfd..4ca702551 100755 --- a/app/index.html +++ b/app/index.html @@ -11,6 +11,7 @@
+ - - - - - \ No newline at end of file diff --git a/test/spec/2D.js b/test/spec/2D.js deleted file mode 100644 index 82367d93b..000000000 --- a/test/spec/2D.js +++ /dev/null @@ -1,75 +0,0 @@ -'use strict'; - -describe('2D utils', function () { - - // load the controller's module - beforeEach(module('prototypo.2D')); - - describe('transformToMatrix2d', function() { - it('can convert a single rotate command to a matrix2d', inject(function( transformToMatrix2d ) { - var m = transformToMatrix2d( 'rotate(90)' ); - - expect( +m[0].toFixed(6) ).toBe( 0 ); - expect( m[1] ).toBe( 1 ); - expect( m[2] ).toBe( -1 ); - expect( +m[3].toFixed(6) ).toBe( 0 ); - expect( m[4] ).toBe( 0 ); - expect( m[5] ).toBe( 0 ); - })); - - it('can convert a single translate command to a matrix2d', inject(function( transformToMatrix2d ) { - var m = transformToMatrix2d( 'translate(-100, -100)' ); - - expect( m[0] ).toBe( 1 ); - expect( m[1] ).toBe( 0 ); - expect( m[2] ).toBe( 0 ); - expect( m[3] ).toBe( 1 ); - expect( m[4] ).toBe( -100 ); - expect( m[5] ).toBe( -100 ); - })); - - it('can convert a single skewX command to a matrix2d', inject(function( transformToMatrix2d ) { - var m = transformToMatrix2d( 'skewX(-45)' ); - - expect( m[0] ).toBe( 1 ); - expect( m[1] ).toBe( 0 ); - expect( m[2] ).toBe( -1 ); - expect( m[3] ).toBe( 1 ); - expect( m[4] ).toBe( 0 ); - expect( m[5] ).toBe( 0 ); - })); - - it('stops parsing transforms when encountering a skewX(90) command', inject(function( transformToMatrix2d ) { - var m = transformToMatrix2d( 'skewX(90)' ); - - expect( m[0] ).toBe( 1 ); - expect( m[1] ).toBe( 0 ); - expect( m[2] ).toBe( 0 ); - expect( m[3] ).toBe( 1 ); - expect( m[4] ).toBe( 0 ); - expect( m[5] ).toBe( 0 ); - })); - - it('can convert multiple transform commands to a matrix2d', inject(function( transformToMatrix2d ) { - var m = transformToMatrix2d( 'translate(-100, -100) rotate(90) translate(100, 100) skewX(-45)' ); - - expect( +m[0].toFixed(6) ).toBe( 0 ); - expect( m[1] ).toBe( 1 ); - expect( m[2] ).toBe( -1 ); - expect( m[3] ).toBe( -1 ); - expect( m[4] ).toBe( -200 ); - expect( m[5] ).toBe( 0 ); - })); - - it('accepts a tranform-origin as a second parameter', inject(function( transformToMatrix2d ) { - var m = transformToMatrix2d( 'rotate(90)', {x: 50, y: -50} ); - - expect( +m[0].toFixed(6) ).toBe( 0 ); - expect( m[1] ).toBe( 1 ); - expect( m[2] ).toBe( -1 ); - expect( +m[3].toFixed(6) ).toBe( 0 ); - expect( m[4] ).toBe( 0 ); - expect( m[5] ).toBe( -100 ); - })); - }); -}); \ No newline at end of file diff --git a/test/spec/Collection.js b/test/spec/Collection.js deleted file mode 100644 index f4cd155ff..000000000 --- a/test/spec/Collection.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -describe('PointCollection structure', function() { - - beforeEach(module('prototypo.Collection', 'prototypo.Point')); - - it('allows a set of points to be created and reused', inject(function( Collection, Point ) { - var points = new Collection( Point ); - - points(0)._(1,2); - points(1)._(3,4); - - expect(points(0).x).toBe(1); - expect(points(0).y).toBe(2); - expect(points(1).x).toBe(3); - expect(points(1).y).toBe(4); - - points(0)._(5,6); - - expect(points(0).x).toBe(5); - expect(points(0).y).toBe(6); - })); - -}); \ No newline at end of file diff --git a/test/spec/Contour.js b/test/spec/Contour.js deleted file mode 100644 index 9cd8d1528..000000000 --- a/test/spec/Contour.js +++ /dev/null @@ -1,172 +0,0 @@ -'use strict'; - -describe('Contour structure', function () { - - // load the controller's module - beforeEach(module('prototypo.Contour')); - - it('should create a nodelist from nodedata', inject(function(Contour) { - var ct = new Contour( - {c: [0, 0]}, - {c: [0, 100]}, - {c: [100, 100]}, - {c: [100, 0]} - ); - - expect(ct.nodes.length).toBe(4); - expect(ct.cycle).toBe(true); - expect(ct.nodes[ct.nodes.length - 1].next).toBe(ct.nodes[0]); - })); - - it('should create a nodelist from nodedata, from an array of nodes', inject(function(Contour) { - var ct = new Contour([ - {c: [0, 0]}, - {c: [0, 100]}, - {c: [100, 100]}, - {c: [100, 0]} - ]); - - expect(ct.nodes.length).toBe(4); - expect(ct.cycle).toBe(true); - })); - - it('should translate to an SVG path', inject(function(Contour) { - var ct = new Contour([ - {c: [0, 0]}, - {c: [0, 100]}, - {c: [100, 100]}, - {c: [100, 0]} - ]); - - ct.updateControls(); - - ct.toSVG(); - - expect(ct.d).toBe([ - 'M 0 0', - 'C -28 28 -28 72 0 100', - 'C 28 128 72 128 100 100', - 'C 128 72 128 28 100 0', - 'C 72 -28 28 -28 0 0', - 'Z' - ].join(' ')); - })); - - describe('Update controls with Hobby', function() { - - it('should be able to update the position of its control points', inject(function(Contour) { - var ct = new Contour([ - {c: [0, 0]}, - {c: [0, 100]}, - {c: [100, 100]}, - {c: [100, 0]} - ]); - - expect(ct.nodes[0].next).toBe(ct.nodes[1]); - - ct.updateControls(); - - // there's no way to predict that the expected value is 28, - // but last time the script worked it produced 28 :) - expect(Math.round(ct.nodes[0].lc.x)).toBe(28); - expect(Math.round(ct.nodes[0].lc.y)).toBe(-28); - expect(Math.round(ct.nodes[0].rc.x)).toBe(-28); - expect(Math.round(ct.nodes[0].rc.y)).toBe(28); - - ct.nodes[0].y = 20; - ct.updateControls(); - - // same here - expect(Math.round(ct.nodes[0].lc.x)).toBe(24); - expect(Math.round(ct.nodes[0].lc.y)).toBe(-14); - expect(Math.round(ct.nodes[0].rc.x)).toBe(-17); - expect(Math.round(ct.nodes[0].rc.y)).toBe(45); - })); - - it('update controls when there\'s one line in the shape', inject(function(Contour) { - var ct = new Contour([ - {c: [0, 0], rType: 'line'}, - {c: [0, 100], lType: 'line'}, - {c: [100, 100]}, - {c: [100, 0]} - ]); - - ct.updateControls(); - - // there's no way to predict that the expected value is 28, - // but last time the script worked it produced 28 :) - expect(Math.round(ct.nodes[0].rc.x)).toBe(0); - expect(Math.round(ct.nodes[0].rc.y)).toBe(0); - expect(Math.round(ct.nodes[1].lc.x)).toBe(0); - expect(Math.round(ct.nodes[1].lc.y)).toBe(100); - - ct.nodes[0].y = 20; - // currently we need to re-set the control type to update the control position - ct.nodes[0].rType = 'line'; - ct.updateControls(); - - // ditto - expect(Math.round(ct.nodes[0].rc.x)).toBe(0); - expect(Math.round(ct.nodes[0].rc.y)).toBe(20); - expect(Math.round(ct.nodes[1].lc.x)).toBe(0); - expect(Math.round(ct.nodes[1].lc.y)).toBe(100); - - // ditto - expect(Math.round(ct.nodes[2].lc.x)).toBe(72); - expect(Math.round(ct.nodes[2].lc.y)).toBe(127); - expect(Math.round(ct.nodes[2].rc.x)).toBe(129); - expect(Math.round(ct.nodes[2].rc.y)).toBe(72); - })); - - it('update controls when there are multiple lines in the shape', inject(function(Contour) { - var ct = new Contour([ - {c: [0, 0], rType: 'line'}, - {c: [0, 100], lType: 'line', rType: 'line'}, - {c: [100, 100], lType: 'line'}, - {c: [100, 0]} - ]); - - ct.updateControls(); - - // ditto - expect(Math.round(ct.nodes[3].lc.x)).toBe(128); - expect(Math.round(ct.nodes[3].lc.y)).toBe(28); - expect(Math.round(ct.nodes[3].rc.x)).toBe(72); - expect(Math.round(ct.nodes[3].rc.y)).toBe(-28); - })); - - // this is equivalent to the first update controls test in skeleton.js - it('update controls with a complex contour', inject(function(Contour) { - var ct = new Contour([ - {c: [-10, 0], lType: 'line', rType: 'line'}, - {c: [50, 100], lType: 'line'}, - {c: [110, 0], rType: 'line'}, - {c: [90, 0], lType: 'line'}, - {c: [50, 90], rType: 'line'}, - {c: [10, 0], lType: 'line', rType: 'line'} - ]), - nodes = ct.nodes; - - ct.updateControls(); - - expect(nodes[0].lType).toBe('line'); - expect(nodes[0].rType).toBe('line'); - - expect(nodes[1].lType).toBe('line'); - expect(nodes[1].rType).toBe('open'); - - expect(nodes[2].lType).toBe('open'); - expect(nodes[2].rType).toBe('line'); - - expect(nodes[3].lType).toBe('line'); - expect(nodes[3].rType).toBe('open'); - - expect(nodes[4].lType).toBe('open'); - expect(nodes[4].rType).toBe('line'); - - expect(nodes[5].lType).toBe('line'); - expect(nodes[5].rType).toBe('line'); - })); - - }); -}); \ No newline at end of file diff --git a/test/spec/History.js b/test/spec/History.js deleted file mode 100644 index ffd7d5d8f..000000000 --- a/test/spec/History.js +++ /dev/null @@ -1,110 +0,0 @@ -'use strict'; - -// load the controller's module -beforeEach(module('prototypo.History')); - -/* jshint camelcase: false */ -describe('History', function() { - - var dummy = { 'thickness' : 0 }; - - it('starts with the reading head at -1 and an empty history', inject(function(History) { - expect(History.readingHead).toBe(-1); - expect(History._history.length).toBe(0); - })); - - it('should increment our reading head when we add changes to the history', inject(function(History) { - History.add( { 'thickness' : +100 } ); - expect(History.readingHead).toBe(0); - expect(History._history.length).toBe(1); - })); - - it('should decrement our reading head when we undo changes to the history', inject(function(History) { - History.add( { 'thickness' : +100 } ); - History.undo(dummy); - expect(History.readingHead).toBe(-1); - expect(History._history.length).toBe(1); - })); - - it('should increment our reading head when we redo changes to the history', inject(function(History) { - History.add( { 'thickness' : +100 } ); - History.undo(dummy); - History.redo(dummy); - expect(History.readingHead).toBe(0); - expect(History._history.length).toBe(1); - })); - - it('shouldn\'t decrement our reading head when we have nothing to undo', inject(function(History) { - History.add( { 'thickness' : +100 } ); - History.undo(dummy); - expect(History.undo(dummy)).toBe(false); - expect(History.readingHead).toBe(-1); - expect(History._history.length).toBe(1); - })); - - it('shouldn\'t increment our reading head when we have nothing to redo', inject(function(History) { - History.redo(dummy); - expect(History.redo(dummy)).toBe(false); - expect(History.readingHead).toBe(-1); - expect(History._history.length).toBe(0); - })); - - it('should undo last changes', inject(function(History) { - var changes = { 'thickness' : +50 }; - History.add(changes); - expect(History.undo(dummy)).toBe(changes); - })); - - it('should redo previous changes', inject(function(History) { - var changes1 = { 'thickness' : +50 }; - var changes2 = { 'thickness' : +100 }; - History.add( changes1 ); - History.add( changes2 ); - History.undo(dummy); - expect(History.redo(dummy)).toBe(changes2); - })); - - it('should modify fontValues when we undo', inject(function(History) { - var changes1 = { 'thickness' : +50 }; - var changes2 = { 'thickness' : +100 }; - var fontValues = { 'thickness' : 300 }; - History.add( changes1 ); - History.add( changes2 ); - History.undo(fontValues); - expect(fontValues.thickness).toBe(200); - })); - - it('should modify fontValues when we redo', inject(function(History) { - var fontValues = { 'thickness' : 300 }; - var changes = { 'thickness' : +50 }; - History.add( changes ); - History.undo(fontValues); - History.redo(fontValues); - expect(fontValues.thickness).toBe(300); - })); - - it('it should add changes after the reading head', inject(function(History) { - expect(History.readingHead).toBe(-1); - expect(History._history.length).toBe(0); - History.add( { 'thickness' : +100 } ); - History.add( { 'thickness' : +150 } ); - History.add( { 'thickness' : +200 } ); - var fontValues = { 'thickness' : 500 }; - - expect(fontValues.thickness).toBe(500); - expect(History.readingHead).toBe(2); - expect(History._history.length).toBe(3); - - History.undo(fontValues); - - expect(fontValues.thickness).toBe(300); - expect(History.readingHead).toBe(1); - expect(History._history.length).toBe(3); - - History.add( { 'thickness' : +10 } ); - - expect(History.readingHead).toBe(2); - expect(History._history.length).toBe(3); - })); - -}); \ No newline at end of file diff --git a/test/spec/Node.js b/test/spec/Node.js deleted file mode 100644 index 89edd1c70..000000000 --- a/test/spec/Node.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -describe('Node structure', function () { - - // load the controller's module - beforeEach(module('prototypo.Node')); - - it('should create a point that inherits from Point', inject(function(Node) { - var n = new Node({ - c: [12,23], - lc: [34,45], - rc: [56,67], - a: 'b' - }); - - expect(n.x).toBe(12); - expect(n.y).toBe(23); - expect(n.lc.x).toBe(34); - expect(n.lc.y).toBe(45); - expect(n.rc.x).toBe(56); - expect(n.rc.y).toBe(67); - expect(n.a).toBe('b'); - expect(n.lType).toBe('open'); - expect(n.rType).toBe('open'); - expect(n.lTension).toBe(1); - expect(n.rTension).toBe(1); - })); -}); \ No newline at end of file diff --git a/test/spec/NodeList.js b/test/spec/NodeList.js deleted file mode 100644 index b3f5091f9..000000000 --- a/test/spec/NodeList.js +++ /dev/null @@ -1,91 +0,0 @@ -'use strict'; - -describe('NodeList structure', function () { - - // load the controller's module - beforeEach(module('prototypo.NodeList')); - - it('should create a linked node list from node data', inject(function(NodeList) { - var nl = new NodeList( - {c: [0, 0]}, - {c: [0, 100]}, - {c: [100, 100]}, - {c: [100, 0]} - ); - - expect(nl.length).toBe(4); - expect(nl.cycle).toBe(false); - expect(nl.lastNode).toBe(nl.nodes[3]); - expect(nl.nodes[0].next).toBe(nl.nodes[1]); - expect(nl.nodes[1].next).toBe(nl.nodes[2]); - expect(nl.nodes[2].next).toBe(nl.nodes[3]); - expect(nl.nodes[3].next).toBe(nl.nodes[0]); - })); - - it('should create a linked node list from an array of node data', inject(function(NodeList) { - var nl = new NodeList([ - {c: [0, 0]}, - {c: [0, 100]}, - {c: [100, 100]}, - {c: [100, 0]} - ]); - - expect(nl.length).toBe(4); - expect(nl.lastNode).toBe(nl.nodes[3]); - expect(nl.nodes[0].next).toBe(nl.nodes[1]); - expect(nl.nodes[1].next).toBe(nl.nodes[2]); - expect(nl.nodes[2].next).toBe(nl.nodes[3]); - expect(nl.nodes[3].next).toBe(nl.nodes[0]); - })); - - it('should create a cycling linked node list from node data', inject(function(NodeList) { - var nl = new NodeList([ - {c: [0, 0]}, - {c: [0, 100]}, - {c: [100, 100]}, - {c: [100, 0]} - ], 'cycle'); - - expect(nl.nodes.length).toBe(4); - expect(nl.nodes[0].prev).toBe(nl.nodes[3]); - expect(nl.nodes[3].next).toBe(nl.nodes[0]); - })); - - it('should handle line instructions between nodes', inject(function(NodeList) { - var nl = new NodeList([ - {c: [0, 0]}, - {c: [0, 100]}, - 'line', - {c: [100, 100]}, - {c: [100, 0]} - ]); - - expect(nl.nodes.length).toBe(4); - expect(nl.nodes[1].next).toBe(nl.nodes[2]); - expect(nl.nodes[2].prev).toBe(nl.nodes[1]); - - expect(nl.nodes[1].rType).toBe('line'); - expect(nl.nodes[2].lType).toBe('line'); - })); - - it('should be possible to add a NodeList to a NodeList', inject(function(NodeList) { - var nl1 = new NodeList([ - {c: [0, 0]}, - {c: [0, 100]} - ], 'cycle'); - - var nl2 = new NodeList([ - {c: [100, 100]}, - {c: [100, 0]} - ], 'cycle'); - - nl1.add( nl2 ); - - expect(nl1.length).toBe(4); - expect(nl1.lastNode).toBe(nl1.nodes[3]); - expect(nl1.nodes[1].next).toBe(nl2.nodes[0]); - expect(nl2.nodes[0].prev).toBe(nl1.nodes[1]); - expect(nl1.nodes[0].prev).toBe(nl1.nodes[3]); - expect(nl1.nodes[3].next).toBe(nl1.nodes[0]); - })); -}); \ No newline at end of file diff --git a/test/spec/Point.js b/test/spec/Point.js deleted file mode 100755 index 080397ae6..000000000 --- a/test/spec/Point.js +++ /dev/null @@ -1,216 +0,0 @@ -'use strict'; - -describe('Point structure', function () { - - // load the controller's module - beforeEach(module('prototypo.Point')); - - var _Point, p0, p1, p2, p3, p4, p5, p6; - - beforeEach(inject(function ( Point ) { - _Point = Point; - p0 = new Point(3,6); - p1 = Point(2,5); - p2 = Point([2,5]); - p3 = Point('2','5'); - p4 = Point(['2','5']); - p5 = Point(p1); - p6 = Point({x: 2, y: 5}); - })); - - it('can be called with or without new', function() { - expect(p0 instanceof _Point).toBe(true); - expect(p1 instanceof _Point).toBe(true); - }); - - it('accepts two args: x and y', function() { - expect(p0.x).toBe(3); - expect(p0.y).toBe(6); - - expect(p1.x).toBe(2); - expect(p1.y).toBe(5); - }); - - it('accepts an array arg: [x,y]', function() { - expect(p2.x).toBe(2); - expect(p2.y).toBe(5); - }); - - it('accepts an object arg: {x:x,y:y}',function() { - expect(p6.x).toBe(2); - expect(p6.y).toBe(5); - }); - - it('accepts number and string args and turns them into numbers', function() { - expect(typeof p3.x).toBe('number'); - expect(typeof p4.x).toBe('number'); - }); - - it('can be serialized', function() { - expect(p1 + '').toBe('2 5'); - }); - - it('accepts a Point as an argument, and this results in an independent clone', function() { - p1.x = 4; - p1.y = 7; - - expect(p5.x).toBe(2); - expect(p5.y).toBe(5); - }); - - it('accepts undefined parameters', inject(function(Point) { - var p1 = Point( undefined, 5 ); - expect(p1.x).toBeNaN(); - expect(p1.y).toBe(5); - - var p2 = Point( 2, undefined ); - expect(p2.y).toBeNaN(); - expect(p2.x).toBe(2); - - var p3 = Point([undefined, 5]); - expect(p3.x).toBeNaN(); - expect(p3.y).toBe(5); - - var p4 = Point([2, undefined]); - expect(p4.y).toBeNaN(); - expect(p4.x).toBe(2); - - var p5 = Point({y: 5}); - expect(p5.x).toBeNaN(); - expect(p5.y).toBe(5); - - var p6 = Point({x: 2}); - expect(p6.y).toBeNaN(); - expect(p6.x).toBe(2); - })); -}); - -describe('translatePoint', function () { - - // load the controller's module - beforeEach(module('prototypo.Point')); - - var _Point, p0, p1, p2, p3, p4, p5, p6; - - beforeEach(inject(function ( Point ) { - _Point = Point; - p0 = new Point(3,6); - p1 = Point(2,5); - p2 = Point([2,5]); - p3 = Point('2','5'); - p4 = Point(['2','5']); - p5 = Point(p1); - p6 = Point({x: 2, y: 5}); - })); - - it('can translate a Point on x axis', inject(function( Point ) { - var p1 = Point(2,5); - p1.translateX(4); - - expect(p1.x).toBe(6); - })); - - it('can translate a Point on y axis', inject(function( Point ) { - var p1 = Point(2,5); - p1.translateY(-2); - - expect(p1.y).toBe(3); - })); - - it('can translate a Point on x and y axis', inject(function( Point ) { - var p1 = Point(2,5); - p1.translate(4,-2); - - expect(p1.x).toBe(6); - expect(p1.y).toBe(3); - })); - - it('can translate a Point with NaN coords', inject(function( Point ) { - var p1 = Point(2,undefined); - p1.translate(4,-2); - - expect(p1.x).toBe(6); - expect(p1.y).toBeNaN(); - - var p2 = Point(undefined,5); - p2.translate(4,-2); - - expect(p2.y).toBe(3); - expect(p2.x).toBeNaN(); - })); - - it('accepts the same arguments in Point constructor and translate method', inject(function(Point) { - expect( Point(0,0).translate( 10, 20 ).toString() ).toBe('10 20'); - expect( Point(0,0).translate( [10, 20] ).toString() ).toBe('10 20'); - expect( Point(0,0).translate( {x: 10, y: 20} ).toString() ).toBe('10 20'); - expect( Point(0,0).translate( Point(10, 20) ).toString() ).toBe('10 20'); - })); -}); - -/*describe('Point structure', function () { - - beforeEach(module('prototypo.Point', 'prototypo.Segment')); - - var seg1, - seg2, - p1, - p2, - p3, - p4; - - beforeEach(inject(function( Segment, Point ) { - seg1 = Segment( 'L 50 100', Point(0,0) ); - seg2 = Segment( 'M 30 -20', Point(-20, 80) ); - p1 = Point(40,80); - p2 = Point(10,20); - p3 = Point(-20,80); - p4 = Point(30,-20); - })); - - it('should find a point on a straight Segment, given x or y', inject(function( pointOn ) { - expect(pointOn({ x: 20 }, seg1).toString()).toBe('20 40'); - - expect(pointOn({ y: 60 }, seg1).toString()).toBe('30 60'); - - expect(pointOn({ x: 0 }, seg2).toString()).toBe('0 40'); - - expect(pointOn({ y: 0 }, seg2).toString()).toBe('20 0'); - })); - - it('should find a point between two Points, given x or y', inject(function( pointOn ) { - expect(pointOn({ x: 20 }, [p1,p2]).toString()).toBe('20 40'); - - expect(pointOn({ y: 60 }, [p1,p2]).toString()).toBe('30 60'); - - expect(pointOn({ x: 0 }, [p3,p4]).toString()).toBe('0 40'); - - expect(pointOn({ y: 0 }, [p3,p4]).toString()).toBe('20 0'); - })); - - it('handles undefined .on, given x or y', inject(function( pointOn ) { - expect(pointOn({ x: 20 }, undefined).toString()).toBe('20 NaN'); - - expect(pointOn({ y: 60 }, undefined).toString()).toBe('NaN 60'); - - expect(pointOn({ x: 20 }, [undefined, p1]).toString()).toBe('20 NaN'); - - expect(pointOn({ y: 60 }, [p1, undefined]).toString()).toBe('NaN 60'); - })); - - it('should find the intersection of two lines', inject(function( pointOn, Segment, Point ) { - expect(pointOn([], [ - Segment('L 50 50', Point(0,0)), - Segment('L 50 0', Point(0,50)) - ]).toString()).toBe('25 25'); - - expect(pointOn([], [ - [Point(0,0), Segment('L 50 50', Point(0,0))], - [Segment('L 50 0', Point(0,50)), Point(0,50)] - ]).toString()).toBe('25 25'); - - expect(pointOn([], [ - [Point(0,0), [50, 50]], - [{x: 50, y: 0}, Point(0,50)] - ]).toString()).toBe('25 25'); - })); -});*/ \ No newline at end of file diff --git a/test/spec/Skeleton.js b/test/spec/Skeleton.js deleted file mode 100644 index 3361f528e..000000000 --- a/test/spec/Skeleton.js +++ /dev/null @@ -1,288 +0,0 @@ -'use strict'; - -describe('Skeleton structure', function () { - - // load the controller's module - beforeEach(module('prototypo.Skeleton')); - - it('should create contour nodes on skeleton creation', inject(function(Skeleton) { - var sk = new Skeleton( - {c: [0,1]}, - {c: [2,3]} - ); - - expect(sk.contours.length).toBe(1); - expect(sk.contours[0].nodes.length).toBe(4); - expect(sk.contours[0].cycle).toBe(true); - })); - - it('should create contour nodes on skeleton creation, from an array of nodes', inject(function(Skeleton) { - var sk = new Skeleton([ - {c: [0,1]}, - {c: [2,3]} - ]); - - expect(sk.contours.length).toBe(1); - expect(sk.contours[0].nodes.length).toBe(4); - expect(sk.contours[0].cycle).toBe(true); - })); - - it('should handle line instructions in skeleton', inject(function(Skeleton) { - var sk = new Skeleton([ - {c: [0,1]}, - 'line', - {c: [2,3]} - ]); - - expect(sk.contours.length).toBe(1); - expect(sk.contours[0].nodes.length).toBe(4); - expect(sk.contours[0].cycle).toBe(true); - - expect(sk.nodes[0].rType).toBe('line'); - expect(sk.nodes[1].lType).toBe('line'); - })); - - it('should create two contours when the skeleton cycles', inject(function(Skeleton) { - var sk = new Skeleton([ - {c: [0,1]}, - {c: [2,3]}, - 'cycle' - ]); - - expect(sk.contours.length).toBe(2); - expect(sk.contours[0].nodes.length).toBe(2); - expect(sk.contours[1].nodes.length).toBe(2); - expect(sk.contours[0].cycle).toBe(true); - expect(sk.contours[1].cycle).toBe(true); - })); - - it('should be able to link the nodes of an open skeleton', inject(function(Skeleton) { - var sk = new Skeleton([ - {c: [0,0], width: 20}, - {c: [50,100], width: 10, angle: -90, distr: 0}, - {c: [100,0], width: 20, angle: -180} - ]), - nodes = sk.contours[0].nodes; - - expect(nodes[0].next).toBe(nodes[1]); - expect(nodes[1].next).toBe(nodes[2]); - expect(nodes[2].next).toBe(nodes[3]); - expect(nodes[3].next).toBe(nodes[4]); - expect(nodes[4].next).toBe(nodes[5]); - expect(nodes[5].next).toBe(nodes[0]); - - expect(sk.nodes[0].left.rc).toBe(nodes[0].rc); - expect(sk.nodes[0].left.lc).toBe(nodes[0].lc); - expect(sk.nodes[1].left.rc).toBe(nodes[1].rc); - expect(sk.nodes[1].left.lc).toBe(nodes[1].lc); - expect(sk.nodes[2].left.rc).toBe(nodes[2].rc); - expect(sk.nodes[2].left.lc).toBe(nodes[2].lc); - expect(sk.nodes[2].right.rc).toBe(nodes[3].rc); - expect(sk.nodes[2].right.lc).toBe(nodes[3].lc); - expect(sk.nodes[1].right.rc).toBe(nodes[4].rc); - expect(sk.nodes[1].right.lc).toBe(nodes[4].lc); - expect(sk.nodes[0].right.rc).toBe(nodes[5].rc); - expect(sk.nodes[0].right.lc).toBe(nodes[5].lc); - })); - - /*it('should be able to link the nodes of an open skeleton containing lines', inject(function(Skeleton) { - var sk = new Skeleton([ - {c: [0,0], width: 20, rType: 'line'}, - {c: [50,100], width: 10, angle: -90, distr: 0, lType: 'line'}, - {c: [100,0], width: 20, angle: -180} - ]), - nodes = sk.contours[0].nodes; - - expect(nodes.length).toBe(8); - - expect(nodes[0].next).toBe(nodes[1]); - expect(nodes[1].next).toBe(nodes[2]); - expect(nodes[2].next).toBe(nodes[3]); - expect(nodes[3].next).toBe(nodes[4]); - expect(nodes[4].next).toBe(nodes[5]); - expect(nodes[5].next).toBe(nodes[6]); - expect(nodes[6].next).toBe(nodes[7]); - expect(nodes[7].next).toBe(nodes[0]); - - expect(sk.nodes[0].left[0].rc).toBe(nodes[0].rc); - expect(sk.nodes[0].left[0].lc).toBe(nodes[0].lc); - expect(sk.nodes[1].left[0].rc).toBe(nodes[1].rc); - expect(sk.nodes[1].left[0].lc).toBe(nodes[1].lc); - expect(sk.nodes[1].left[1].rc).toBe(nodes[2].rc); - expect(sk.nodes[1].left[1].lc).toBe(nodes[2].lc); - expect(sk.nodes[2].left[0].rc).toBe(nodes[3].rc); - expect(sk.nodes[2].left[0].lc).toBe(nodes[3].lc); - expect(sk.nodes[2].right[0].rc).toBe(nodes[4].rc); - expect(sk.nodes[2].right[0].lc).toBe(nodes[4].lc); - // I'm not 100% sure right[0] should comes before right 1 - expect(sk.nodes[1].right[0].rc).toBe(nodes[5].rc); - expect(sk.nodes[1].right[0].lc).toBe(nodes[5].lc); - expect(sk.nodes[1].right[1].rc).toBe(nodes[6].rc); - expect(sk.nodes[1].right[1].lc).toBe(nodes[6].lc); - expect(sk.nodes[0].right[0].rc).toBe(nodes[7].rc); - expect(sk.nodes[0].right[0].lc).toBe(nodes[7].lc); - }));*/ - - it('should be able to link the nodes of a cycling skeleton', inject(function(Skeleton) { - var sk = new Skeleton([ - {c: [50, 100], width: 20, angle: 90, distr: 1}, - {c: [100, 50], width: 20, angle: 0, distr: 1 }, - {c: [50, 0], width: 20, angle: -90, distr: 1}, - {c: [0, 50], width: 20, angle: -180, distr: 1}, - 'cycle' - ]), - nodes = sk.nodes; - - sk.expand({}); - - expect(nodes[0].left.toString()).toBe(sk.contours[0].nodes[0].toString()); - expect(nodes[1].left.toString()).toBe(sk.contours[0].nodes[1].toString()); - expect(nodes[2].left.toString()).toBe(sk.contours[0].nodes[2].toString()); - expect(nodes[3].left.toString()).toBe(sk.contours[0].nodes[3].toString()); - - expect(nodes[0].right.toString()).toBe(sk.contours[1].nodes[3].toString()); - expect(nodes[1].right.toString()).toBe(sk.contours[1].nodes[2].toString()); - expect(nodes[2].right.toString()).toBe(sk.contours[1].nodes[1].toString()); - expect(nodes[3].right.toString()).toBe(sk.contours[1].nodes[0].toString()); - - - expect(nodes[0].left.next.toString()).toBe(nodes[1].left.toString()); - expect(nodes[1].left.next.toString()).toBe(nodes[2].left.toString()); - expect(nodes[2].left.next.toString()).toBe(nodes[3].left.toString()); - expect(nodes[3].left.next.toString()).toBe(nodes[0].left.toString()); - - expect(nodes[0].right.next.toString()).toBe(nodes[3].right.toString()); - expect(nodes[1].right.next.toString()).toBe(nodes[0].right.toString()); - expect(nodes[2].right.next.toString()).toBe(nodes[1].right.toString()); - expect(nodes[3].right.next.toString()).toBe(nodes[2].right.toString()); - })); - - it('should be able to expand the skeleton using width/angle/distr params', inject(function(Skeleton) { - var sk = new Skeleton([ - {c: [0,0], width: 20}, - {c: [50,100], width: 10, angle: -90, distr: 0}, - {c: [100,0], width: 20, angle: -180} - ]), - nodes = sk.contours[0].nodes; - - sk.expand({}); - - expect(nodes[0].x).toBe( -10 ); - expect( Math.round(nodes[0].y) ).toBe( 0 ); - - expect(nodes[1].x).toBe( 50 ); - expect(nodes[1].y).toBe( 100 ); - - expect(nodes[2].x).toBe( 110 ); - expect( Math.round(nodes[2].y) ).toBe( 0 ); - - expect(nodes[3].x).toBe( 90 ); - expect( Math.round(nodes[3].y) ).toBe( 0 ); - - expect(nodes[4].x).toBe( 50 ); - expect(nodes[4].y).toBe( 90 ); - - expect(nodes[5].x).toBe( 10 ); - expect( Math.round(nodes[5].y) ).toBe( 0 ); - })); - - /*it('should be able to expand the skeleton made of lines using width/angle/distr params', inject(function(Skeleton) { - var sk = new Skeleton([ - {c: [0,0], width: 20}, - 'line', - {c: [50,100], width: 10}, - 'line', - {c: [100,0], width: 20, angle: -180} - ]), - nodes = sk.contours[0].nodes; - - sk.expand(); - - expect(nodes[0].x).toBe( -10 ); - expect( Math.round(nodes[0].y) ).toBe( 0 ); - - expect(nodes[1].x).toBe( 40 ); - expect(nodes[1].y).toBe( 100 ); - - expect(nodes[2].x).toBe( 60 ); - expect(nodes[2].y).toBe( 100 ); - - expect(nodes[3].x).toBe( 110 ); - expect( Math.round(nodes[3].y) ).toBe( 0 ); - - expect(nodes[4].x).toBe( 90 ); - expect( Math.round(nodes[4].y) ).toBe( 0 ); - - expect(nodes[5].x).toBe( 40 ); - expect(nodes[5].y).toBe( 100 ); - - expect(nodes[6].x).toBe( 60 ); - expect(nodes[6].y).toBe( 100 ); - - expect(nodes[7].x).toBe( 10 ); - expect( Math.round(nodes[7].y) ).toBe( 0 ); - }));*/ - - describe('Update controls with Hobby', function() { - - // there's an equivalent test in coutour.js - it('should update controls when there\'s one line in the shape', inject(function(Skeleton) { - var sk = new Skeleton([ - {c: [0,0], width: 20}, - 'line', - {c: [50,100], width: 10, angle: -90, distr: 0}, - {c: [100,0], width: 20, angle: -180} - ]), - nodes = sk.contours[0].nodes; - - sk.updateContours({}); - - expect(nodes[0].lType).toBe('line'); - expect(nodes[0].rType).toBe('line'); - - expect(nodes[1].lType).toBe('line'); - expect(nodes[1].rType).toBe('open'); - - expect(nodes[2].lType).toBe('open'); - expect(nodes[2].rType).toBe('line'); - - expect(nodes[3].lType).toBe('line'); - expect(nodes[3].rType).toBe('open'); - - expect(nodes[4].lType).toBe('open'); - expect(nodes[4].rType).toBe('line'); - - expect(nodes[5].lType).toBe('line'); - expect(nodes[5].rType).toBe('line'); - - - - expect(nodes[0].rc.x).toBe( -10 ); - expect( Math.round(nodes[0].rc.y) ).toBe( 0 ); - - expect(nodes[1].lc.x).toBe( 50 ); - expect(nodes[1].lc.y).toBe( 100 ); - - // second line - expect(nodes[2].rc.x).toBe( 110 ); - expect( Math.round(nodes[2].rc.y) ).toBe( 0 ); - - expect(nodes[3].lc.x).toBe( 90 ); - expect( Math.round(nodes[3].lc.y) ).toBe( 0 ); - - // third line - expect(nodes[4].rc.x).toBe( 50 ); - expect(nodes[4].rc.y).toBe( 90 ); - - expect(nodes[5].lc.x).toBe( 10 ); - expect( Math.round(nodes[5].lc.y) ).toBe( 0 ); - - // fourth line - expect(nodes[5].rc.x).toBe( 10 ); - expect( Math.round(nodes[5].rc.y) ).toBe( 0 ); - - expect(nodes[0].lc.x).toBe( -10 ); - expect( Math.round(nodes[0].lc.y) ).toBe( 0 ); - })); - }); -}); \ No newline at end of file diff --git a/test/test.webpack.js b/test/test.webpack.js new file mode 100644 index 000000000..e5982c1a9 --- /dev/null +++ b/test/test.webpack.js @@ -0,0 +1,2 @@ +var testsContext = require.context(".", true, /\.test\.js$/); +testsContext.keys().forEach(testsContext); diff --git a/webpack.config.js b/webpack.config.js index 48c933b61..deba656f0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -3,9 +3,11 @@ var webpack = require('webpack'); module.exports = { cache: true, + devtool: 'cheap-module-eval-source-map', entry: [ 'webpack-dev-server/client?http://0.0.0.0:9000', // WebpackDevServer host and port 'webpack/hot/only-dev-server', // "only" prevents reload on syntax errors + 'babel-polyfill', './app/scripts/main' ], output: { @@ -17,20 +19,21 @@ module.exports = { loaders: [ { test: /\.jsx?$/, - preloaders: ['prelude-loader'], - loaders: ['react-hot-loader', 'babel-loader'], + loaders: ['prelude-loader','react-hot-loader', 'babel-loader?cacheDirectory'], include: [ - path.join(__dirname, 'app'), - path.join(__dirname, '/node_modules/nexus-flux'), - path.join(__dirname, '/node_modules/remutable'), - path.join(__dirname, '/node_modules/lifespan') + path.join(__dirname, 'app') ] } ], - noParse:/(levelup)|(prototypo-canvas)/ + noParse:/(dist\/prototypo-canvas)/ }, plugins: [ - new webpack.HotModuleReplacementPlugin() + new webpack.HotModuleReplacementPlugin(), + new webpack.DllReferencePlugin({ + context: __dirname, + manifest: require('./dist/dll/libs-manifest'), + sourceType: 'this', + }), ], resolve: { extensions: ['','.js', '.jsx']