test: highlighter-kind + single-finger-pan widget guards
Some checks failed
CI / Windows build (push) Has been cancelled
Some checks failed
CI / Windows build (push) Has been cancelled
Two more device-independent live-path guards: the highlighter tool commits a PenStrokeKind.highlighter stroke; a single finger PANS the shared transform (translation changes) when finger-drawing is off and does NOT draw — the touch→pan vs stylus→draw split. flutter analyze lib/editor clean; 240/240 tests (+2). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
92
test/pen_tool_widget_test.dart
Normal file
92
test/pen_tool_widget_test.dart
Normal file
@@ -0,0 +1,92 @@
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user