test: split test into widget and unit test (#1432)

This commit is contained in:
Richard Shiue
2022-11-11 12:42:20 +08:00
committed by GitHub
parent f426745094
commit 5b4a93ee34
3 changed files with 81 additions and 47 deletions

View File

@ -136,31 +136,12 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
return;
}
final trimmedText = text.trimLeft();
List<String> splits = [];
String currentString = '';
final result = splitInput(text.trimLeft(), widget.textSeparators);
// split the string into tokens
for (final char in trimmedText.split('')) {
if (widget.textSeparators.contains(char)) {
if (currentString.isNotEmpty) {
splits.add(currentString.trim());
}
currentString = '';
continue;
}
currentString += char;
}
// add the remainder (might be '')
splits.add(currentString);
final submittedOptions = splits.sublist(0, splits.length - 1).toList();
final remainder = splits.elementAt(splits.length - 1).trimLeft();
editingController.text = remainder;
editingController.text = result[1];
editingController.selection =
TextSelection.collapsed(offset: controller.text.length);
widget.onPaste(submittedOptions, remainder);
widget.onPaste(result[0], result[1]);
}
Widget? _renderTags(BuildContext context, ScrollController sc) {
@ -193,3 +174,28 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
);
}
}
@visibleForTesting
List splitInput(String input, List<String> textSeparators) {
List<String> splits = [];
String currentString = '';
// split the string into tokens
for (final char in input.split('')) {
if (textSeparators.contains(char)) {
if (currentString.trim().isNotEmpty) {
splits.add(currentString.trim());
}
currentString = '';
continue;
}
currentString += char;
}
// add the remainder (might be '')
splits.add(currentString);
final submittedOptions = splits.sublist(0, splits.length - 1).toList();
final remainder = splits.elementAt(splits.length - 1).trimLeft();
return [submittedOptions, remainder];
}