Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
112 lines
4.0 KiB
Dart
112 lines
4.0 KiB
Dart
import 'package:cutdex/shared/widgets/workspace_resize_handle.dart';
|
|
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
for (final axis in Axis.values) {
|
|
for (final finish in ['release', 'cancel', 'unmount']) {
|
|
testWidgets('$axis resize cursor stays locked until $finish', (
|
|
tester,
|
|
) async {
|
|
var showHandle = true;
|
|
var taps = 0;
|
|
var ends = 0;
|
|
var starts = 0;
|
|
var updates = 0;
|
|
late StateSetter update;
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
home: Scaffold(
|
|
body: StatefulBuilder(
|
|
builder: (context, setState) {
|
|
update = setState;
|
|
return Stack(
|
|
children: [
|
|
Positioned(
|
|
left: 400,
|
|
top: 400,
|
|
width: 100,
|
|
height: 60,
|
|
child: MouseRegion(
|
|
cursor: SystemMouseCursors.click,
|
|
child: GestureDetector(
|
|
key: const Key('button'),
|
|
onTap: () => taps++,
|
|
child: const ColoredBox(color: Colors.blue),
|
|
),
|
|
),
|
|
),
|
|
if (showHandle)
|
|
Positioned(
|
|
left: 100,
|
|
top: 100,
|
|
width: axis == Axis.horizontal ? 5 : 200,
|
|
height: axis == Axis.horizontal ? 200 : 5,
|
|
child: WorkspaceResizeHandle(
|
|
key: const Key('handle'),
|
|
axis: axis,
|
|
initialValue: 100,
|
|
onStart: () => starts++,
|
|
onResize: (_) {
|
|
expect(starts, 1);
|
|
updates++;
|
|
},
|
|
onEnd: () => ends++,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
);
|
|
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
|
final start = tester.getCenter(find.byKey(const Key('handle')));
|
|
final button = tester.getCenter(find.byKey(const Key('button')));
|
|
await mouse.addPointer(location: start);
|
|
await mouse.down(start);
|
|
await mouse.moveBy(
|
|
axis == Axis.horizontal ? const Offset(30, 0) : const Offset(0, 30),
|
|
);
|
|
await tester.pump();
|
|
await mouse.moveTo(button);
|
|
await tester.pump();
|
|
expect(updates, greaterThan(0));
|
|
expect(starts, 1);
|
|
expect(
|
|
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
|
axis == Axis.horizontal
|
|
? SystemMouseCursors.resizeColumn
|
|
: SystemMouseCursors.resizeRow,
|
|
);
|
|
// A second pointer still reaches the control through the cursor overlay.
|
|
await tester.tap(find.byKey(const Key('button')));
|
|
expect(taps, 1);
|
|
|
|
if (finish == 'unmount') {
|
|
update(() => showHandle = false);
|
|
await tester.pumpAndSettle();
|
|
await mouse.up();
|
|
} else if (finish == 'cancel') {
|
|
await mouse.cancel();
|
|
} else {
|
|
await mouse.up();
|
|
}
|
|
await tester.pumpAndSettle();
|
|
await mouse.moveTo(button + const Offset(1, 0));
|
|
await tester.pump();
|
|
expect(
|
|
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
|
SystemMouseCursors.click,
|
|
);
|
|
expect(ends, finish == 'unmount' ? 0 : 1);
|
|
await mouse.removePointer();
|
|
expect(tester.takeException(), isNull);
|
|
});
|
|
}
|
|
}
|
|
}
|