Skip to content

Commit

Permalink
Test updates/clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mstahv committed Dec 29, 2022
1 parent 997b5d0 commit 95e3619
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions flow-server/src/test/java/com/vaadin/flow/component/SvgTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,12 @@ public void attachedToElement() {
new Svg("<svg></svg>").getParent();
}

@Test(expected = IllegalArgumentException.class)
public void nullSvg() {
new Svg((String) null);
}

@Test(expected = IllegalArgumentException.class)
public void nullStream() {
new Svg((InputStream) null);
}

@Test(expected = IllegalArgumentException.class)
public void emptySvg() {
new Svg("");
}

@Test(expected = IllegalArgumentException.class)
public void text() {
new Svg("hello");
Expand All @@ -53,15 +44,13 @@ public void text() {
static String TRIVIAL_SVG = """
<svg>
<circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>
""";
</svg>""";

static String TRIVIAL_SVG2 = """
<svg height="140" width="500">
<ellipse cx="200" cy="80" rx="100" ry="50"
style="fill:yellow;stroke:purple;stroke-width:2" />
</svg>
""";
</svg>""";

static String SVG_WITH_DOCTYPE_ET_AL = """
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
Expand All @@ -74,38 +63,40 @@ public void text() {
<polyline points="50,150 50,200 200,200 200,100" stroke="red" stroke-width="4" fill="none" />
<line x1="50" y1="50" x2="200" y2="200" stroke="blue" stroke-width="4" />
</g>
</svg>
""";
</svg>""";

@Test
public void simpleSvg() {
Svg html = new Svg(TRIVIAL_SVG);
Svg svg = new Svg(TRIVIAL_SVG);
Assert.assertEquals(TRIVIAL_SVG,
html.getElement().getProperty("innerHTML"));
getSvgDocumentBody(svg));
}

@Test
public void withDocType() {
Svg html = new Svg(SVG_WITH_DOCTYPE_ET_AL);
Assert.assertTrue(
html.getElement().getProperty("innerHTML").startsWith("<svg"));
Svg svg = new Svg(SVG_WITH_DOCTYPE_ET_AL);
Assert.assertTrue(getSvgDocumentBody(svg).startsWith("<svg"));
}

@Test
public void setHtmlContent() {
Svg html = new Svg(TRIVIAL_SVG);
public void resetSvg() {
Svg svg = new Svg(TRIVIAL_SVG);
Assert.assertEquals(TRIVIAL_SVG,
html.getElement().getProperty("innerHTML"));
html.setSvg(TRIVIAL_SVG2);
getSvgDocumentBody(svg));
svg.setSvg(TRIVIAL_SVG2);
Assert.assertEquals(TRIVIAL_SVG2,
html.getElement().getProperty("innerHTML"));
getSvgDocumentBody(svg));
}

@Test
public void fromStream() {
Svg svg = new Svg(new ByteArrayInputStream(TRIVIAL_SVG.getBytes()));
Assert.assertEquals(TRIVIAL_SVG,
svg.getElement().getProperty("innerHTML"));
getSvgDocumentBody(svg));
}

private static String getSvgDocumentBody(Svg svg) {
return svg.getElement().getProperty("innerHTML");
}

}

0 comments on commit 95e3619

Please sign in to comment.