Skip to content

Commit

Permalink
Add tests for radio button
Browse files Browse the repository at this point in the history
  • Loading branch information
sundaram123krishnan committed Nov 21, 2024
1 parent f6614d3 commit f34761c
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/views/radio_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,66 @@ where
{
RadioButton::new_labeled(represented_value, actual_value, label)
}

#[cfg(test)]
mod test {
use super::*;
use floem_reactive::{create_rw_signal, SignalGet, SignalUpdate};

#[test]
fn test_radio_button_new_initial_value() {
let actual_value = create_rw_signal(String::from("Option1"));
let _radio_button = RadioButton::new_rw("Option1".to_string(), actual_value);
assert_eq!(actual_value.get(), "Option1");
}

#[test]
fn test_radio_button_new_changes_state() {
let actual_value = create_rw_signal(String::from("Option1"));
let _radio_button = RadioButton::new_rw("Option2".to_string(), actual_value);
actual_value.set("Option2".to_string());
assert_eq!(actual_value.get(), "Option2");
}

#[test]
fn test_labeled_radio_button_initial_value() {
let actual_value = create_rw_signal(String::from("OptionA"));
let _labeled_radio_button =
RadioButton::new_labeled_rw("OptionA".to_string(), actual_value, || {
"Label for Option A"
});

assert_eq!(actual_value.get(), "OptionA");
}

#[test]
fn test_labeled_radio_button_changes_state() {
let actual_value = create_rw_signal(String::from("OptionA"));
let _labeled_radio_button =
RadioButton::new_labeled_rw("OptionB".to_string(), actual_value, || {
"Label for Option B"
});

actual_value.set("OptionB".to_string());

assert_eq!(actual_value.get(), "OptionB");
}

#[test]
fn test_radio_button_new_get() {
let actual_value = create_rw_signal(String::from("Option1"));
let _radio_button = RadioButton::new_get("Option1".to_string(), actual_value);
assert_eq!(actual_value.get(), "Option1");
}

#[test]
fn test_radio_button_new_labeled_get() {
let actual_value = create_rw_signal(String::from("OptionA"));
let _labeled_radio_button =
RadioButton::new_labeled_get("OptionA".to_string(), actual_value, || {
"Label for Option A"
});

assert_eq!(actual_value.get(), "OptionA");
}
}

0 comments on commit f34761c

Please sign in to comment.