diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-04-22 22:16:36 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-04-22 22:16:36 +0200 |
commit | ab1c07e80bd21f2cdf773be238d4dd754db4e80a (patch) | |
tree | b1386635a4e54f29eee8cfa41151fd930610c25e /spec | |
parent | 03d25548fe99c87ed74e789b894e37a7fc6caf34 (diff) | |
download | svg.js-ab1c07e80bd21f2cdf773be238d4dd754db4e80a.tar.gz svg.js-ab1c07e80bd21f2cdf773be238d4dd754db4e80a.zip |
changed `style()` to `css()`
it now accepts array as input and returns object when no argument given (#517)
also removed sub-pixel offset fix
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/element.js | 42 | ||||
-rw-r--r-- | spec/spec/fx.js | 68 |
2 files changed, 56 insertions, 54 deletions
diff --git a/spec/spec/element.js b/spec/spec/element.js index 70642f5..6dbf8ea 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -70,7 +70,7 @@ describe('Element', function() { expect(rect.attr('stroke-linejoin')).toBe('miter') }) it('gets the "style" attribute as a string', function() { - rect.style('cursor', 'pointer') + rect.css('cursor', 'pointer') expect(rect.node.style.cursor).toBe('pointer') }) it('sets the style attribute correctly', function() { @@ -135,36 +135,38 @@ describe('Element', function() { }) }) - describe('style()', function() { + describe('css()', function() { it('sets the style with key and value arguments', function() { - var rect = draw.rect(100,100).style('cursor', 'crosshair') + var rect = draw.rect(100,100).css('cursor', 'crosshair') expect(window.stripped(rect.node.style.cssText)).toBe('cursor:crosshair') }) it('sets multiple styles with an object as the first argument', function() { - var rect = draw.rect(100,100).style({ cursor: 'help', display: 'block' }) + var rect = draw.rect(100,100).css({ cursor: 'help', display: 'block' }) expect(window.stripped(rect.node.style.cssText)).toMatch(/cursor:help/) expect(window.stripped(rect.node.style.cssText)).toMatch(/display:block/) expect(window.stripped(rect.node.style.cssText).length).toBe(('display:block;cursor:help').length) }) - it('gets a style with a string key as the fists argument', function() { - var rect = draw.rect(100,100).style({ cursor: 'progress', display: 'block' }) - expect(rect.style('cursor')).toBe('progress') + it('gets a style with a string key as the first argument', function() { + var rect = draw.rect(100,100).css({ cursor: 'progress', display: 'block' }) + expect(rect.css('cursor')).toBe('progress') }) - it('gets the full css string with no argument', function() { - var rect = draw.rect(100,100).style({ cursor: 's-resize', display: 'none' }) - expect(window.stripped(rect.style())).toMatch(/display:none/) - expect(window.stripped(rect.style())).toMatch(/cursor:s-resize/) - expect(window.stripped(rect.style()).length).toBe(('cursor:s-resize;display:none').length) + it('gets multiple sytyles with array as first argument', function() { + var rect = draw.rect(100,100).css({ cursor: 'progress', display: 'block' }) + expect(rect.css(['cursor', 'display'])).toEqual({ cursor: 'progress', display: 'block' }) + }) + it('gets an object with all styles with zero arguments', function() { + var rect = draw.rect(100,100).css({ cursor: 's-resize', display: 'none' }) + expect(rect.css()).toEqual({ cursor: 's-resize', display: 'none' }) }) it('removes a style if the value is an empty string', function() { - var rect = draw.rect(100,100).style({ cursor: 'n-resize', display: '' }) - expect(window.stripped(rect.style())).toBe('cursor:n-resize') + var rect = draw.rect(100,100).css({ cursor: 'n-resize', display: '' }) + expect(rect.css('display')).toBe('') }) it('removes a style if the value explicitly set to null', function() { - var rect = draw.rect(100,100).style('cursor', 'w-resize') - expect(window.stripped(rect.style())).toBe('cursor:w-resize') - rect.style('cursor', null) - expect(rect.style()).toBe('') + var rect = draw.rect(100,100).css('cursor', 'w-resize') + expect(rect.css()).toEqual({ cursor:'w-resize' }) + rect.css('cursor', null) + expect(rect.css('cursor')).toBe('') }) }) @@ -933,13 +935,13 @@ describe('Element', function() { describe('show()', function() { it('sets display property to ""', function() { var rect = draw.rect(100,100).show() - expect(rect.style('display')).toBe('') + expect(rect.css('display')).toBe('') }) }) describe('hide()', function() { it('sets display property to none', function() { var rect = draw.rect(100,100).hide() - expect(rect.style('display')).toBe('none') + expect(rect.css('display')).toBe('none') }) }) describe('visible()', function() { diff --git a/spec/spec/fx.js b/spec/spec/fx.js index 78101d4..e7aad57 100644 --- a/spec/spec/fx.js +++ b/spec/spec/fx.js @@ -2261,38 +2261,38 @@ describe('FX', function() { , endValue = 5 , morph = new SVG.Number(startValue).morph(endValue) - rect.style('stroke-width', startValue) - fx.style('stroke-width', endValue) + rect.css('stroke-width', startValue) + fx.css('stroke-width', endValue) fx.start() - expect(rect.style('stroke-width')).toBe(morph.at(0).toString()) + expect(rect.css('stroke-width')).toBe(morph.at(0).toString()) jasmine.clock().tick(250) // Have the animation be half way fx.step() - expect(rect.style('stroke-width')).toBe(morph.at(0.5).toString()) + expect(rect.css('stroke-width')).toBe(morph.at(0.5).toString()) jasmine.clock().tick(250) // Have the animation reach its end fx.step() - expect(rect.style('stroke-width')).toBe(morph.at(1).toString()) + expect(rect.css('stroke-width')).toBe(morph.at(1).toString()) }) it('should be possible to animate non-numeric styles', function () { var startValue = 'butt' , endValue = 'round' - , line = draw.line('0,0 100,150').style('stroke-linecap', startValue) + , line = draw.line('0,0 100,150').css('stroke-linecap', startValue) - fx = line.animate(3000).style('stroke-linecap', endValue) + fx = line.animate(3000).css('stroke-linecap', endValue) fx.start() - expect(line.style('stroke-linecap')).toBe(startValue) + expect(line.css('stroke-linecap')).toBe(startValue) jasmine.clock().tick(1500) // Have the animation be half way fx.step() - expect(line.style('stroke-linecap')).toBe(startValue) + expect(line.css('stroke-linecap')).toBe(startValue) jasmine.clock().tick(1500) // Have the animation reach its end fx.step() - expect(line.style('stroke-linecap')).toBe(endValue) + expect(line.css('stroke-linecap')).toBe(endValue) }) it('should be possible to animate color styles by using SVG.Color', function() { @@ -2300,8 +2300,8 @@ describe('FX', function() { , endValue = '#B1835D' , morph = new SVG.Color(startValue).morph(endValue) - rect.style('fill', startValue) - fx.style('fill', endValue) + rect.css('fill', startValue) + fx.css('fill', endValue) fx.start() @@ -2309,15 +2309,15 @@ describe('FX', function() { // The style rgb string has spaces while the one returned by SVG.Color do not as show bellow // CSS: rgb(255, 255, 255) SVG.Color: rgb(255,255,255) // The space in the style rbg string are removed so they can be equal - expect(rect.style('fill').replace(/\s+/g, '')).toBe(morph.at(0).toRgb()) + expect(rect.css('fill').replace(/\s+/g, '')).toBe(morph.at(0).toRgb()) jasmine.clock().tick(250) // Have the animation be half way fx.step() - expect(rect.style('fill').replace(/ /g, '')).toBe(morph.at(0.5).toRgb()) + expect(rect.css('fill').replace(/ /g, '')).toBe(morph.at(0.5).toRgb()) jasmine.clock().tick(250) // Have the animation reach its end fx.step() - expect(rect.style('fill').replace(/ /g, '')).toBe(morph.at(1).toRgb()) + expect(rect.css('fill').replace(/ /g, '')).toBe(morph.at(1).toRgb()) }) it('should be possible to pass percentage strings to numeric styles', function () { @@ -2325,44 +2325,44 @@ describe('FX', function() { , endValue = '5%' , morph = new SVG.Number(startValue).morph(endValue) - rect.style('stroke-width', startValue) - fx.style('stroke-width', endValue) + rect.css('stroke-width', startValue) + fx.css('stroke-width', endValue) fx.start() - expect(rect.style('stroke-width')).toBe(morph.at(0).toString()) + expect(rect.css('stroke-width')).toBe(morph.at(0).toString()) jasmine.clock().tick(250) // Have the animation be half way fx.step() - expect(rect.style('stroke-width')).toBe(morph.at(0.5).toString()) + expect(rect.css('stroke-width')).toBe(morph.at(0.5).toString()) jasmine.clock().tick(250) // Have the animation reach its end fx.step() - expect(rect.style('stroke-width')).toBe(morph.at(1).toString()) + expect(rect.css('stroke-width')).toBe(morph.at(1).toString()) }) it('should allow 0 to be specified without a unit', function () { var r1 = draw.rect(100,100).move(200,200) , r2 = draw.rect(100,100).move(400,400) - r1.style('stroke-width', '100%').animate(500).style('stroke-width', 0) - r2.style('stroke-width', 0).animate(500).style('stroke-width', '100%') + r1.css('stroke-width', '100%').animate(500).css('stroke-width', 0) + r2.css('stroke-width', 0).animate(500).css('stroke-width', '100%') r1.fx.start() r2.fx.start() - expect(r1.style('stroke-width')).toBe('100%') - expect(r2.style('stroke-width')).toBe('0%') + expect(r1.css('stroke-width')).toBe('100%') + expect(r2.css('stroke-width')).toBe('0%') jasmine.clock().tick(250) // Have the animation be half way r1.fx.step() r2.fx.step() - expect(r1.style('stroke-width')).toBe('50%') - expect(r2.style('stroke-width')).toBe('50%') + expect(r1.css('stroke-width')).toBe('50%') + expect(r2.css('stroke-width')).toBe('50%') jasmine.clock().tick(250) // Have the animation reach its end r1.fx.step() r2.fx.step() - expect(r1.style('stroke-width')).toBe('0%') - expect(r2.style('stroke-width')).toBe('100%') + expect(r1.css('stroke-width')).toBe('0%') + expect(r2.css('stroke-width')).toBe('100%') }) }) @@ -2402,21 +2402,21 @@ describe('FX', function() { }) }) - describe('style()', function() { + describe('css()', function() { it('should allow an object to be passed', function() { - spyOn(fx, 'style').and.callThrough() - fx.style({ + spyOn(fx, 'css').and.callThrough() + fx.css({ x: 20, y: 20 }) - expect(fx.style).toHaveBeenCalledWith('x', 20) - expect(fx.style).toHaveBeenCalledWith('y', 20) + expect(fx.css).toHaveBeenCalledWith('x', 20) + expect(fx.css).toHaveBeenCalledWith('y', 20) }) it('should call add() with styles as method', function() { spyOn(fx, 'add') - fx.style('x', 20) + fx.css('x', 20) expect(fx.add).toHaveBeenCalledWith('x', 20, 'styles') }) }) |