mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
test: add an option test (#3006)
This commit is contained in:
parent
c65584d23c
commit
26f078128a
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -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(
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user