2022-08-23 13:25:05 +08:00
|
|
|
import 'package:appflowy_editor/src/render/toolbar/toolbar_item.dart';
|
|
|
|
|
import 'package:appflowy_editor/src/render/toolbar/toolbar_item_widget.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
|
|
|
|
|
void main() async {
|
|
|
|
|
setUpAll(() {
|
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
group('toolbar_item_widget.dart', () {
|
|
|
|
|
testWidgets('test single toolbar item widget', (tester) async {
|
|
|
|
|
final key = GlobalKey();
|
2022-08-30 14:28:17 +08:00
|
|
|
final iconKey = GlobalKey();
|
2022-08-23 13:25:05 +08:00
|
|
|
var hit = false;
|
|
|
|
|
final item = ToolbarItem(
|
|
|
|
|
id: 'appflowy.toolbar.test',
|
2023-05-16 18:57:53 +08:00
|
|
|
group: 0,
|
2022-08-30 14:28:17 +08:00
|
|
|
iconBuilder: (isHighlight) {
|
|
|
|
|
return Icon(
|
|
|
|
|
key: iconKey,
|
|
|
|
|
Icons.abc,
|
|
|
|
|
color: isHighlight ? Colors.lightBlue : null,
|
|
|
|
|
);
|
|
|
|
|
},
|
2022-08-23 13:25:05 +08:00
|
|
|
validator: (editorState) => true,
|
|
|
|
|
handler: (editorState, context) {},
|
2022-08-30 14:28:17 +08:00
|
|
|
highlightCallback: (editorState) {
|
|
|
|
|
return true;
|
|
|
|
|
},
|
2022-08-23 13:25:05 +08:00
|
|
|
);
|
|
|
|
|
final widget = ToolbarItemWidget(
|
|
|
|
|
key: key,
|
|
|
|
|
item: item,
|
2022-08-30 14:28:17 +08:00
|
|
|
isHighlight: true,
|
2026-07-27 15:37:27 +08:00
|
|
|
onPressed: () {
|
2022-08-23 13:25:05 +08:00
|
|
|
hit = true;
|
2026-07-27 15:37:27 +08:00
|
|
|
},
|
2022-08-23 13:25:05 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await tester.pumpWidget(
|
|
|
|
|
MaterialApp(
|
|
|
|
|
home: Material(
|
|
|
|
|
child: widget,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(find.byKey(key), findsOneWidget);
|
2022-08-30 14:28:17 +08:00
|
|
|
expect(find.byKey(iconKey), findsOneWidget);
|
|
|
|
|
expect(
|
|
|
|
|
(tester.firstWidget(find.byKey(iconKey)) as Icon).color,
|
|
|
|
|
Colors.lightBlue,
|
|
|
|
|
);
|
2022-08-23 13:25:05 +08:00
|
|
|
|
|
|
|
|
await tester.tap(find.byKey(key));
|
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
|
|
expect(hit, true);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|