Skip to content

Commit

Permalink
test: added tests for resolve css variables
Browse files Browse the repository at this point in the history
  • Loading branch information
paviad committed Dec 15, 2024
1 parent 939a9bf commit 92871f7
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions itext.tests/itext.svg.tests/itext/svg/css/SvgStyleResolverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,54 @@ public virtual void OverrideDefaultStyleTest() {
NUnit.Framework.Assert.AreEqual("white", resolvedStyles.Get(SvgConstants.Attributes.STROKE));
}

[NUnit.Framework.TestCase("a", "30px", "30px")]
[NUnit.Framework.TestCase("b", "50px", "30px")]
[NUnit.Framework.TestCase("c d", "35px", "35px")]
public virtual void ResolveCssVariablesTest(string divClass, string expectedMargin, string expectedVarValue) {
iText.StyledXmlParser.Jsoup.Nodes.Element styleTag = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("style"), "");
TextNode styleContents = new TextNode(@"
div {
--test-var: 30px;
}
div.a {
margin: var(--test-var,40px);
}
div.b {
margin: var(--other-var,50px);
}
div.c {
--test-var: 35px;
}
div.c.d {
margin: var(--test-var,40px);
}
");
JsoupElementNode jSoupStyle = new JsoupElementNode(styleTag);
jSoupStyle.AddChild(new JsoupTextNode(styleContents));
SvgProcessorContext context = new SvgProcessorContext(new SvgConverterProperties());

SvgStyleResolver resolver = new SvgStyleResolver(jSoupStyle, context);
AbstractCssContext svgContext = new SvgCssContext();

iText.StyledXmlParser.Jsoup.Nodes.Element div = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag
.ValueOf("div"), "");
JsoupElementNode jSoupEllipse = new JsoupElementNode(div);
Attributes divAttributes = div.Attributes();
divAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("class", divClass));

IDictionary<String, String> actual = resolver.ResolveStyles(jSoupEllipse, svgContext);
IDictionary<String, String> expected = new Dictionary<String, String>();
expected.Put("class", divClass);
expected.Put("--test-var", expectedVarValue);
expected.Put("margin-top", expectedMargin);
expected.Put("margin-right", expectedMargin);
expected.Put("margin-bottom", expectedMargin);
expected.Put("margin-left", expectedMargin);
expected.Put("font-size", "12pt");
NUnit.Framework.Assert.AreEqual(expected, actual);
}

[NUnit.Framework.Test]
public virtual void SvgCssResolverStyleTagTest() {
iText.StyledXmlParser.Jsoup.Nodes.Element styleTag = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag
Expand Down

0 comments on commit 92871f7

Please sign in to comment.