diff options
author | Patrick Klingemann <patrick.klingemann@gmail.com> | 2014-06-02 19:21:58 -0500 |
---|---|---|
committer | Patrick Klingemann <patrick.klingemann@gmail.com> | 2014-06-02 19:21:58 -0500 |
commit | 5fd4a57bfd339f01221d2b51abb03465012e7828 (patch) | |
tree | 1ff64b6245565579be227c93df7a12d5ba064065 /spec | |
parent | 8e44d115af4907276cb23567dc2d2a10d0efdf2f (diff) | |
download | svg.js-5fd4a57bfd339f01221d2b51abb03465012e7828.tar.gz svg.js-5fd4a57bfd339f01221d2b51abb03465012e7828.zip |
add classes, hasClass, addClass, removeClass, toggleClass functions to Element
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/spec/element.js | 76 |
1 files changed, 74 insertions, 2 deletions
diff --git a/spec/spec/element.js b/spec/spec/element.js index 919df93..ae443f7 100755 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -315,9 +315,81 @@ describe('Element', function() { expect(element).toBe(circle) }) }) - -}) + describe('classes()', function() { + it('returns an array of classes on the node', function() { + var element = draw.rect(100,100) + element.node.setAttribute('class', 'one two') + expect(element.classes()).toEqual(['one', 'two']) + }) + }) + + describe('hasClass()', function() { + it('returns true if the node has the class', function() { + var element = draw.rect(100,100) + element.node.setAttribute('class', 'one') + expect(element.hasClass('one')).toBeTruthy() + }) + + it('returns false if the node does not have the class', function() { + var element = draw.rect(100,100) + element.node.setAttribute('class', 'one') + expect(element.hasClass('two')).toBeFalsy() + }) + }) + + describe('addClass()', function() { + it('adds the class to the node', function() { + var element = draw.rect(100,100) + element.addClass('one') + expect(element.hasClass('one')).toBeTruthy() + }) + + it('does not add duplicate classes', function() { + var element = draw.rect(100,100) + element.addClass('one') + element.addClass('one') + expect(element.node.getAttribute('class')).toEqual('one') + }) + + it('returns the svg instance', function() { + var element = draw.rect(100,100) + expect(element.addClass('one')).toEqual(element) + }) + }) + describe('removeClass()', function() { + it('removes the class from the node when the class exists', function() { + var element = draw.rect(100,100) + element.addClass('one') + element.removeClass('one') + expect(element.hasClass('one')).toBeFalsy() + }) + it('does nothing when the class does not exist', function() { + var element = draw.rect(100,100) + element.removeClass('one') + expect(element.hasClass('one')).toBeFalsy() + }) + it('returns the element', function() { + var element = draw.rect(100,100) + expect(element.removeClass('one')).toEqual(element) + }) + }) + + describe('toggleClass()', function() { + it('adds the class when it does not already exist', function(){ + var element = draw.rect(100,100) + element.toggleClass('one') + expect(element.hasClass('one')).toBeTruthy() + }) + + it('removes the class when it already exists', function(){ + var element = draw.rect(100,100) + element.addClass('one') + element.toggleClass('one') + expect(element.hasClass('one')).toBeFalsy() + }) + }) +}) |