|
17 | 17 | get_string_parameters, |
18 | 18 | generate_path, |
19 | 19 | generate_import_statements, |
| 20 | + get_widgets_file_import_flags, |
20 | 21 | ) |
21 | 22 |
|
22 | 23 |
|
@@ -935,3 +936,251 @@ def test_parse_parameters_multiple_line_breaks(self): |
935 | 936 | assert params["max"] == "7" |
936 | 937 | assert params["overmaxallowed"] is True |
937 | 938 | assert len(params) == 3 # make sure no empty or extra keys are created |
| 939 | + |
| 940 | + |
| 941 | +class TestGetWidgetsFileImportFlags: |
| 942 | + """Tests for get_widgets_file_import_flags function""" |
| 943 | + |
| 944 | + def test_empty_section_rows(self): |
| 945 | + """Test that empty section_rows returns default ImportFlags""" |
| 946 | + section_rows = [] |
| 947 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 948 | + |
| 949 | + # Only validations should be True by default |
| 950 | + assert import_flags.has_validations_import is True |
| 951 | + |
| 952 | + # All other flags should be False |
| 953 | + assert import_flags.has_choices_import is False |
| 954 | + assert import_flags.has_custom_choices_import is False |
| 955 | + assert import_flags.has_conditionals_import is False |
| 956 | + assert import_flags.has_input_range_import is False |
| 957 | + assert import_flags.has_custom_widgets_import is False |
| 958 | + assert import_flags.has_custom_validations_import is False |
| 959 | + assert import_flags.has_custom_conditionals_import is False |
| 960 | + assert import_flags.has_help_popup_import is False |
| 961 | + assert import_flags.has_helper_import is False |
| 962 | + assert import_flags.has_formatter_import is False |
| 963 | + assert import_flags.has_custom_formatter_import is False |
| 964 | + assert import_flags.has_nickname_label is False |
| 965 | + assert import_flags.has_persons_count_label is False |
| 966 | + assert import_flags.has_gendered_suffix_label is False |
| 967 | + |
| 968 | + def test_choices_imports(self): |
| 969 | + """Test that choices columns are correctly detected""" |
| 970 | + # Standard choices |
| 971 | + section_rows = [ |
| 972 | + { |
| 973 | + "choices": "yesNo", |
| 974 | + "inputType": "Radio", |
| 975 | + "validation": "", |
| 976 | + "conditional": "", |
| 977 | + } |
| 978 | + ] |
| 979 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 980 | + assert import_flags.has_choices_import is True |
| 981 | + assert import_flags.has_custom_choices_import is False |
| 982 | + |
| 983 | + # Custom choices |
| 984 | + section_rows = [ |
| 985 | + { |
| 986 | + "choices": "myCustomChoices", |
| 987 | + "inputType": "Radio", |
| 988 | + "validation": "", |
| 989 | + "conditional": "", |
| 990 | + } |
| 991 | + ] |
| 992 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 993 | + assert import_flags.has_choices_import is False |
| 994 | + assert import_flags.has_custom_choices_import is True |
| 995 | + |
| 996 | + # Explicitly custom choices with CustomChoices suffix |
| 997 | + section_rows = [ |
| 998 | + { |
| 999 | + "choices": "myCustomChoices_customChoices", |
| 1000 | + "inputType": "Radio", |
| 1001 | + "validation": "", |
| 1002 | + "conditional": "", |
| 1003 | + } |
| 1004 | + ] |
| 1005 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1006 | + assert import_flags.has_choices_import is False |
| 1007 | + assert import_flags.has_custom_choices_import is True |
| 1008 | + |
| 1009 | + def test_validation_imports(self): |
| 1010 | + """Test that validation columns are correctly detected""" |
| 1011 | + # Default validations |
| 1012 | + section_rows = [ |
| 1013 | + {"inputType": "Radio", "choices": "", "validation": "", "conditional": ""} |
| 1014 | + ] |
| 1015 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1016 | + assert import_flags.has_validations_import is True |
| 1017 | + assert import_flags.has_custom_validations_import is False |
| 1018 | + |
| 1019 | + # Standard validation |
| 1020 | + section_rows = [ |
| 1021 | + { |
| 1022 | + "inputType": "Radio", |
| 1023 | + "choices": "", |
| 1024 | + "validation": "phoneNumberValidation", |
| 1025 | + "conditional": "", |
| 1026 | + } |
| 1027 | + ] |
| 1028 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1029 | + assert import_flags.has_validations_import is True |
| 1030 | + assert import_flags.has_custom_validations_import is False |
| 1031 | + |
| 1032 | + # Explicitly custom validation with CustomValidation suffix |
| 1033 | + section_rows = [ |
| 1034 | + { |
| 1035 | + "inputType": "Radio", |
| 1036 | + "choices": "", |
| 1037 | + "validation": "specialCustomValidation", |
| 1038 | + "conditional": "", |
| 1039 | + } |
| 1040 | + ] |
| 1041 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1042 | + print(import_flags) |
| 1043 | + # has_validation_import is always true because of default validations, should it be? |
| 1044 | + assert import_flags.has_validations_import is True |
| 1045 | + assert import_flags.has_custom_validations_import is True |
| 1046 | + |
| 1047 | + def test_conditional_imports(self): |
| 1048 | + """Test that conditional columns are correctly detected""" |
| 1049 | + # Default conditionals |
| 1050 | + section_rows = [ |
| 1051 | + {"inputType": "Radio", "choices": "", "validation": "", "conditional": ""} |
| 1052 | + ] |
| 1053 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1054 | + assert import_flags.has_conditionals_import is False |
| 1055 | + assert import_flags.has_custom_conditionals_import is False |
| 1056 | + |
| 1057 | + # Standard conditional |
| 1058 | + section_rows = [ |
| 1059 | + { |
| 1060 | + "inputType": "Radio", |
| 1061 | + "choices": "", |
| 1062 | + "validation": "", |
| 1063 | + "conditional": "someConditional", |
| 1064 | + } |
| 1065 | + ] |
| 1066 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1067 | + assert import_flags.has_conditionals_import is True |
| 1068 | + assert import_flags.has_custom_conditionals_import is False |
| 1069 | + |
| 1070 | + # Custom conditional with CustomConditional suffix |
| 1071 | + section_rows = [ |
| 1072 | + { |
| 1073 | + "inputType": "Radio", |
| 1074 | + "choices": "", |
| 1075 | + "validation": "", |
| 1076 | + "conditional": "myCustomConditional", |
| 1077 | + } |
| 1078 | + ] |
| 1079 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1080 | + assert import_flags.has_conditionals_import is False |
| 1081 | + assert import_flags.has_custom_conditionals_import is True |
| 1082 | + |
| 1083 | + def test_input_range_imports(self): |
| 1084 | + """Test that inputRange columns are correctly detected""" |
| 1085 | + section_rows = [ |
| 1086 | + { |
| 1087 | + "inputType": "Radio", |
| 1088 | + "choices": "", |
| 1089 | + "validation": "", |
| 1090 | + "conditional": "", |
| 1091 | + "inputRange": "satisfaction", |
| 1092 | + } |
| 1093 | + ] |
| 1094 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1095 | + assert import_flags.has_input_range_import is True |
| 1096 | + |
| 1097 | + def test_custom_widgets_imports(self): |
| 1098 | + """Test that Custom inputType is correctly detected""" |
| 1099 | + section_rows = [ |
| 1100 | + {"inputType": "Custom", "choices": "", "validation": "", "conditional": ""} |
| 1101 | + ] |
| 1102 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1103 | + assert import_flags.has_custom_widgets_import is True |
| 1104 | + |
| 1105 | + def test_help_popup_imports(self): |
| 1106 | + """Test that help_popup columns are correctly detected""" |
| 1107 | + # Help popup |
| 1108 | + section_rows = [ |
| 1109 | + { |
| 1110 | + "inputType": "Radio", |
| 1111 | + "choices": "", |
| 1112 | + "validation": "", |
| 1113 | + "conditional": "", |
| 1114 | + "help_popup": "someHelpPopup", |
| 1115 | + } |
| 1116 | + ] |
| 1117 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1118 | + assert import_flags.has_help_popup_import is True |
| 1119 | + |
| 1120 | + # Confirm popup |
| 1121 | + section_rows = [ |
| 1122 | + { |
| 1123 | + "inputType": "Radio", |
| 1124 | + "choices": "", |
| 1125 | + "validation": "", |
| 1126 | + "conditional": "", |
| 1127 | + "confirm_popup": "someConfirmPopup", |
| 1128 | + } |
| 1129 | + ] |
| 1130 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1131 | + assert import_flags.has_help_popup_import is True |
| 1132 | + |
| 1133 | + def test_label_context_imports(self): |
| 1134 | + """Test that label context imports are correctly detected""" |
| 1135 | + # Nickname label |
| 1136 | + section_rows = [ |
| 1137 | + { |
| 1138 | + "inputType": "Radio", |
| 1139 | + "choices": "", |
| 1140 | + "validation": "", |
| 1141 | + "conditional": "", |
| 1142 | + "label::en": "Hello {{nickname}}!", |
| 1143 | + } |
| 1144 | + ] |
| 1145 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1146 | + assert import_flags.has_nickname_label is True |
| 1147 | + |
| 1148 | + # Persons count via count in label |
| 1149 | + section_rows = [ |
| 1150 | + { |
| 1151 | + "inputType": "Radio", |
| 1152 | + "choices": "", |
| 1153 | + "validation": "", |
| 1154 | + "conditional": "", |
| 1155 | + "label::en": "There are {{count}} people", |
| 1156 | + } |
| 1157 | + ] |
| 1158 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1159 | + assert import_flags.has_persons_count_label is True |
| 1160 | + |
| 1161 | + # Persons count via label_one |
| 1162 | + section_rows = [ |
| 1163 | + { |
| 1164 | + "inputType": "Radio", |
| 1165 | + "choices": "", |
| 1166 | + "validation": "", |
| 1167 | + "conditional": "", |
| 1168 | + "label::en": "Regular label", |
| 1169 | + "label_one::en": "Single person label", |
| 1170 | + } |
| 1171 | + ] |
| 1172 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1173 | + assert import_flags.has_persons_count_label is True |
| 1174 | + |
| 1175 | + # Gendered suffix |
| 1176 | + section_rows = [ |
| 1177 | + { |
| 1178 | + "inputType": "Radio", |
| 1179 | + "choices": "", |
| 1180 | + "validation": "", |
| 1181 | + "conditional": "", |
| 1182 | + "label::en": "{{genderedSuffix:he/she}} is happy", |
| 1183 | + } |
| 1184 | + ] |
| 1185 | + import_flags = get_widgets_file_import_flags(section_rows) |
| 1186 | + assert import_flags.has_gendered_suffix_label is True |
0 commit comments