forked from vault-development/react-native-svg-uri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
58 lines (48 loc) · 2.17 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import {expect} from 'chai';
import {transformStyle, camelCase, removePixelsFromNodeValue, getEnabledAttributes} from '../utils';
describe('transformStyle', () => {
it('transforms style attribute', () => {
expect(
transformStyle({nodeName: 'style', nodeValue: 'fill:rgb(0,0,255);stroke:rgb(0,0,0)'})
).to.deep.equal({
fill: 'rgb(0,0,255)',
stroke: 'rgb(0,0,0)',
});
});
it('transforms style attribute with dash-case attribute', () => {
expect(
transformStyle({nodeName: 'style', nodeValue: 'stop-color:#ffffff'})
).to.deep.equal({
stopColor: '#ffffff',
});
});
});
describe('removePixelsFromNodeValue', () => {
it('removes pixels from x, y, height and width attributes', () => {
expect(removePixelsFromNodeValue({nodeName: 'x', nodeValue: '2px'})).to.deep.equal({nodeName: 'x', nodeValue: '2'});
expect(removePixelsFromNodeValue({nodeName: 'y', nodeValue: '4px'})).to.deep.equal({nodeName: 'y', nodeValue: '4'});
expect(removePixelsFromNodeValue({nodeName: 'height', nodeValue: '65px'})).to.deep.equal({nodeName: 'height', nodeValue: '65'});
expect(removePixelsFromNodeValue({nodeName: 'width', nodeValue: '999px'})).to.deep.equal({nodeName: 'width', nodeValue: '999'});
});
})
describe('camelCase', () => {
it('transforms two word attribute with dash', () => {
expect(camelCase('stop-color')).to.deep.equal('stopColor');
});
it('does not do anything to string that is already camel cased', () => {
expect(camelCase('stopColor')).to.deep.equal('stopColor');
});
});
describe('getEnabledAttributes', () => {
it('return true when nodeName is found', () => {
const enabledAttributes = ['x', 'y', 'strokeOpacity'];
const hasEnabledAttribute = getEnabledAttributes(enabledAttributes);
expect(hasEnabledAttribute({nodeName: 'x'})).to.deep.equal(true);
expect(hasEnabledAttribute({nodeName: 'stroke-opacity'})).to.deep.equal(true);
});
it('return false when nodeName is not found', () => {
const enabledAttributes = ['width', 'height'];
const hasEnabledAttribute = getEnabledAttributes(enabledAttributes);
expect(hasEnabledAttribute({nodeName: 'depth'})).to.deep.equal(false);
});
});