From f31fef8a28b68256345bc16d9d32513d6ef0ead8 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Wed, 23 Jul 2025 00:41:30 +0900 Subject: [PATCH] Add keyframe test code --- libs/sheet/src/lib.rs | 110 ++++++++++++++++++ ...ts__create_css_with_global_selector-5.snap | 5 + .../snapshots/sheet__tests__keyframes-2.snap | 5 + .../snapshots/sheet__tests__keyframes-3.snap | 5 + .../snapshots/sheet__tests__keyframes.snap | 5 + .../sheet__tests__selector_with_query.snap | 5 + 6 files changed, 135 insertions(+) create mode 100644 libs/sheet/src/snapshots/sheet__tests__create_css_with_global_selector-5.snap create mode 100644 libs/sheet/src/snapshots/sheet__tests__keyframes-2.snap create mode 100644 libs/sheet/src/snapshots/sheet__tests__keyframes-3.snap create mode 100644 libs/sheet/src/snapshots/sheet__tests__keyframes.snap create mode 100644 libs/sheet/src/snapshots/sheet__tests__selector_with_query.snap diff --git a/libs/sheet/src/lib.rs b/libs/sheet/src/lib.rs index 564c17b3..a538272c 100644 --- a/libs/sheet/src/lib.rs +++ b/libs/sheet/src/lib.rs @@ -755,6 +755,27 @@ mod tests { assert_debug_snapshot!(sheet.create_css()); } + #[test] + fn test_selector_with_query() { + let mut sheet = StyleSheet::default(); + sheet.add_property( + "test", + "my", + 0, + "40px", + Some( + &StyleSelector::Media { + query: "(min-width: 1024px)".to_string(), + selector: Some("&:hover".to_string()), + } + .into(), + ), + None, + ); + + assert_debug_snapshot!(sheet.create_css()); + } + #[test] fn test_deserialize() { { @@ -906,6 +927,30 @@ mod tests { Some(255), ); assert_debug_snapshot!(sheet.create_css()); + + sheet.add_property( + "test", + "background-color", + 0, + "red", + Some(&StyleSelector::Global( + "div".to_string(), + "test2.tsx".to_string(), + )), + Some(255), + ); + + sheet.add_property( + "test2", + "background-color", + 0, + "red", + Some(&StyleSelector::Selector("&:hover".to_string()).into()), + Some(255), + ); + + sheet.rm_global_css("test.tsx"); + assert_debug_snapshot!(sheet.create_css()); } #[test] @@ -988,4 +1033,69 @@ mod tests { "import \"package\";declare module \"package\"{interface ColorInterface{[`$(primary)`]:null;}interface TypographyInterface{[`prim\\`\\`ary`]:null;}interface ThemeInterface{dark:null;}}" ); } + + #[test] + fn test_keyframes() { + let mut sheet = StyleSheet::default(); + let mut keyframes: BTreeMap> = BTreeMap::new(); + + let mut from_props = BTreeSet::new(); + from_props.insert(StyleSheetProperty { + class_name: String::from("test"), + property: String::from("opacity"), + value: String::from("0"), + selector: None, + }); + keyframes.insert( + String::from("from"), + vec![(String::from("opacity"), String::from("0"))], + ); + + let mut to_props = BTreeSet::new(); + to_props.insert(StyleSheetProperty { + class_name: String::from("test"), + property: String::from("opacity"), + value: String::from("1"), + selector: None, + }); + keyframes.insert( + String::from("to"), + vec![(String::from("opacity"), String::from("1"))], + ); + + sheet.add_keyframes("fadeIn", keyframes); + let past = sheet.create_css(); + assert_debug_snapshot!(past); + + let mut keyframes: BTreeMap> = BTreeMap::new(); + let mut from_props = BTreeSet::new(); + from_props.insert(StyleSheetProperty { + class_name: String::from("test"), + property: String::from("opacity"), + value: String::from("0"), + selector: None, + }); + keyframes.insert( + String::from("from"), + vec![(String::from("opacity"), String::from("0"))], + ); + + let mut to_props = BTreeSet::new(); + to_props.insert(StyleSheetProperty { + class_name: String::from("test"), + property: String::from("opacity"), + value: String::from("1"), + selector: None, + }); + keyframes.insert( + String::from("to"), + vec![(String::from("opacity"), String::from("1"))], + ); + + sheet.add_keyframes("fadeIn", keyframes); + + let now = sheet.create_css(); + assert_debug_snapshot!(now); + assert_eq!(past, now); + } } diff --git a/libs/sheet/src/snapshots/sheet__tests__create_css_with_global_selector-5.snap b/libs/sheet/src/snapshots/sheet__tests__create_css_with_global_selector-5.snap new file mode 100644 index 00000000..dab7c090 --- /dev/null +++ b/libs/sheet/src/snapshots/sheet__tests__create_css_with_global_selector-5.snap @@ -0,0 +1,5 @@ +--- +source: libs/sheet/src/lib.rs +expression: sheet.create_css() +--- +"div{background-color:red}.test2:hover{background-color:red}" diff --git a/libs/sheet/src/snapshots/sheet__tests__keyframes-2.snap b/libs/sheet/src/snapshots/sheet__tests__keyframes-2.snap new file mode 100644 index 00000000..6fb6a675 --- /dev/null +++ b/libs/sheet/src/snapshots/sheet__tests__keyframes-2.snap @@ -0,0 +1,5 @@ +--- +source: libs/sheet/src/lib.rs +expression: now +--- +"@keyframes fadeIn{from{opacity:0}to{opacity:1}}" diff --git a/libs/sheet/src/snapshots/sheet__tests__keyframes-3.snap b/libs/sheet/src/snapshots/sheet__tests__keyframes-3.snap new file mode 100644 index 00000000..af506892 --- /dev/null +++ b/libs/sheet/src/snapshots/sheet__tests__keyframes-3.snap @@ -0,0 +1,5 @@ +--- +source: libs/sheet/src/lib.rs +expression: sheet.create_css() +--- +"@keyframes fadeIn{from{opacity:0}to{opacity:1}}" diff --git a/libs/sheet/src/snapshots/sheet__tests__keyframes.snap b/libs/sheet/src/snapshots/sheet__tests__keyframes.snap new file mode 100644 index 00000000..af506892 --- /dev/null +++ b/libs/sheet/src/snapshots/sheet__tests__keyframes.snap @@ -0,0 +1,5 @@ +--- +source: libs/sheet/src/lib.rs +expression: sheet.create_css() +--- +"@keyframes fadeIn{from{opacity:0}to{opacity:1}}" diff --git a/libs/sheet/src/snapshots/sheet__tests__selector_with_query.snap b/libs/sheet/src/snapshots/sheet__tests__selector_with_query.snap new file mode 100644 index 00000000..84040e9c --- /dev/null +++ b/libs/sheet/src/snapshots/sheet__tests__selector_with_query.snap @@ -0,0 +1,5 @@ +--- +source: libs/sheet/src/lib.rs +expression: sheet.create_css() +--- +"@media(min-width: 1024px){.test:hover{margin-top:40px;margin-bottom:40px}}"