From 7e26a46e3438c220eb5b886c391f20e5b7996776 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Mon, 18 Mar 2024 15:19:19 +0100 Subject: [PATCH] test: add tests for menu category customization --- src/model/data_form.rs | 50 ++++++++++++++++++++++++++++++++++++++ src/model/unterformular.rs | 20 +++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/src/model/data_form.rs b/src/model/data_form.rs index adae6e3..a038a13 100644 --- a/src/model/data_form.rs +++ b/src/model/data_form.rs @@ -745,4 +745,54 @@ mod tests { assert_eq!(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] + fn should_change_menu_category() { + let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc")); + + assert!(onkostar_editor.is_ok()); + let mut onkostar_editor = onkostar_editor.unwrap(); + + let profile = "forms: + - name: 'Hauptformular' + menu_category: + name: Testformulare + position: 1.0 + column: 1 + "; + + let profile = Profile::from_str(profile); + assert!(profile.is_ok()); + let profile = profile.unwrap(); + + onkostar_editor.apply_profile(&profile); + + match &onkostar_editor.editor.data_form[0].menu_category { + Some(menu_category) => assert_eq!(menu_category.name, "Testformulare"), + _ => panic!("Test failed: MenuCategory not found!") + } + } + + #[test] + fn should_keep_menu_category() { + let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc")); + + assert!(onkostar_editor.is_ok()); + let mut onkostar_editor = onkostar_editor.unwrap(); + + let profile = "forms: + - name: 'Hauptformular' + "; + + let profile = Profile::from_str(profile); + assert!(profile.is_ok()); + let profile = profile.unwrap(); + + onkostar_editor.apply_profile(&profile); + + match &onkostar_editor.editor.data_form[0].menu_category { + Some(menu_category) => assert_eq!(menu_category.name, "Test"), + _ => panic!("Test failed: MenuCategory not found!") + } + } } diff --git a/src/model/unterformular.rs b/src/model/unterformular.rs index bb095d1..fc4a721 100644 --- a/src/model/unterformular.rs +++ b/src/model/unterformular.rs @@ -744,4 +744,24 @@ mod tests { assert_eq!(onkostar_editor.editor.unterformular[0].entries.entry[1].name, "Termin"); assert_eq!(onkostar_editor.editor.unterformular[0].entries.entry[1].default_value, "") } + + #[test] + fn should_ignore_menu_category_for_subform() { + let onkostar_editor = OnkostarEditor::from_str(include_str!("../../tests/test.osc")); + + assert!(onkostar_editor.is_ok()); + let mut onkostar_editor = onkostar_editor.unwrap(); + + let profile = "forms: + - name: 'Unterformular' + "; + + let profile = Profile::from_str(profile); + assert!(profile.is_ok()); + let profile = profile.unwrap(); + + onkostar_editor.apply_profile(&profile); + + assert!(&onkostar_editor.editor.unterformular[0].menu_category.is_none()); + } } \ No newline at end of file