diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-08 12:38:07 +1000 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2020-04-08 12:38:07 +1000 |
commit | 36b65881bd090e105d19952d10b3681313daf2af (patch) | |
tree | d9da811fae1a082c029edef560ef27e722a22f37 /spec | |
parent | 9a67cc3bbaf2e3f83368dc9706a06ec245a22c6a (diff) | |
download | svg.js-36b65881bd090e105d19952d10b3681313daf2af.tar.gz svg.js-36b65881bd090e105d19952d10b3681313daf2af.zip |
added tests for ClipPath
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/elements/ClipPath.js | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/spec/spec/elements/ClipPath.js b/spec/spec/elements/ClipPath.js new file mode 100644 index 0000000..6ed6bfe --- /dev/null +++ b/spec/spec/elements/ClipPath.js @@ -0,0 +1,94 @@ +/* globals describe, expect, it, spyOn, jasmine, container */ + +import { ClipPath, SVG, Container, Rect } from '../../../src/main.js' + +const { any } = jasmine + +describe('ClipPath.js', () => { + describe('()', () => { + it('creates a new object of type ClipPath', () => { + expect(new ClipPath()).toEqual(any(ClipPath)) + }) + + it('sets passed attributes on the element', () => { + expect(new ClipPath({ id: 'foo' }).id()).toBe('foo') + }) + }) + + describe('remove()', () => { + it('unclips all targets', () => { + const canvas = SVG().addTo(container) + const clip = canvas.clip() + const rect = canvas.rect(100, 100).clipWith(clip) + expect(clip.remove()).toBe(clip) + expect(rect.clipper()).toBe(null) + }) + + it('calls remove on parent class', () => { + const clip = new ClipPath() + const spy = spyOn(Container.prototype, 'remove') + clip.remove() + expect(spy).toHaveBeenCalled() + }) + }) + + describe('target()', () => { + it('gets all targets of this clipPath', () => { + const canvas = SVG().addTo(container) + const clip = canvas.clip() + const rect = canvas.rect(100, 100).clipWith(clip) + expect(clip.targets()).toEqual([ rect ]) + }) + }) + + describe('Container', () => { + describe('circle()', () => { + it('creates a clipPath in the defs', () => { + const canvas = SVG() + const clip = canvas.clip() + expect(clip).toEqual(any(ClipPath)) + expect(canvas.defs().children()).toEqual([ clip ]) + }) + }) + }) + + describe('Element', () => { + describe('clipper()', () => { + it('returns the instance of ClipPath the current element is clipped with', () => { + const canvas = SVG().addTo(container) + const clip = canvas.clip() + const rect = canvas.rect(100, 100).clipWith(clip) + expect(rect.clipper()).toEqual(clip) + }) + + it('returns null if no clipPath was found', () => { + expect(new Rect().clipper()).toBe(null) + }) + }) + + describe('clipWith()', () => { + it('sets the clip-path attribute on the element to the id of the clipPath', () => { + const clip = new ClipPath().id('foo') + const rect = new Rect().clipWith(clip) + expect(rect.attr('clip-path')).toBe('url("#foo")') + }) + + it('creates a clipPath and appends the passed element to it to clip current element', () => { + const canvas = SVG().addTo(container) + const circle = canvas.circle(40) + const rect = canvas.rect(100, 100).clipWith(circle) + expect(circle.parent()).toEqual(any(ClipPath)) + expect(rect.attr('clip-path')).toBe(`url("#${circle.parent().id()}")`) + }) + }) + + describe('unclip()', () => { + it('sets the clip-target attribute to null and returns itself', () => { + const clip = new ClipPath().id('foo') + const rect = new Rect().clipWith(clip) + expect(rect.unclip()).toBe(rect) + expect(rect.attr('clip-path')).toBe(undefined) + }) + }) + }) +}) |