tests: add test for combining parse with inlineStyles

This commit is contained in:
Mikael Sand
2019-10-23 17:43:41 +03:00
parent fdd1698f73
commit b1c0a43e9a
4 changed files with 93 additions and 4 deletions
+82
View File
@@ -1,5 +1,87 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`inlines styles 1`] = `
Object {
"Tag": [Function],
"children": Array [
<Defs>
<missingTag
type="text/css"
>
/* tag selector */
rect {
stroke: blue;
fill: yellow
}
/* class selector */
.redbox { fill: red; }
/* multiple selectors */
g .class-1, g .class-2 {
stroke-width: 16
}
/* two classes */
.class-2.transparent {
fill-opacity: 0.3;
}
/* Commented out
rect {
fill: black;
}
*/
</missingTag>
</Defs>,
<G>
<Rect
class="redbox class-1"
height={200}
style={
Object {
"fill": "red",
"stroke": "blue",
"strokeWidth": "16",
}
}
width={1000}
x={100}
y={0}
/>
</G>,
<G>
<Rect
class="redbox class-2 transparent"
height={200}
style={
Object {
"fill": "red",
"fillOpacity": "0.3",
"stroke": "blue",
"strokeWidth": "16",
}
}
width={750}
x={100}
y={350}
/>
</G>,
],
"parent": null,
"props": Object {
"height": "100%",
"version": 1.1,
"viewBox": "0 0 1000 500",
"width": "100%",
"xmlns": "http://www.w3.org/2000/svg",
},
"tag": "svg",
}
`;
exports[`supports CSS in style element 1`] = `
<RNSVGSvgView
align="xMidYMid"
+8 -3
View File
@@ -1,9 +1,8 @@
import React from 'react';
import renderer from 'react-test-renderer';
import { SvgCss } from '../src/ReactNativeSVG';
import { SvgCss, parse, inlineStyles } from '../src/ReactNativeSVG';
test('supports CSS in style element', () => {
const xml = `<?xml version="1.0" standalone="no"?>
const xml = `<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
@@ -44,6 +43,12 @@ test('supports CSS in style element', () => {
</g>
</svg>`;
test('inlines styles', () => {
const ast = parse(xml, inlineStyles);
expect(ast).toMatchSnapshot();
});
test('supports CSS in style element', () => {
const tree = renderer.create(<SvgCss xml={xml} />).toJSON();
expect(tree).toMatchSnapshot();
});
+2 -1
View File
@@ -38,9 +38,10 @@
"flowgen": "flowgen src/index.d.ts -o src/index.js.flow",
"flowtyped": "flow-typed install",
"format": "prettier README.md './src/**/*.{ts,tsx}' src/index.d.ts --write",
"jest": "jest",
"peg": "pegjs -o src/lib/extract/transform.js ./src/lib/extract/transform.peg",
"tsc": "tsc --noEmit",
"test": "npm run lint && npm run tsc && npm run flow && jest",
"test": "npm run lint && npm run tsc && npm run flow && npm run jest",
"prepare": "npm run flowgen && npm run bob",
"semantic-release": "semantic-release"
},
+1
View File
@@ -28,6 +28,7 @@ import cssSelect, { Adapter, Options, Predicate, Query } from 'css-select';
/*
* Style element inlining experiment based on SVGO
* https://github.com/svg/svgo/blob/11f9c797411a8de966aacc4cb83dbb3e471757bc/plugins/inlineStyles.js
* */
/**