1
0
mirror of https://github.com/pcvolkmer/osc-variant.git synced 2025-04-20 20:26:50 +00:00

chore: simple code cleanup

This commit is contained in:
Paul-Christian Volkmer 2024-04-08 19:37:57 +02:00
parent f340afe9ef
commit aeab8bee2f
3 changed files with 83 additions and 30 deletions

View File

@ -28,16 +28,16 @@ use std::collections::HashSet;
use console::style; use console::style;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::checks::{Checkable, CheckNotice};
use crate::checks::CheckNotice::ErrorWithCode; use crate::checks::CheckNotice::ErrorWithCode;
use crate::checks::{CheckNotice, Checkable};
use crate::model::onkostar_editor::OnkostarEditor;
use crate::model::requirements::{Requirement, Requires};
use crate::model::{ use crate::model::{
Ansichten, apply_profile_to_form_entry, apply_profile_to_form_field, Comparable, Entries, apply_profile_to_form_entry, apply_profile_to_form_field, Ansichten, Comparable, Entries,
Filter, FolderContent, FormEntry, FormEntryContainer, Kennzahlen, Listable, MenuCategory, Filter, FolderContent, FormEntry, FormEntryContainer, Kennzahlen, Listable, MenuCategory,
PlausibilityRules, PunkteKategorien, RefEntries, Script, Sortable, PlausibilityRules, PunkteKategorien, RefEntries, Script, Sortable,
}; };
use crate::model::{Haeufigkeiten, Ordner}; use crate::model::{Haeufigkeiten, Ordner};
use crate::model::onkostar_editor::OnkostarEditor;
use crate::model::requirements::{Requirement, Requires};
use crate::profile::Profile; use crate::profile::Profile;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -713,13 +713,25 @@ mod tests {
assert!(profile.is_ok()); assert!(profile.is_ok());
let profile = profile.unwrap(); let profile = profile.unwrap();
assert_eq!(onkostar_editor.editor.data_form[0].entries.entry[2].name, "Auswahl"); assert_eq!(
assert_eq!(onkostar_editor.editor.data_form[0].entries.entry[2].default_value, ""); onkostar_editor.editor.data_form[0].entries.entry[2].name,
"Auswahl"
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[2].default_value,
""
);
onkostar_editor.apply_profile(&profile); onkostar_editor.apply_profile(&profile);
assert_eq!(onkostar_editor.editor.data_form[0].entries.entry[2].name, "Auswahl"); assert_eq!(
assert_eq!(onkostar_editor.editor.data_form[0].entries.entry[2].default_value, "B") onkostar_editor.editor.data_form[0].entries.entry[2].name,
"Auswahl"
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[2].default_value,
"B"
)
} }
#[test] #[test]
@ -737,13 +749,25 @@ mod tests {
assert!(profile.is_ok()); assert!(profile.is_ok());
let profile = profile.unwrap(); let profile = profile.unwrap();
assert_eq!(onkostar_editor.editor.data_form[0].entries.entry[2].name, "Auswahl"); assert_eq!(
assert_eq!(onkostar_editor.editor.data_form[0].entries.entry[2].default_value, ""); onkostar_editor.editor.data_form[0].entries.entry[2].name,
"Auswahl"
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[2].default_value,
""
);
onkostar_editor.apply_profile(&profile); onkostar_editor.apply_profile(&profile);
assert_eq!(onkostar_editor.editor.data_form[0].entries.entry[2].name, "Auswahl"); assert_eq!(
assert_eq!(onkostar_editor.editor.data_form[0].entries.entry[2].default_value, "") onkostar_editor.editor.data_form[0].entries.entry[2].name,
"Auswahl"
);
assert_eq!(
onkostar_editor.editor.data_form[0].entries.entry[2].default_value,
""
)
} }
#[test] #[test]
@ -769,7 +793,7 @@ mod tests {
match &onkostar_editor.editor.data_form[0].menu_category { match &onkostar_editor.editor.data_form[0].menu_category {
Some(menu_category) => assert_eq!(menu_category.name, "Testformulare"), Some(menu_category) => assert_eq!(menu_category.name, "Testformulare"),
_ => panic!("Test failed: MenuCategory not found!") _ => panic!("Test failed: MenuCategory not found!"),
} }
} }
@ -792,7 +816,7 @@ mod tests {
match &onkostar_editor.editor.data_form[0].menu_category { match &onkostar_editor.editor.data_form[0].menu_category {
Some(menu_category) => assert_eq!(menu_category.name, "Test"), Some(menu_category) => assert_eq!(menu_category.name, "Test"),
_ => panic!("Test failed: MenuCategory not found!") _ => panic!("Test failed: MenuCategory not found!"),
} }
} }
} }

View File

