public void CanRegisterFromToKeyFrames() { StyleEngine.Keyframes(new Keyframes { From = new Style { Opacity = 0, }, To = new Style { Opacity = 1 } }); Assert.AreEqual("@keyframes css-0{from{opacity:0;}to{opacity:1;}}", stylesheet.GetRules()); }
public async Task SupportOverridingTheDefaultPrefix() { var className = await StyleEngine.StyleToClassName(new Style { Background = "red" }); Assert.AreEqual(className, "myCss-0"); Assert.AreEqual(".myCss-0{background:red;}", _stylessheet.GetRules()); }
public void CanMergeStylesSet() { Func <object, StyleSetFake> fn1 = (prop) => { return(new StyleSetFake() { Root = new Style { Background = "green", FontSize = 12 }, }); }; Func <object, StyleSetFake> fn2 = (porps) => { return(new StyleSetFake { Root = new Style { Background = "yellow", Color = "pink" } }); }; var empty = new StyleSetFake { }; var result = StyleEngine .MergeStyleSets(empty, new StyleSetFake { Root = new Style { Background = "red", }, A = new Style { Background = "green" }, SubComponentStyles = { ["labelStyles"] = fn1 } }, new StyleSetFake { A = new Style { Background = "white" }, B = new Style { Background = "blue" } }, new StyleSetFake { Root = new Style { Selectors = { [":hover"] = new Style { Background = "yellow" } } }, SubComponentStyles = { ["labelStyles"] = fn2 } }); Assert.AreEqual("root-0", result.Root); Assert.AreEqual("a-1", result.A); Assert.AreEqual("b-2", result.B); Assert.IsTrue(result.ContainsKey(("sub-component-styles", "SubComponentStyles"))); if (result.SubComponentStyles["labelStyles"] is Func <object, StyleSetFake> function) { var mergedLabelStyles = function(new StyleSetFake { }); Assert.AreEqual(new StyleSetFake { Root = new Style[] { new Style { Background = "green", FontSize = 12, }, new Style { Background = "yellow", Color = "pink" } } }, mergedLabelStyles); } else { Assert.IsTrue(false, "The subcompoment must be a function"); } Assert.AreEqual(".root-0{background:red;}.root-0:hover{background:yellow;}" + ".a-1{background:white;}" + ".b-2{background:blue;}", _stylesheet.GetRules()); }
public async Task CanRegisterClassesAndAvoidReRegistering() { var className = await StyleEngine.StyleToClassName(new Style { Background = "red" }); Assert.AreEqual("css-0", className, $"Bad generated class name, expected css-0 and get {className}"); Assert.AreEqual(".css-0{background:red;}", _stylesheet.GetRules()); className = await StyleEngine.StyleToClassName(new Style { Background = "red" }); Assert.AreEqual("css-0", className, $"Bad generated class name, expected css-0 and get {className}"); Assert.AreEqual(".css-0{background:red;}", _stylesheet.GetRules()); className = await StyleEngine.StyleToClassName(new Style { Background = "green" }); Assert.AreEqual("css-1", className, $"Bad generated class name, expected css-0 and get {className}"); Assert.AreEqual(".css-0{background:red;}.css-1{background:green;}", _stylesheet.GetRules()); }