Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a property "appearance" into RadioFormItem #134

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sos21-domain/src/model/form/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ impl CheckFormItems {
#[cfg(test)]
mod tests {
use super::{
radio::{RadioFormItem, RadioFormItemButtons, RadioId},
radio::{Appearance, RadioFormItem, RadioFormItemButtons, RadioId},
CheckAnswerErrorKind, CheckAnswerItemErrorKind, CheckFormItems, FormItemBody,
FormItemCondition, FormItemId, FormItems, FromItemsErrorKind,
};
Expand Down Expand Up @@ -828,6 +828,7 @@ mod tests {
buttons: RadioFormItemButtons::from_buttons(vec![radio1.clone(), radio2.clone()])
.unwrap(),
is_required: true,
appearance: Appearance::RadioButton,
}));
let condition = FormItemCondition::RadioSelected {
item_id: item1.id,
Expand Down
14 changes: 13 additions & 1 deletion sos21-domain/src/model/form/item/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ pub use radio::{Radio, RadioId, RadioLabel};
#[serde(transparent)]
pub struct RadioFormItemButtons(LengthBoundedVec<typenum::U1, typenum::U32, Radio>);

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Appearance {
DropDown,
RadioButton,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FromButtonsErrorKind {
Empty,
Expand Down Expand Up @@ -93,6 +100,7 @@ impl<'de> Deserialize<'de> for RadioFormItemButtons {
pub struct RadioFormItem {
pub buttons: RadioFormItemButtons,
pub is_required: bool,
pub appearance: Appearance,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
Expand Down Expand Up @@ -146,7 +154,7 @@ impl RadioFormItem {

#[cfg(test)]
mod tests {
use super::{CheckAnswerErrorKind, RadioFormItem, RadioFormItemButtons};
use super::{Appearance, CheckAnswerErrorKind, RadioFormItem, RadioFormItemButtons};
use crate::test::model as test_model;

#[test]
Expand All @@ -158,6 +166,7 @@ mod tests {
buttons: RadioFormItemButtons::from_buttons(vec![button1.clone(), button2.clone()])
.unwrap(),
is_required: true,
appearance: Appearance::RadioButton,
}
.check_answer(Some(button1.id))
.unwrap();
Expand All @@ -166,6 +175,7 @@ mod tests {
buttons: RadioFormItemButtons::from_buttons(vec![button1.clone(), button2.clone()])
.unwrap(),
is_required: false,
appearance: Appearance::RadioButton,
}
.check_answer(None)
.unwrap();
Expand All @@ -181,6 +191,7 @@ mod tests {
buttons: RadioFormItemButtons::from_buttons(vec![button1.clone(), button2.clone()])
.unwrap(),
is_required: true,
appearance: Appearance::RadioButton
}
.check_answer(None)
.unwrap_err()
Expand All @@ -200,6 +211,7 @@ mod tests {
buttons: RadioFormItemButtons::from_buttons(vec![button1.clone(), button2.clone()])
.unwrap(),
is_required: true,
appearance: Appearance::RadioButton
}
.check_answer(Some(button3.id))
.unwrap_err()
Expand Down
3 changes: 2 additions & 1 deletion sos21-domain/src/test/model/form/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::model::form::item::{
GridRadioColumn, GridRadioColumnId, GridRadioColumnLabel, GridRadioRow, GridRadioRowId,
GridRadioRowLabel,
},
radio::{Radio, RadioFormItemButtons, RadioId, RadioLabel},
radio::{Appearance, Radio, RadioFormItemButtons, RadioId, RadioLabel},
FormItem, FormItemBody, FormItemCondition, FormItemConditions, FormItemDescription, FormItemId,
FormItemName, FormItems, RadioFormItem,
};
Expand Down Expand Up @@ -85,6 +85,7 @@ pub fn new_radio_form_item_body_with_button(button: Radio) -> FormItemBody {
FormItemBody::Radio(RadioFormItem {
buttons: RadioFormItemButtons::from_buttons(vec![button]).unwrap(),
is_required: true,
appearance: Appearance::RadioButton,
})
}

Expand Down
2 changes: 2 additions & 0 deletions sos21-use-case/src/interface/form/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ pub fn to_form_item(item: FormItem) -> Result<form::FormItem, FormItemError> {
FormItemBody::Radio {
buttons,
is_required,
appearance,
} => {
let buttons = buttons
.into_iter()
Expand All @@ -254,6 +255,7 @@ pub fn to_form_item(item: FormItem) -> Result<form::FormItem, FormItemError> {
let radio_item = item::RadioFormItem {
buttons,
is_required,
appearance,
};
item::FormItemBody::Radio(radio_item)
}
Expand Down