appflowy-editor/test/customer/custom_block_icon_test.dart
Lucas f882d958d9
feat: integrate awesome_lints and upgrade to Flutter 3.38 (#1173)
* chore: update Flutter SDK to version 3.38.5

Upgrade Flutter from 3.32.4 to 3.38.5 to meet awesome_lints
requirement for Dart SDK 3.10.0+. Update CI workflow to use
the new Flutter version and add custom_lint verification step.

* chore: integrate awesome_lints with custom lint rules

Add awesome_lints and custom_lint dependencies, configure
analysis_options.yaml to enable newline lint rules: newline_before_case,
newline_before_constructor, newline_before_method, and newline_before_return.

* style: apply newline formatting per awesome_lints rules

Add blank lines before case clauses, return statements, method
declarations, and constructors throughout the codebase to comply
with awesome_lints newline rules.

* fix: replace deprecated translate with leftTranslateByDouble

Update Matrix4.translate() calls to use the new leftTranslateByDouble()
API to resolve deprecation warnings in Flutter SDK 3.38.5.

* chore: improve code readability with blank line formatting
2025-12-23 15:12:57 +08:00

87 lines
2.5 KiB
Dart

import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:network_image_mock/network_image_mock.dart';
void main() async {
/// supports
///
/// - numbered list
/// - bulleted list
/// - todo list
/// - quote
await AppFlowyEditorLocalizations.load(
const Locale.fromSubtags(languageCode: 'en'),
);
testWidgets('custom block icon', (tester) async {
await mockNetworkImagesFor(() async {
const widget = CustomBlockIcon();
await tester.pumpWidget(widget);
await tester.pumpAndSettle();
iconMap.forEach((key, value) {
expect(find.byIcon(value), findsOneWidget);
});
});
});
}
const menu = 'Here\'s a custom menu!';
final iconMap = {
BulletedListBlockKeys.type: Icons.format_list_bulleted,
NumberedListBlockKeys.type: Icons.format_list_numbered,
QuoteBlockKeys.type: Icons.format_quote,
TodoListBlockKeys.type: Icons.check_box_outline_blank,
};
class CustomBlockIcon extends StatelessWidget {
const CustomBlockIcon({super.key});
@override
Widget build(BuildContext context) {
final delta = Delta()..insert('Hello World');
final document = Document.blank()
..insert(
[0],
[
bulletedListNode(delta: delta),
numberedListNode(delta: delta),
todoListNode(delta: delta, checked: false),
quoteNode(delta: delta),
],
);
final customBlockComponentBuilders = {
...standardBlockComponentBuilderMap,
BulletedListBlockKeys.type: BulletedListBlockComponentBuilder(
iconBuilder: (_, __) => Icon(iconMap[BulletedListBlockKeys.type]),
),
NumberedListBlockKeys.type: NumberedListBlockComponentBuilder(
iconBuilder: (_, __, ___) => Icon(iconMap[NumberedListBlockKeys.type]),
),
TodoListBlockKeys.type: TodoListBlockComponentBuilder(
iconBuilder: (_, __, ___) => Icon(iconMap[TodoListBlockKeys.type]),
),
QuoteBlockKeys.type: QuoteBlockComponentBuilder(
iconBuilder: (_, __) => Icon(iconMap[QuoteBlockKeys.type]),
),
};
final editorState = EditorState(document: document);
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: SizedBox(
width: 500,
child: AppFlowyEditor(
editorState: editorState,
blockComponentBuilders: customBlockComponentBuilders,
),
),
),
),
);
}
}