use fader_config::{ProfileDocument, SelectorDraft, SelectorField, SelectorPattern, TargetKind}; const PROFILE: &str = include_str!("../../examples/profiles/desktop.toml"); #[test] fn draft_creates_an_application_group_and_fader_as_valid_toml() { let mut draft = ProfileDocument::parse(PROFILE).unwrap(); draft .add_application( "chat", "Chat", &[SelectorDraft { field: SelectorField::ProcessBinary, pattern: SelectorPattern::Exact("signal-desktop".to_owned()), }], ) .unwrap(); draft .add_group("communications", "Communications", &["chat", "browser"]) .unwrap(); draft .add_fader( "communications-fader", TargetKind::Group, "communications", true, 0.02, ) .unwrap(); let profile = draft.preview().unwrap(); assert!( profile .applications() .iter() .any(|item| item.id() == "chat") ); assert!( profile .groups() .iter() .any(|item| item.id() == "communications") ); assert!( profile .faders() .iter() .any(|item| item.id() == "communications-fader") ); ProfileDocument::parse(&draft.finish().unwrap()).unwrap(); } #[test] fn invalid_edits_and_referenced_deletes_roll_back_the_draft() { let mut draft = ProfileDocument::parse(PROFILE).unwrap(); let original = draft.source(); let invalid = draft .add_application( "broken", "Broken", &[SelectorDraft { field: SelectorField::ApplicationName, pattern: SelectorPattern::Regex("(".to_owned()), }], ) .unwrap_err(); assert!(invalid.to_string().contains("regex")); assert_eq!(draft.source(), original); let referenced = draft.remove_application("browser").unwrap_err(); assert!(referenced.to_string().contains("unknown application")); assert_eq!(draft.source(), original); }