|
| 1 | +var SVGAttributeHook = require('../../../lib/get-property-info/svg/svg-attribute-hook'); |
| 2 | + |
| 3 | + |
| 4 | +describe('SVGAttributeHook', function () { |
| 5 | + var testNamespace = "http://www.testnamespace.com"; |
| 6 | + var testValue = "test-value"; |
| 7 | + var attributeHook = SVGAttributeHook(testNamespace, testValue); |
| 8 | + |
| 9 | + it('creates new AttributeBook with namespace and value', function () { |
| 10 | + attributeHook.namespace.should.equal(testNamespace) |
| 11 | + attributeHook.value.should.equal(testValue) |
| 12 | + }); |
| 13 | + |
| 14 | + describe('hook', function() { |
| 15 | + context('prev is the same AttributeHook', function() { |
| 16 | + it('does nothing', function() { |
| 17 | + var prev = attributeHook; |
| 18 | + var node = {}; |
| 19 | + var prop = {}; |
| 20 | + |
| 21 | + var hooked = attributeHook.hook(node, prop, prev) |
| 22 | + |
| 23 | + should.equal(hooked, undefined) |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + context('prev is different AttributeHook', function() { |
| 28 | + it('sets the attribute to the input node', function() { |
| 29 | + var otherNamespace = "othernamespace"; |
| 30 | + var otherValue = "otherValue"; |
| 31 | + var testProp = "testProp"; |
| 32 | + var prev = SVGAttributeHook(otherNamespace, otherValue); |
| 33 | + var node = { |
| 34 | + setAttributeNS: function(namespace, prop, value) { |
| 35 | + this.namespace = namespace; |
| 36 | + this.value = value; |
| 37 | + this.prop = prop; |
| 38 | + }, |
| 39 | + namespace: null, |
| 40 | + value: null, |
| 41 | + prop: null, |
| 42 | + }; |
| 43 | + |
| 44 | + attributeHook.hook(node, testProp, prev) |
| 45 | + |
| 46 | + node.namespace.should.equal(testNamespace) |
| 47 | + node.value.should.equal(testValue) |
| 48 | + node.prop.should.equal(testProp) |
| 49 | + }); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('unhook', function() { |
| 54 | + context('node is has same namespace as next', function() { |
| 55 | + it('does nothing', function() { |
| 56 | + var next = attributeHook; |
| 57 | + var node = {}; |
| 58 | + var prop = {}; |
| 59 | + |
| 60 | + var hooked = attributeHook.unhook(node, prop, next) |
| 61 | + |
| 62 | + should.equal(hooked, undefined) |
| 63 | + }); |
| 64 | + }); |
| 65 | + |
| 66 | + context('node has different namespace as next', function() { |
| 67 | + it('removes attribute namespace from the node', function() { |
| 68 | + var otherNamespace = "othernamespace"; |
| 69 | + var otherValue = "otherValue"; |
| 70 | + var testProp = "color:red"; |
| 71 | + var next = SVGAttributeHook(otherNamespace, otherValue); |
| 72 | + var node = { |
| 73 | + removeAttributeNS: function(namespace, name) { |
| 74 | + this.namespace = name; |
| 75 | + }, |
| 76 | + namespace: testNamespace |
| 77 | + }; |
| 78 | + |
| 79 | + attributeHook.unhook(node, testProp, next) |
| 80 | + |
| 81 | + node.namespace.should.equal('red') |
| 82 | + }); |
| 83 | + |
| 84 | + it('removes attribute namespace without colon in prop from the node', function() { |
| 85 | + var otherNamespace = "othernamespace"; |
| 86 | + var otherValue = "otherValue"; |
| 87 | + var testProp = "color"; |
| 88 | + var next = SVGAttributeHook(otherNamespace, otherValue); |
| 89 | + var node = { |
| 90 | + removeAttributeNS: function(namespace, name) { |
| 91 | + this.namespace = name; |
| 92 | + }, |
| 93 | + namespace: testNamespace |
| 94 | + }; |
| 95 | + |
| 96 | + attributeHook.unhook(node, testProp, next) |
| 97 | + |
| 98 | + node.namespace.should.equal('color') |
| 99 | + }); |
| 100 | + }); |
| 101 | + }); |
| 102 | +}); |
0 commit comments