Files
BadNote/test/pen_tool_widget_test.dart
Akiba So d1b265dc70
Some checks failed
CI / Windows build (push) Has been cancelled
chore: clean analyzer to zero issues
Whole-project `flutter analyze` exited 1 on 17 pre-existing info/warning
lints (no errors) in dev tools and test files. Clean them so analyze is
green:
- editor_repository_test: drop the redundant sqflite_common import; keep
  the used utils import with a transitive-dep ignore.
- pen_* widget tests: `(_, __)` wildcard params -> `(_, _)`.
- search_snippet_test / gen_bench_pdf / gen_dense_strokes: drop needless
  interpolation braces; remove an unused `Size` show and an unused local;
  mark the gen tool as print-allowed.

No runtime behavior changed. flutter analyze: No issues found. Affected
tests: 22/22 pass.
2026-06-23 09:57:04 +08:00

93 lines
3.0 KiB
Dart

// Device-independent guards for two more live-path behaviors: the highlighter
// tool produces a highlighter-kind stroke, and a single finger PANS the shared
// transform when finger-drawing is off (touch → pan, not draw).
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:badnote/editor/canvas/pen_canvas.dart';
import 'package:badnote/editor/canvas/pen_stroke.dart';
void main() {
const pageSize = Size(400, 600);
Widget host({
required void Function(PenStroke) onComplete,
required TransformationController controller,
CanvasTool tool = CanvasTool.pen,
bool allowFinger = false,
}) =>
MaterialApp(
home: Scaffold(
body: Center(
child: SizedBox(
width: pageSize.width,
height: pageSize.height,
child: PenCanvas(
pageWidget: Container(color: const Color(0xFFEEEEEE)),
pageSize: pageSize,
strokes: const <PenStroke>[],
transformationController: controller,
tool: tool,
color: const Color(0xFFFF0000),
strokeWidth: 0.02,
allowFingerDrawing: allowFinger,
onStrokeComplete: onComplete,
onEraseStroke: (_, _) {},
),
),
),
),
);
testWidgets('highlighter tool commits a highlighter-kind stroke',
(tester) async {
final committed = <PenStroke>[];
final controller = TransformationController();
addTearDown(controller.dispose);
await tester.pumpWidget(host(
onComplete: committed.add,
controller: controller,
tool: CanvasTool.highlighter,
));
final center = tester.getCenter(find.byType(PenCanvas));
final g = await tester.startGesture(center, kind: PointerDeviceKind.stylus);
await g.moveBy(const Offset(30, 0));
await g.up();
await tester.pump();
expect(committed, hasLength(1));
expect(committed.single.kind, PenStrokeKind.highlighter);
});
testWidgets('a single finger PANS the transform when finger-drawing is off',
(tester) async {
final committed = <PenStroke>[];
final controller = TransformationController();
addTearDown(controller.dispose);
await tester.pumpWidget(host(
onComplete: committed.add,
controller: controller,
allowFinger: false,
));
final before = controller.value.getTranslation();
final center = tester.getCenter(find.byType(PenCanvas));
final g = await tester.startGesture(center, kind: PointerDeviceKind.touch);
await g.moveBy(const Offset(40, 25));
await g.moveBy(const Offset(20, 15));
await g.up();
await tester.pump();
final after = controller.value.getTranslation();
// It panned (translation changed) and did NOT draw.
expect((after.x - before.x).abs() + (after.y - before.y).abs(),
greaterThan(1.0));
expect(committed, isEmpty);
});
}