1 | import React from 'react';
|
2 | import renderer from 'react-test-renderer';
|
3 | import { SvgCss, parse, inlineStyles } from '../src/ReactNativeSVG';
|
4 |
|
5 | const xml = `<?xml version="1.0" standalone="no"?>
|
6 | <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
7 | "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
8 | <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
|
9 | width="100%" height="100%" viewBox="0 0 1000 500">
|
10 | <defs>
|
11 | <style type="text/css">
|
12 | /* tag selector */
|
13 | rect {
|
14 | stroke: blue;
|
15 | fill: yellow
|
16 | }
|
17 |
|
18 | /* class selector */
|
19 | .redbox { fill: red; }
|
20 |
|
21 | /* multiple selectors */
|
22 | g .class-1, g .class-2 {
|
23 | stroke-width: 16
|
24 | }
|
25 |
|
26 | /* two classes */
|
27 | .class-2.transparent {
|
28 | fill-opacity: 0.3;
|
29 | }
|
30 |
|
31 | /* Commented out
|
32 | rect {
|
33 | fill: black;
|
34 | }
|
35 | */
|
36 | </style>
|
37 | </defs>
|
38 | <g>
|
39 | <rect class="redbox class-1" x="100" y="0" width="1000" height="200" />
|
40 | </g>
|
41 | <g>
|
42 | <rect class="redbox class-2 transparent" x="100" y="350" width="750" height="200" />
|
43 | </g>
|
44 | </svg>`;
|
45 |
|
46 | test('inlines styles', () => {
|
47 | const ast = parse(xml, inlineStyles);
|
48 | expect(ast).toMatchSnapshot();
|
49 | });
|
50 |
|
51 | test('supports CSS in style element', () => {
|
52 | const tree = renderer.create(<SvgCss xml={xml} />).toJSON();
|
53 | expect(tree).toMatchSnapshot();
|
54 | });
|