import 'dart:ui' show PointerDeviceKind; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:lumen/domain/book.dart'; import 'package:lumen/domain/game.dart'; import 'package:lumen/main.dart'; import 'package:lumen/services/progress.dart'; void main() { testWidgets('rapid mouse clicks tolerate small movement and cycle to X', ( tester, ) async { final book = (await tester.runAsync(Book.load))!; final game = Game(book, Progress.memory())..showStory(2); await tester.pumpWidget(LumenApp(game: game, adsEnabled: false)); await tester.pumpAndSettle(); final cell = List.generate( game.cells.length, (i) => i, ).firstWhere((i) => !game.puzzle!.given[i]); final center = tester.getCenter(find.byKey(ValueKey('cell-$cell'))); final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse); await mouse.addPointer(location: center); await mouse.down(center); await mouse.up(); await tester.pump(const Duration(milliseconds: 30)); expect(game.cells[cell], 1); await mouse.down(center); await mouse.moveTo(center + const Offset(4, 1)); await mouse.up(); await tester.pump(); expect( game.cells[cell], 2, reason: 'Minor mouse drift must not become a swipe', ); await mouse.down(center); await mouse.moveTo(center + const Offset(80, 0)); await mouse.up(); await tester.pump(); expect(game.cells[cell], 2, reason: 'A deliberate grid drag must not mark'); expect(game.storyIndex, 2, reason: 'A grid drag must not turn the page'); await mouse.removePointer(); await tester.pumpWidget(const SizedBox()); }); testWidgets('next-leaf mouse click tolerates small movement', (tester) async { final book = (await tester.runAsync(Book.load))!; final game = Game(book, Progress.memory())..showStory(0); await tester.pumpWidget(LumenApp(game: game, adsEnabled: false)); await tester.pumpAndSettle(); final next = find.text('Next leaf →'); await tester.ensureVisible(next); await tester.pumpAndSettle(); final center = tester.getCenter(next); final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse); await mouse.addPointer(location: center); await mouse.down(center); await mouse.moveTo(center + const Offset(5, 1)); await mouse.up(); await tester.pump(); expect(game.storyIndex, 1); await mouse.down(const Offset(30, 300)); await mouse.moveTo(const Offset(110, 300)); await mouse.up(); await tester.pump(); expect(game.storyIndex, 0, reason: 'A deliberate margin swipe still turns'); await mouse.removePointer(); await tester.pumpWidget(const SizedBox()); }); }