feat: alter some select option editor bloc events and add tests (#1264)

* chore: separate select and unselect events

* style: improve readability

* chore: don't send empty payloads if we can help it

* test: add select option text field test

* test: complete bloc test for select option

* test: delete all options between each test

* fix: keep insert order

* test: combine select and unselect tests

* chore: remove duplicate wait

Co-authored-by: appflowy <annie@appflowy.io>
This commit is contained in:
Richard Shiue
2022-10-22 19:55:18 +08:00
committed by GitHub
parent bf1d4b923a
commit 80f034beee
6 changed files with 324 additions and 43 deletions

View File

@ -261,9 +261,15 @@ class _SelectOptionCellState extends State<_SelectOptionCell> {
child: SelectOptionTagCell(
option: widget.option,
onSelected: (option) {
context
.read<SelectOptionCellEditorBloc>()
.add(SelectOptionEditorEvent.selectOption(option.id));
if (widget.isSelected) {
context
.read<SelectOptionCellEditorBloc>()
.add(SelectOptionEditorEvent.unSelectOption(option.id));
} else {
context
.read<SelectOptionCellEditorBloc>()
.add(SelectOptionEditorEvent.selectOption(option.id));
}
},
children: [
if (widget.isSelected)

View File

@ -96,7 +96,7 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
}
if (text.isNotEmpty) {
widget.onSubmitted(text);
widget.onSubmitted(text.trim());
focusNode.requestFocus();
}
},
@ -132,26 +132,25 @@ class _SelectOptionTextFieldState extends State<SelectOptionTextField> {
return;
}
final trimmedText = text.trim();
final trimmedText = text.trimLeft();
List<String> splits = [];
String currentString = '';
// split the string into tokens
for (final char in trimmedText.split('')) {
if (!widget.textSeparators.contains(char)) {
currentString += char;
if (widget.textSeparators.contains(char)) {
if (currentString.isNotEmpty) {
splits.add(currentString.trim());
}
currentString = '';
continue;
}
if (currentString.isNotEmpty) {
splits.add(currentString);
}
currentString = '';
currentString += char;
}
// add the remainder (might be '')
splits.add(currentString);
final submittedOptions =
splits.sublist(0, splits.length - 1).map((e) => e.trim()).toList();
final submittedOptions = splits.sublist(0, splits.length - 1).toList();
final remainder = splits.elementAt(splits.length - 1).trimLeft();
editingController.text = remainder;