summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-26 09:54:06 +1000
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-26 09:54:06 +1000
commit77c20c30bde7941f1489ce47d8aea439ec1b8e5f (patch)
treed39ff1f3b875d4a49308898ba2aba6fba0a24ab7 /spec
parent4f6e1fb5e66960040836fa38720933ee553c1d0f (diff)
downloadsvg.js-77c20c30bde7941f1489ce47d8aea439ec1b8e5f.tar.gz
svg.js-77c20c30bde7941f1489ce47d8aea439ec1b8e5f.zip
added tests for css.js
Diffstat (limited to 'spec')
-rw-r--r--spec/spec/modules/optional/css.js107
1 files changed, 107 insertions, 0 deletions
diff --git a/spec/spec/modules/optional/css.js b/spec/spec/modules/optional/css.js
new file mode 100644
index 0000000..a0a3e6d
--- /dev/null
+++ b/spec/spec/modules/optional/css.js
@@ -0,0 +1,107 @@
+/* globals describe, expect, it */
+
+import { Rect } from '../../../../src/main.js'
+
+describe('css.js', () => {
+ describe('Dom', () => {
+ describe('css()', () => {
+ describe('as getter', () => {
+ it('returns all css as object', () => {
+ const rect = new Rect({ style: 'fill: none; outline: 1px solid black; stroke: none' })
+ expect(rect.css()).toEqual({
+ fill: 'none',
+ outline: '1px solid black',
+ stroke: 'none'
+ })
+ })
+
+ it('returns an object with selected css properries', () => {
+ const rect = new Rect({ style: 'fill: none; outline: 1px solid black; stroke: none' })
+ expect(rect.css([ 'fill', 'stroke' ])).toEqual({
+ fill: 'none',
+ stroke: 'none'
+ })
+ })
+
+ it('returns a single property with property name given', () => {
+ const rect = new Rect({ style: 'fill: none; outline: 1px solid black; stroke: none' })
+ expect(rect.css('fill')).toBe('none')
+ })
+
+ it('returns undefined if css property is not set', () => {
+ const rect = new Rect({ style: 'fill: none; outline: 1px solid black; stroke: none' })
+ expect(rect.css('something')).toBe('')
+ })
+ })
+
+ describe('as setter', () => {
+ it('returns itself', () => {
+ const rect = new Rect({ style: 'fill: none; outline: 1px solid black; stroke: none' })
+ expect(rect.css('fill', 'black')).toBe(rect)
+ })
+
+ it('adds a css property', () => {
+ const rect = new Rect({ style: 'fill: none; outline: 1px solid black; stroke: none' })
+ expect(rect.css('stroke-width', 2).css('stroke-width')).toBe('2')
+ })
+
+ it('changes a css property', () => {
+ const rect = new Rect({ style: 'fill: none; outline: 1px solid black; stroke: none' })
+ expect(rect.css('fill', 'black').css('fill')).toBe('black')
+ })
+
+ it('sets an object of properties', () => {
+ const rect = new Rect()
+ expect(rect.css({ fill: 'none', stroke: 'none' }).css()).toEqual({ fill: 'none', stroke: 'none' })
+ })
+
+ it('removes property if empty string is passed as value', () => {
+ const rect = new Rect({ style: 'fill: none; outline: 1px solid black; stroke: none' })
+ expect(rect.css('fill', '').css('fill')).toBe('')
+ })
+
+ it('removes property if null is passed as value', () => {
+ const rect = new Rect({ style: 'fill: none; outline: 1px solid black; stroke: none' })
+ expect(rect.css('fill', null).css('fill')).toBe('')
+ })
+ })
+ })
+
+ describe('show()', () => {
+ it('returns itself', () => {
+ const rect = new Rect()
+ expect(rect.show()).toBe(rect)
+ })
+
+ it('removes the display property', () => {
+ const rect = new Rect().hide()
+ expect(rect.show().css('display')).toBe('')
+ })
+ })
+
+ describe('hide()', () => {
+ it('returns itself', () => {
+ const rect = new Rect()
+ expect(rect.hide()).toBe(rect)
+ })
+
+ it('sets the css display property to none', () => {
+ const rect = new Rect()
+ expect(rect.hide().css('display')).toBe('none')
+ })
+ })
+
+ describe('visible()', () => {
+ it('returns true if display is not none', () => {
+ const rect = new Rect()
+ expect(rect.show().visible()).toBe(true)
+ expect(rect.css('display', 'block').visible()).toBe(true)
+ })
+
+ it('returns false if display is none', () => {
+ const rect = new Rect()
+ expect(rect.hide().visible()).toBe(false)
+ })
+ })
+ })
+})