use tailor_api::{Color, ColorPoint, ColorProfile, ColorTransition, FanProfilePoint};
use tailor_client::TailorConnection;
#[tokio::test]
async fn test_profiles() {
let connection = TailorConnection::new().await.unwrap();
let name = "__test_global_profile";
let second_name = "__test_global_profile2";
let fan_rename = "__test_fan_rename";
let keyboard_rename = "__test_keyboard_rename";
connection.get_number_of_fans().await.unwrap();
connection.get_led_devices().await.unwrap();
let active_name = connection.get_active_global_profile_name().await.unwrap();
let active_profile = connection.get_global_profile(&active_name).await.unwrap();
connection
.add_global_profile(name, &active_profile)
.await
.unwrap();
connection
.add_global_profile(name, &active_profile)
.await
.unwrap();
assert_eq!(
connection.get_global_profile(name).await.unwrap(),
active_profile
);
assert!(connection
.list_global_profiles()
.await
.unwrap()
.contains(&name.to_owned()));
connection
.rename_fan_profile(&active_profile.fans[0], fan_rename)
.await
.unwrap();
connection
.rename_led_profile(&active_profile.leds[0].profile, keyboard_rename)
.await
.unwrap();
let profile_after_rename = connection.get_global_profile(name).await.unwrap();
assert_eq!(profile_after_rename.fans[0], fan_rename);
assert_eq!(profile_after_rename.leds[0].profile, keyboard_rename);
connection
.rename_fan_profile(fan_rename, &active_profile.fans[0])
.await
.unwrap();
connection
.rename_led_profile(keyboard_rename, &active_profile.leds[0].profile)
.await
.unwrap();
assert_eq!(
connection.get_global_profile(name).await.unwrap(),
active_profile
);
connection
.rename_global_profile(name, second_name)
.await
.unwrap();
assert!(connection
.list_global_profiles()
.await
.unwrap()
.contains(&second_name.to_owned()));
assert!(!connection
.list_global_profiles()
.await
.unwrap()
.contains(&name.to_owned()));
connection
.rename_global_profile(name, second_name)
.await
.unwrap_err();
connection.remove_global_profile(name).await.unwrap_err();
connection
.copy_global_profile(second_name, name)
.await
.unwrap();
connection.remove_global_profile(name).await.unwrap();
connection.remove_global_profile(second_name).await.unwrap();
connection
.remove_global_profile(second_name)
.await
.unwrap_err();
}
#[tokio::test]
async fn test_fan() {
let connection = TailorConnection::new().await.unwrap();
let name = "__test_fan_profile";
let second_name = "__test_fan_profile2";
let profile = vec![
FanProfilePoint { temp: 30, fan: 20 },
FanProfilePoint { temp: 70, fan: 100 },
];
connection.add_fan_profile(name, &profile).await.unwrap();
connection.add_fan_profile(name, &profile).await.unwrap();
assert_eq!(connection.get_fan_profile(name).await.unwrap(), profile);
assert!(connection
.list_fan_profiles()
.await
.unwrap()
.contains(&name.to_owned()));
connection
.rename_fan_profile(name, second_name)
.await
.unwrap();
assert!(connection
.list_fan_profiles()
.await
.unwrap()
.contains(&second_name.to_owned()));
assert!(!connection
.list_fan_profiles()
.await
.unwrap()
.contains(&name.to_owned()));
connection
.rename_fan_profile(name, second_name)
.await
.unwrap_err();
connection.remove_fan_profile(name).await.unwrap_err();
connection
.copy_fan_profile(second_name, name)
.await
.unwrap();
connection.remove_fan_profile(name).await.unwrap();
connection.remove_fan_profile(second_name).await.unwrap();
connection
.remove_fan_profile(second_name)
.await
.unwrap_err();
}
#[tokio::test]
async fn test_keyboard() {
let connection = TailorConnection::new().await.unwrap();
let name = "__test_keyboard_profile";
let second_name = "__test_keyboard_profile2";
let profile = ColorProfile::Multiple(vec![
ColorPoint {
color: Color { r: 0, g: 255, b: 0 },
transition: ColorTransition::Linear,
transition_time: 3000,
},
ColorPoint {
color: Color { r: 255, g: 0, b: 0 },
transition: ColorTransition::Linear,
transition_time: 3000,
},
ColorPoint {
color: Color { r: 0, g: 0, b: 255 },
transition: ColorTransition::Linear,
transition_time: 3000,
},
]);
connection.add_led_profile(name, &profile).await.unwrap();
connection.add_led_profile(name, &profile).await.unwrap();
assert_eq!(connection.get_led_profile(name).await.unwrap(), profile);
assert!(connection
.list_led_profiles()
.await
.unwrap()
.contains(&name.to_owned()));
connection
.rename_led_profile(name, second_name)
.await
.unwrap();
assert!(connection
.list_led_profiles()
.await
.unwrap()
.contains(&second_name.to_owned()));
assert!(!connection
.list_led_profiles()
.await
.unwrap()
.contains(&name.to_owned()));
connection
.rename_led_profile(name, second_name)
.await
.unwrap_err();
connection.remove_led_profile(name).await.unwrap_err();
connection
.copy_led_profile(second_name, name)
.await
.unwrap();
connection.remove_led_profile(name).await.unwrap();
connection.remove_led_profile(second_name).await.unwrap();
connection
.remove_led_profile(second_name)
.await
.unwrap_err();
}