@ -28,16 +28,16 @@ use std::collections::HashSet;
use console::style; use console::style;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::checks::{Checkable, CheckNotice};
use crate::checks::CheckNotice::ErrorWithCode; use crate::checks::CheckNotice::ErrorWithCode;
use crate::checks::{CheckNotice, Checkable};
use crate::model::onkostar_editor::OnkostarEditor;
use crate::model::requirements::{Requirement, Requires};
use crate::model::{ use crate::model::{
Ansichten, apply_profile_to_form_entry, apply_profile_to_form_field, Comparable, Entries, apply_profile_to_form_entry, apply_profile_to_form_field, Ansichten, Comparable, Entries,
Filter, FolderContent, FormEntry, FormEntryContainer, Kennzahlen, Listable, MenuCategory, Filter, FolderContent, FormEntry, FormEntryContainer, Kennzahlen, Listable, MenuCategory,
PlausibilityRules, PunkteKategorien, RefEntries, Script, Sortable, PlausibilityRules, PunkteKategorien, RefEntries, Script, Sortable,
}; };
use crate::model::{Haeufigkeiten, Ordner}; use crate::model::{Haeufigkeiten, Ordner};
use crate::model::onkostar_editor::OnkostarEditor;
use crate::model::requirements::{Requirement, Requires};
use crate::profile::Profile; use crate::profile::Profile;
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
@ -712,13 +712,25 @@ mod tests {
assert!(profile.is_ok()); assert!(profile.is_ok());
let profile = profile.unwrap(); let profile = profile.unwrap();
assert_eq!(onkostar_editor.editor.unterformular[0].entries.entry[1].name, "Termin"); assert_eq!(
assert_eq!(onkostar_editor.editor.unterformular[0].entries.entry[1].default_value, ""); onkostar_editor.editor.unterformular[0].entries.entry[1].name,
"Termin"
);
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[1].default_value,
""
);
onkostar_editor.apply_profile(&profile); onkostar_editor.apply_profile(&profile);
assert_eq!(onkostar_editor.editor.unterformular[0].entries.entry[1].name, "Termin"); assert_eq!(
assert_eq!(onkostar_editor.editor.unterformular[0].entries.entry[1].default_value, "2024-03-18") onkostar_editor.editor.unterformular[0].entries.entry[1].name,
"Termin"
);
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[1].default_value,
"2024-03-18"
)
} }
#[test] #[test]
@ -736,13 +748,25 @@ mod tests {
assert!(profile.is_ok()); assert!(profile.is_ok());
let profile = profile.unwrap(); let profile = profile.unwrap();
assert_eq!(onkostar_editor.editor.unterformular[0].entries.entry[1].name, "Termin"); assert_eq!(
assert_eq!(onkostar_editor.editor.unterformular[0].entries.entry[1].default_value, ""); onkostar_editor.editor.unterformular[0].entries.entry[1].name,
"Termin"
);
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[1].default_value,
""
);
onkostar_editor.apply_profile(&profile); onkostar_editor.apply_profile(&profile);
assert_eq!(onkostar_editor.editor.unterformular[0].entries.entry[1].name, "Termin"); assert_eq!(
assert_eq!(onkostar_editor.editor.unterformular[0].entries.entry[1].default_value, "") onkostar_editor.editor.unterformular[0].entries.entry[1].name,
"Termin"
);
assert_eq!(
onkostar_editor.editor.unterformular[0].entries.entry[1].default_value,
""
)
} }
#[test] #[test]
@ -762,6 +786,8 @@ mod tests {
onkostar_editor.apply_profile(&profile); onkostar_editor.apply_profile(&profile);
assert!(&onkostar_editor.editor.unterformular[0].menu_category.is_none()); assert!(&onkostar_editor.editor.unterformular[0]
.menu_category
.is_none());
} }
} }

View File

@ -89,7 +89,7 @@ pub struct FormField {
pub name: String, pub name: String,
#[serde(default)] #[serde(default)]
pub hide: bool, pub hide: bool,
pub default_value: Option<String> pub default_value: Option<String>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -280,7 +280,10 @@ mod tests {
assert_eq!(profile.forms.len(), 1); assert_eq!(profile.forms.len(), 1);
assert_eq!(profile.forms[0].name, "DNPM Therapieplan"); assert_eq!(profile.forms[0].name, "DNPM Therapieplan");
assert_eq!(profile.forms[0].form_fields[0].name, "formularfeld_to_keep"); assert_eq!(profile.forms[0].form_fields[0].name, "formularfeld_to_keep");
assert_eq!(profile.forms[0].form_fields[0].default_value, Some("X".to_string())); assert_eq!(
profile.forms[0].form_fields[0].default_value,
Some("X".to_string())
);
} }
Err(e) => panic!("Cannot deserialize profile: {}", e), Err(e) => panic!("Cannot deserialize profile: {}", e),
} }