MCPcopy Create free account
hub / github.com/Moosync/Moosync / test_preference_events

Function test_preference_events

src-tauri/preferences/src/test.rs:272–306  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

270
271#[test]
272fn test_preference_events() -> Result<()> {
273 let test_dir = setup_test_dir();
274
275 let prefs = PreferenceConfig::new(test_dir.clone())?;
276
277 // Get the receiver
278 let receiver = prefs.get_receiver();
279
280 // Save data to trigger an event
281 let event_key = "event_key";
282 prefs.save_selective(event_key.to_string(), Some("event_value"))?;
283
284 // Small delay to ensure event is processed
285 thread::sleep(Duration::from_millis(50));
286
287 // Try to receive the event
288 if let Ok((key, value)) = receiver.try_recv() {
289 // The actual key is prefixed with "prefs."
290 let expected_key = format!("prefs.{}", event_key);
291 assert_eq!(
292 key, expected_key,
293 "Event key should match with 'prefs.' prefix"
294 );
295 assert_eq!(
296 value.as_str().unwrap(),
297 "event_value",
298 "Event value should match"
299 );
300 } else {
301 panic!("No event received");
302 }
303
304 cleanup_test_dir(test_dir);
305 Ok(())
306}
307
308#[test]
309fn test_remove_preference() -> Result<()> {

Callers

nothing calls this directly

Calls 5

setup_test_dirFunction · 0.85
cleanup_test_dirFunction · 0.85
cloneMethod · 0.80
get_receiverMethod · 0.80
save_selectiveMethod · 0.80

Tested by

no test coverage detected