From b8f4400075126d9da64c5403333baa3c52048507 Mon Sep 17 00:00:00 2001 From: wout Date: Sat, 29 Jun 2013 09:56:37 +0100 Subject: Fixed naming conflict in mask and clip modules, bumped to v0.22 --- spec/index.html | 2 ++ spec/spec/clip.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ spec/spec/mask.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 spec/spec/clip.js create mode 100644 spec/spec/mask.js (limited to 'spec') diff --git a/spec/index.html b/spec/index.html index 524bff7..d619acd 100644 --- a/spec/index.html +++ b/spec/index.html @@ -44,6 +44,8 @@ + + diff --git a/spec/spec/clip.js b/spec/spec/clip.js new file mode 100644 index 0000000..ac3a147 --- /dev/null +++ b/spec/spec/clip.js @@ -0,0 +1,57 @@ +describe('ClipPath', function() { + var rect, circle + + beforeEach(function() { + rect = draw.rect(100,100) + circle = draw.circle(100).move(50, 50) + rect.clipWith(circle) + }) + + afterEach(function() { + draw.clear() + }) + + it('moves the masking element to a new clip node', function() { + expect(circle.parent instanceof SVG.Clip).toBe(true) + }) + + it('creates the clip node in the defs node', function() { + expect(circle.parent.parent).toBe(draw.defs()) + }) + + it('sets the "clip-path" attribute on the cliped element with the clip id', function() { + expect(rect.attr('clip-path')).toBe('url(#' + circle.parent.attr('id') + ')') + }) + + it('references the clip element in the masked element', function() { + expect(rect.clipper).toBe(circle.parent) + }) + + it('references the clipped element in the clipPath target list', function() { + expect(rect.clipper.targets.indexOf(rect) > -1).toBe(true) + }) + + it('unclips all clipped elements when being removed', function() { + rect.clipper.remove() + expect(rect.attr('clip-path')).toBe(undefined) + }) + + describe('unclip()', function() { + + it('clears the "clip-path" attribute on the clipped element', function() { + rect.unclip() + expect(rect.attr('clip-path')).toBe(undefined) + }) + + it('removes the reference to the clipping element', function() { + rect.unclip() + expect(rect.clipper).toBe(undefined) + }) + + it('returns the clipPath element', function() { + expect(rect.unclip()).toBe(rect) + }) + + }) + +}) \ No newline at end of file diff --git a/spec/spec/mask.js b/spec/spec/mask.js new file mode 100644 index 0000000..b8d8a10 --- /dev/null +++ b/spec/spec/mask.js @@ -0,0 +1,57 @@ +describe('Mask', function() { + var rect, circle + + beforeEach(function() { + rect = draw.rect(100,100) + circle = draw.circle(100).move(50, 50).fill('#fff') + rect.maskWith(circle) + }) + + afterEach(function() { + draw.clear() + }) + + it('moves the masking element to a new mask node', function() { + expect(circle.parent instanceof SVG.Mask).toBe(true) + }) + + it('creates the mask node in the defs node', function() { + expect(circle.parent.parent).toBe(draw.defs()) + }) + + it('sets the "mask" attribute on the masked element with the mask id', function() { + expect(rect.attr('mask')).toBe('url(#' + circle.parent.attr('id') + ')') + }) + + it('references the mask element in the masked element', function() { + expect(rect.masker).toBe(circle.parent) + }) + + it('references the masked element in the mask target list', function() { + expect(rect.masker.targets.indexOf(rect) > -1).toBe(true) + }) + + it('unmasks all masked elements when being removed', function() { + rect.masker.remove() + expect(rect.attr('mask')).toBe(undefined) + }) + + describe('unmask()', function() { + + it('clears the "mask" attribute on the masked element', function() { + rect.unmask() + expect(rect.attr('mask')).toBe(undefined) + }) + + it('removes the reference to the masking element', function() { + rect.unmask() + expect(rect.masker).toBe(undefined) + }) + + it('returns the element itslef', function() { + expect(rect.unmask()).toBe(rect) + }) + + }) + +}) \ No newline at end of file -- cgit v1.2.3