@@ -755,6 +755,27 @@ mod tests {
755755 assert_debug_snapshot ! ( sheet. create_css( ) ) ;
756756 }
757757
758+ #[ test]
759+ fn test_selector_with_query ( ) {
760+ let mut sheet = StyleSheet :: default ( ) ;
761+ sheet. add_property (
762+ "test" ,
763+ "my" ,
764+ 0 ,
765+ "40px" ,
766+ Some (
767+ & StyleSelector :: Media {
768+ query : "(min-width: 1024px)" . to_string ( ) ,
769+ selector : Some ( "&:hover" . to_string ( ) ) ,
770+ }
771+ . into ( ) ,
772+ ) ,
773+ None ,
774+ ) ;
775+
776+ assert_debug_snapshot ! ( sheet. create_css( ) ) ;
777+ }
778+
758779 #[ test]
759780 fn test_deserialize ( ) {
760781 {
@@ -906,6 +927,30 @@ mod tests {
906927 Some ( 255 ) ,
907928 ) ;
908929 assert_debug_snapshot ! ( sheet. create_css( ) ) ;
930+
931+ sheet. add_property (
932+ "test" ,
933+ "background-color" ,
934+ 0 ,
935+ "red" ,
936+ Some ( & StyleSelector :: Global (
937+ "div" . to_string ( ) ,
938+ "test2.tsx" . to_string ( ) ,
939+ ) ) ,
940+ Some ( 255 ) ,
941+ ) ;
942+
943+ sheet. add_property (
944+ "test2" ,
945+ "background-color" ,
946+ 0 ,
947+ "red" ,
948+ Some ( & StyleSelector :: Selector ( "&:hover" . to_string ( ) ) . into ( ) ) ,
949+ Some ( 255 ) ,
950+ ) ;
951+
952+ sheet. rm_global_css ( "test.tsx" ) ;
953+ assert_debug_snapshot ! ( sheet. create_css( ) ) ;
909954 }
910955
911956 #[ test]
@@ -988,4 +1033,69 @@ mod tests {
9881033 "import \" package\" ;declare module \" package\" {interface ColorInterface{[`$(primary)`]:null;}interface TypographyInterface{[`prim\\ `\\ `ary`]:null;}interface ThemeInterface{dark:null;}}"
9891034 ) ;
9901035 }
1036+
1037+ #[ test]
1038+ fn test_keyframes ( ) {
1039+ let mut sheet = StyleSheet :: default ( ) ;
1040+ let mut keyframes: BTreeMap < String , Vec < ( String , String ) > > = BTreeMap :: new ( ) ;
1041+
1042+ let mut from_props = BTreeSet :: new ( ) ;
1043+ from_props. insert ( StyleSheetProperty {
1044+ class_name : String :: from ( "test" ) ,
1045+ property : String :: from ( "opacity" ) ,
1046+ value : String :: from ( "0" ) ,
1047+ selector : None ,
1048+ } ) ;
1049+ keyframes. insert (
1050+ String :: from ( "from" ) ,
1051+ vec ! [ ( String :: from( "opacity" ) , String :: from( "0" ) ) ] ,
1052+ ) ;
1053+
1054+ let mut to_props = BTreeSet :: new ( ) ;
1055+ to_props. insert ( StyleSheetProperty {
1056+ class_name : String :: from ( "test" ) ,
1057+ property : String :: from ( "opacity" ) ,
1058+ value : String :: from ( "1" ) ,
1059+ selector : None ,
1060+ } ) ;
1061+ keyframes. insert (
1062+ String :: from ( "to" ) ,
1063+ vec ! [ ( String :: from( "opacity" ) , String :: from( "1" ) ) ] ,
1064+ ) ;
1065+
1066+ sheet. add_keyframes ( "fadeIn" , keyframes) ;
1067+ let past = sheet. create_css ( ) ;
1068+ assert_debug_snapshot ! ( past) ;
1069+
1070+ let mut keyframes: BTreeMap < String , Vec < ( String , String ) > > = BTreeMap :: new ( ) ;
1071+ let mut from_props = BTreeSet :: new ( ) ;
1072+ from_props. insert ( StyleSheetProperty {
1073+ class_name : String :: from ( "test" ) ,
1074+ property : String :: from ( "opacity" ) ,
1075+ value : String :: from ( "0" ) ,
1076+ selector : None ,
1077+ } ) ;
1078+ keyframes. insert (
1079+ String :: from ( "from" ) ,
1080+ vec ! [ ( String :: from( "opacity" ) , String :: from( "0" ) ) ] ,
1081+ ) ;
1082+
1083+ let mut to_props = BTreeSet :: new ( ) ;
1084+ to_props. insert ( StyleSheetProperty {
1085+ class_name : String :: from ( "test" ) ,
1086+ property : String :: from ( "opacity" ) ,
1087+ value : String :: from ( "1" ) ,
1088+ selector : None ,
1089+ } ) ;
1090+ keyframes. insert (
1091+ String :: from ( "to" ) ,
1092+ vec ! [ ( String :: from( "opacity" ) , String :: from( "1" ) ) ] ,
1093+ ) ;
1094+
1095+ sheet. add_keyframes ( "fadeIn" , keyframes) ;
1096+
1097+ let now = sheet. create_css ( ) ;
1098+ assert_debug_snapshot ! ( now) ;
1099+ assert_eq ! ( past, now) ;
1100+ }
9911101}
0 commit comments