test: add an option test (#3006)

This commit is contained in:
Lucas.Xu 2023-07-15 08:45:44 +07:00 committed by GitHub
parent c65584d23c
commit 26f078128a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 16 deletions

View File

@ -1,5 +1,8 @@
import 'package:appflowy/plugins/database_view/grid/presentation/grid_page.dart';
import 'package:appflowy/plugins/database_view/grid/presentation/widgets/header/type_option/select_option.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/protobuf.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@ -182,5 +185,31 @@ void main() {
await tester.pumpAndSettle();
}
});
testWidgets('add option', (tester) async {
await tester.initializeAppFlowy();
await tester.tapGoButton();
await tester.createNewPageWithName(ViewLayoutPB.Grid);
// Invoke the field editor
await tester.tapGridFieldWithName('Type');
await tester.tapEditPropertyButton();
// tap 'add option' button
await tester.tapAddSelectOptionButton();
const text = 'Hello AppFlowy';
final inputField = find.descendant(
of: find.byType(CreateOptionTextField),
matching: find.byType(TextField),
);
await tester.enterText(inputField, text);
await tester.pumpAndSettle();
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.pumpAndSettle(const Duration(seconds: 1));
// check the result
tester.expectToSeeText(text);
});
});
}

View File

@ -224,21 +224,26 @@ extension CommonOperations on WidgetTester {
await tapButton(markdownButton);
}
Future<void> createNewPageWithName(ViewLayoutPB layout, String name) async {
Future<void> createNewPageWithName(
ViewLayoutPB layout, [
String? name,
]) async {
// create a new page
await tapAddButton();
await tapButtonWithName(layout.menuName);
await pumpAndSettle();
// hover on it and change it's name
await hoverOnPageName(
LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
onHover: () async {
await renamePage(name);
await pumpAndSettle();
},
);
await pumpAndSettle();
if (name != null) {
await hoverOnPageName(
LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
onHover: () async {
await renamePage(name);
await pumpAndSettle();
},
);
await pumpAndSettle();
}
}
Future<void> simulateKeyEvent(

View File

@ -1197,6 +1197,10 @@ extension AppFlowyDatabaseTest on WidgetTester {
Future<void> tapDatabaseRawDataButton() async {
await tapButtonWithName(LocaleKeys.importPanel_database.tr());
}
Future<void> tapAddSelectOptionButton() async {
await tapButtonWithName(LocaleKeys.grid_field_addSelectOption.tr());
}
}
Finder finderForDatabaseLayoutType(DatabaseLayoutPB layout) {

View File

@ -42,7 +42,7 @@ class SelectOptionTypeOptionWidget extends StatelessWidget {
const TypeOptionSeparator(),
const OptionTitle(),
if (state.isEditingOption)
_CreateOptionTextField(popoverMutex: popoverMutex),
CreateOptionTextField(popoverMutex: popoverMutex),
if (state.options.isNotEmpty && state.isEditingOption)
const VSpace(10),
if (state.options.isEmpty && !state.isEditingOption)
@ -266,18 +266,18 @@ class _AddOptionButton extends StatelessWidget {
}
}
class _CreateOptionTextField extends StatefulWidget {
class CreateOptionTextField extends StatefulWidget {
final PopoverMutex? popoverMutex;
const _CreateOptionTextField({
const CreateOptionTextField({
Key? key,
this.popoverMutex,
}) : super(key: key);
@override
State<_CreateOptionTextField> createState() => _CreateOptionTextFieldState();
State<CreateOptionTextField> createState() => _CreateOptionTextFieldState();
}
class _CreateOptionTextFieldState extends State<_CreateOptionTextField> {
class _CreateOptionTextFieldState extends State<CreateOptionTextField> {
late final FocusNode _focusNode;
@override

View File

@ -85,8 +85,8 @@ class FlowyTextFieldState extends State<FlowyTextField> {
void _onSubmitted(String text) {
widget.onSubmitted?.call(text);
if (widget.autoClearWhenDone) {
controller.text = "";
setState(() {});
// using `controller.clear()` instead of `controller.text = ''` which will crash on Windows.
controller.clear();
}
}