From cf159c28a580e6a874d87def2eee52c4a935dbb9 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Fri, 26 Dec 2014 10:57:46 -0500 Subject: [PATCH] Finishing tests for MatchFragment nodes --- spec/parser/javascript/match_fragment_spec.js | 98 ++++++++++++++++++- src/js/parser/javascript/match_fragment.js | 3 +- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/spec/parser/javascript/match_fragment_spec.js b/spec/parser/javascript/match_fragment_spec.js index 5412eca..272d0c5 100644 --- a/spec/parser/javascript/match_fragment_spec.js +++ b/spec/parser/javascript/match_fragment_spec.js @@ -57,9 +57,74 @@ describe('parser/javascript/match_fragment.js', function() { beforeEach(function() { this.node = new javascript.Parser('a').__consume__match_fragment(); + + this.node.container = jasmine.createSpyObj('container', [ + 'addClass', + 'group', + 'prepend', + 'path' + ]); + this.node.container.group.and.returnValue('example group'); + + this.renderDeferred = Q.defer(); + this.node.content = jasmine.createSpyObj('content', [ + 'render', + 'transform', + 'getBBox' + ]); + this.node.content.getBBox.and.returnValue('content bbox'); + this.node.content.render.and.returnValue(this.renderDeferred.promise); + + this.node.repeat = { + contentPosition: 'example position' + }; + + spyOn(this.node, 'skipPath').and.returnValue('skip path'); + spyOn(this.node, 'loopPath').and.returnValue('loop path'); + spyOn(this.node, 'loopLabel'); }); - pending(); + it('renders the content', function() { + this.node._render(); + expect(this.node.content.render).toHaveBeenCalledWith('example group'); + }); + + describe('positioning of content', function() { + + beforeEach(function() { + this.renderDeferred.resolve(); + }); + + it('moves the content to the correct position', function(done) { + this.node._render() + .then(() => { + expect(this.node.content.transform).toHaveBeenCalledWith('example position'); + }) + .finally(done) + .done(); + }); + + it('renders a skip path and loop path', function(done) { + this.node._render() + .then(() => { + expect(this.node.skipPath).toHaveBeenCalledWith('content bbox'); + expect(this.node.loopPath).toHaveBeenCalledWith('content bbox'); + expect(this.node.container.path).toHaveBeenCalledWith('skip pathloop path'); + }) + .finally(done) + .done(); + }); + + it('renders a loop label', function(done) { + this.node._render() + .then(() => { + expect(this.node.loopLabel).toHaveBeenCalled(); + }) + .finally(done) + .done(); + }); + + }); }); @@ -67,9 +132,38 @@ describe('parser/javascript/match_fragment.js', function() { beforeEach(function() { this.node = new javascript.Parser('a').__consume__match_fragment(); + + this.node.repeat = {}; + + this.box = { + y: 11, + ay: 22, + width: 33 + }; + }); + + it('returns nothing when there is no skip', function() { + this.node.repeat.hasSkip = false; + expect(this.node.skipPath(this.box)).toEqual([]); + }); + + it('returns a path when there is a skip', function() { + this.node.repeat.hasSkip = true; + this.node.repeat.greedy = true; + expect(this.node.skipPath(this.box)).toEqual([ + 'M0,22q10,0 10,-10v-1q0,-10 10,-10h23q10,0 10,10v1q0,10 10,10' + ]); + }); + + it('returns a path with arrow when there is a non-greedy skip', function() { + this.node.repeat.hasSkip = true; + this.node.repeat.greedy = false; + expect(this.node.skipPath(this.box)).toEqual([ + 'M0,22q10,0 10,-10v-1q0,-10 10,-10h23q10,0 10,10v1q0,10 10,10', + 'M10,7l5,5m-5,-5l-5,5' + ]); }); - pending(); }); diff --git a/src/js/parser/javascript/match_fragment.js b/src/js/parser/javascript/match_fragment.js index e58059e..d37d17d 100644 --- a/src/js/parser/javascript/match_fragment.js +++ b/src/js/parser/javascript/match_fragment.js @@ -34,8 +34,7 @@ export default { this.container.prepend( this.container.path(paths.join(''))); - }) - .then(() => { + this.loopLabel(); }); },