stylex_transform/shared/structures/tests/
gen_css_test.rs1#[cfg(test)]
2mod converting_pre_rule_to_css {
3 use indexmap::IndexMap;
4
5 use crate::shared::structures::pre_rule::{
6 CompiledResult, ComputedStyle, PreRule, PreRuleValue, StylesPreRule,
7 };
8 use crate::shared::structures::state_manager::StateManager;
9 use crate::shared::structures::types::ClassesToOriginalPaths;
10 use stylex_enums::style_resolution::StyleResolution;
11 use stylex_types::structures::injectable_style::InjectableStyle;
12
13 pub(super) fn get_state() -> StateManager {
14 let mut state_manager = StateManager::default();
15
16 state_manager.options.class_name_prefix = "x".to_string();
17 state_manager.options.dev = false;
18 state_manager.options.debug = false;
19 state_manager.options.enable_debug_class_names = true;
20 state_manager.options.enable_dev_class_names = false;
21 state_manager.options.enable_debug_data_prop = true;
22 state_manager.options.enable_font_size_px_to_rem = false;
23 state_manager.options.enable_logical_styles_polyfill = false;
24 state_manager.options.enable_minified_keys = true;
25 state_manager.options.style_resolution = StyleResolution::LegacyExpandShorthands;
26 state_manager.options.test = false;
27
28 state_manager
29 }
30
31 #[test]
32 fn should_convert_a_pre_rule_to_css() {
33 let result = StylesPreRule::new(
34 "color",
35 PreRuleValue::String("red".to_string()),
36 Some(vec!["color".to_string()]),
37 )
38 .compiled(&mut get_state());
39
40 let mut classes_to_original_paths: ClassesToOriginalPaths = IndexMap::new();
41 classes_to_original_paths.insert("x1e2nbdu".to_string(), vec!["color".to_string()]);
42
43 assert_eq!(
44 result,
45 CompiledResult::ComputedStyles(vec![ComputedStyle(
46 "x1e2nbdu".to_string(),
47 InjectableStyle {
48 ltr: ".x1e2nbdu{color:red}".to_string(),
49 rtl: None,
50 priority: Some(3000.0)
51 },
52 classes_to_original_paths
53 )])
54 );
55 }
56}