forked from lichess-org/mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathover_the_board_screen_test.dart
More file actions
671 lines (556 loc) · 23.6 KB
/
over_the_board_screen_test.dart
File metadata and controls
671 lines (556 loc) · 23.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
import 'dart:io';
import 'package:chessground/chessground.dart';
import 'package:dartchess/dartchess.dart';
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lichess_mobile/src/model/common/chess.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:lichess_mobile/src/model/common/perf.dart';
import 'package:lichess_mobile/src/model/common/speed.dart';
import 'package:lichess_mobile/src/model/common/time_increment.dart';
import 'package:lichess_mobile/src/model/game/game.dart';
import 'package:lichess_mobile/src/model/game/game_status.dart';
import 'package:lichess_mobile/src/model/game/over_the_board_game.dart';
import 'package:lichess_mobile/src/model/over_the_board/over_the_board_clock.dart';
import 'package:lichess_mobile/src/model/over_the_board/over_the_board_game_controller.dart';
import 'package:lichess_mobile/src/model/over_the_board/over_the_board_game_storage.dart';
import 'package:lichess_mobile/src/utils/navigation.dart';
import 'package:lichess_mobile/src/view/over_the_board/over_the_board_screen.dart';
import 'package:lichess_mobile/src/widgets/clock.dart';
import 'package:mocktail/mocktail.dart';
import '../../test_helpers.dart';
import '../../test_provider_scope.dart';
// A position after 1.e4 e5 — white to move
const _customFen = 'rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2';
class MockOverTheBoardGameStorage extends Mock implements OverTheBoardGameStorage {}
void main() {
registerFallbackValue(
OverTheBoardGame(
id: const StringId('otb_test00'),
steps: [const GameStep(position: Chess.initial)].lock,
meta: GameMeta(
createdAt: DateTime.now(),
rated: false,
variant: Variant.standard,
speed: Speed.rapid,
perf: Perf.rapid,
),
initialFen: null,
status: GameStatus.unknown,
),
);
registerFallbackValue(const TimeIncrement(0, 0));
group('Playing over the board (offline)', () {
testWidgets('Checkmate and Rematch', (tester) async {
final boardRect = await initOverTheBoardGame(tester, const TimeIncrement(60, 5));
// Default orientation is white at the bottom
expect(
tester.getBottomLeft(find.byKey(const ValueKey('a1-whiterook'))),
boardRect.bottomLeft,
);
await playMove(tester, 'e2', 'e4');
await playMove(tester, 'f7', 'f6');
await playMove(tester, 'd2', 'd4');
await playMove(tester, 'g7', 'g5');
await playMove(tester, 'd1', 'h5');
await tester.pumpAndSettle(const Duration(milliseconds: 600));
expect(find.text('Checkmate • White is victorious'), findsOneWidget);
await tester.tap(find.text('Rematch'));
await tester.pumpAndSettle();
final container = ProviderScope.containerOf(tester.element(find.byType(Chessboard)));
final gameState = container.read(overTheBoardGameControllerProvider);
expect(gameState.game.steps.length, 1);
expect(gameState.game.steps.first.position, Chess.initial);
// Rematch should flip orientation
expect(tester.getTopRight(find.byKey(const ValueKey('a1-whiterook'))), boardRect.topRight);
expect(activeClock(tester), null);
});
testWidgets('Game ends when out of time', (tester) async {
const time = Duration(seconds: 1);
await initOverTheBoardGame(tester, TimeIncrement(time.inSeconds, 0));
await playMove(tester, 'e2', 'e4');
await playMove(tester, 'e7', 'e5');
// The clock measures system time internally, so we need to actually sleep in order
// for the clock to reach 0, instead of using tester.pump()
sleep(time + const Duration(milliseconds: 100));
// Now for game result dialog to show up
await tester.pumpAndSettle(const Duration(milliseconds: 600));
expect(find.text('White time out • Black is victorious'), findsOneWidget);
await tester.tap(find.text('Rematch'));
expect(activeClock(tester), null);
});
testWidgets('Pausing the clock', (tester) async {
const time = Duration(seconds: 10);
await initOverTheBoardGame(tester, TimeIncrement(time.inSeconds, 0));
await playMove(tester, 'e2', 'e4');
await playMove(tester, 'e7', 'e5');
await tester.tap(find.byTooltip('Pause'));
await tester.pump();
expect(activeClock(tester), null);
await tester.tap(find.byTooltip('Resume'));
await tester.pump();
expect(activeClock(tester), Side.white);
// Going back a move should not unpause...
await tester.tap(find.byTooltip('Pause'));
await tester.pump();
await tester.tap(find.byTooltip('Previous'));
await tester.pump();
expect(activeClock(tester), null);
// ... but playing a move resumes the clock
await playMove(tester, 'd7', 'd5');
expect(activeClock(tester), Side.white);
});
testWidgets('Go back and Forward', (tester) async {
const time = Duration(seconds: 10);
await initOverTheBoardGame(tester, TimeIncrement(time.inSeconds, 0));
await playMove(tester, 'e2', 'e4');
await playMove(tester, 'e7', 'e5');
await tester.tap(find.byTooltip('Previous'));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('e7-blackpawn')), findsOneWidget);
expect(activeClock(tester), Side.black);
await tester.tap(find.byTooltip('Next'));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('e5-blackpawn')), findsOneWidget);
expect(activeClock(tester), Side.white);
// Go back all the way to the initial position
await tester.tap(find.byTooltip('Previous'));
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Previous'));
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Previous'));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('e2-whitepawn')), findsOneWidget);
expect(find.byKey(const ValueKey('e7-blackpawn')), findsOneWidget);
expect(activeClock(tester), Side.white);
await playMove(tester, 'e2', 'e4');
expect(find.byKey(const ValueKey('e4-whitepawn')), findsOneWidget);
expect(activeClock(tester), Side.black);
});
testWidgets('No clock if time is infinite', (tester) async {
await initOverTheBoardGame(tester, const TimeIncrement(0, 0));
expect(find.byType(Clock), findsNothing);
});
testWidgets('Clock logic', (tester) async {
const time = Duration(minutes: 5);
await initOverTheBoardGame(tester, TimeIncrement(time.inSeconds, 3));
expect(activeClock(tester), null);
expect(findWhiteClock(tester).timeLeft, time);
expect(findBlackClock(tester).timeLeft, time);
await playMove(tester, 'e2', 'e4');
const moveTime = Duration(milliseconds: 500);
await tester.pumpAndSettle(moveTime);
expect(activeClock(tester), Side.black);
expect(findWhiteClock(tester).timeLeft, time);
expect(findBlackClock(tester).timeLeft, lessThan(time));
await playMove(tester, 'e7', 'e5');
await tester.pumpAndSettle();
expect(activeClock(tester), Side.white);
// Expect increment to be added
expect(findBlackClock(tester).timeLeft, greaterThan(time));
expect(findWhiteClock(tester).timeLeft, lessThan(time));
});
testWidgets('Loading saved game', (tester) async {
final gameStorage = MockOverTheBoardGameStorage();
when(() => gameStorage.fetchOngoingGame()).thenAnswer(
(_) async => SavedOtbGame(
game: OverTheBoardGame(
id: const StringId('otb_test01'),
steps: [
const GameStep(position: Chess.initial),
GameStep(
position: Position.setupPosition(
Rule.chess,
Setup.parseFen('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1'),
),
sanMove: SanMove('e4', Move.parse('e2e4')!),
),
GameStep(
position: Position.setupPosition(
Rule.chess,
Setup.parseFen('rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2'),
),
sanMove: SanMove('e5', Move.parse('e7e5')!),
),
].lock,
meta: GameMeta(
createdAt: DateTime.now(),
rated: false,
variant: Variant.standard,
speed: Speed.rapid,
perf: Perf.rapid,
),
initialFen: null,
status: GameStatus.started,
),
whiteTimeLeft: const Duration(minutes: 2),
blackTimeLeft: const Duration(minutes: 1),
timeIncrement: const TimeIncrement(5, 3),
),
);
when(
() => gameStorage.save(
any(),
timeIncrement: any(named: 'timeIncrement'),
whiteTimeLeft: any(named: 'whiteTimeLeft'),
blackTimeLeft: any(named: 'blackTimeLeft'),
),
).thenAnswer((_) async {});
final app = await makeTestProviderScopeApp(
tester,
home: Builder(
builder: (context) => Scaffold(
appBar: AppBar(title: const Text('Test OTB Screen')),
body: FilledButton(
child: const Text('OTB'),
onPressed: () => Navigator.of(
context,
).push(buildScreenRoute<void>(context, screen: const OverTheBoardScreen())),
),
),
),
overrides: {
overTheBoardGameStorageProvider: overTheBoardGameStorageProvider.overrideWith(
(_) => gameStorage,
),
},
);
await tester.pumpWidget(app);
await tester.tap(find.text('OTB'));
// Wait for previous game to be loaded
await tester.pumpAndSettle();
verify(() => gameStorage.fetchOngoingGame()).called(1);
// Should not show bottom sheet if we loaded a previous game
expect(find.text('Play'), findsNothing);
// Should load the game's current position, i.e. e4 and e5 were played
expect(find.byKey(const ValueKey('e2-whitepawn')), findsNothing);
expect(find.byKey(const ValueKey('e4-whitepawn')), findsOneWidget);
expect(find.byKey(const ValueKey('e7-blackpawn')), findsNothing);
expect(find.byKey(const ValueKey('e5-blackpawn')), findsOneWidget);
expect(activeClock(tester), null);
expect(findWhiteClock(tester).timeLeft, const Duration(minutes: 2));
expect(findBlackClock(tester).timeLeft, const Duration(minutes: 1));
// Start white's clock
await tester.tap(find.byTooltip('Resume'));
await tester.pump();
expect(activeClock(tester), Side.white);
// Close OTB screen and confirm dialog to trigger save
await tester.pageBack();
await tester.pumpAndSettle();
await tester.tap(find.text('Yes'));
verify(
() => gameStorage.save(
any(),
timeIncrement: const TimeIncrement(5, 3),
whiteTimeLeft: const Duration(minutes: 2),
blackTimeLeft: const Duration(minutes: 1),
),
).called(1);
});
});
group('Custom starting position (initialFen)', () {
testWidgets('Configure sheet shows mini board preview when initialFen is provided', (
tester,
) async {
final gameStorage = MockOverTheBoardGameStorage();
when(() => gameStorage.fetchOngoingGame()).thenAnswer((_) async => null);
final app = await makeTestProviderScopeApp(
tester,
home: const OverTheBoardScreen(initialFen: _customFen),
overrides: {
overTheBoardGameStorageProvider: overTheBoardGameStorageProvider.overrideWith(
(_) => gameStorage,
),
},
);
await tester.pumpWidget(app);
await tester.pumpAndSettle();
expect(find.byType(StaticChessboard), findsOneWidget);
});
testWidgets('Configure sheet does not show mini board without initialFen', (tester) async {
final gameStorage = MockOverTheBoardGameStorage();
when(() => gameStorage.fetchOngoingGame()).thenAnswer((_) async => null);
final app = await makeTestProviderScopeApp(
tester,
home: const OverTheBoardScreen(),
overrides: {
overTheBoardGameStorageProvider: overTheBoardGameStorageProvider.overrideWith(
(_) => gameStorage,
),
},
);
await tester.pumpWidget(app);
await tester.pumpAndSettle();
expect(find.byType(StaticChessboard), findsNothing);
});
testWidgets('initialFen bypasses saved game and shows configure sheet immediately', (
tester,
) async {
final gameStorage = MockOverTheBoardGameStorage();
// A saved game exists, but it should be ignored when initialFen is provided
when(() => gameStorage.fetchOngoingGame()).thenAnswer(
(_) async => SavedOtbGame(
game: OverTheBoardGame(
id: const StringId('otb_saved'),
steps: [
const GameStep(position: Chess.initial),
GameStep(
position: Position.setupPosition(
Rule.chess,
Setup.parseFen('rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1'),
),
sanMove: SanMove('e4', Move.parse('e2e4')!),
),
].lock,
meta: GameMeta(
createdAt: DateTime.now(),
rated: false,
variant: Variant.standard,
speed: Speed.rapid,
perf: Perf.rapid,
),
initialFen: null,
status: GameStatus.started,
),
whiteTimeLeft: const Duration(minutes: 5),
blackTimeLeft: const Duration(minutes: 5),
timeIncrement: const TimeIncrement(5, 0),
),
);
final app = await makeTestProviderScopeApp(
tester,
home: const OverTheBoardScreen(initialFen: _customFen),
overrides: {
overTheBoardGameStorageProvider: overTheBoardGameStorageProvider.overrideWith(
(_) => gameStorage,
),
},
);
await tester.pumpWidget(app);
await tester.pumpAndSettle();
// Configure sheet must be shown (not the saved game)
expect(find.text('Play'), findsOneWidget);
// Mini board preview must be visible
expect(find.byType(StaticChessboard), findsOneWidget);
// fetchOngoingGame must NOT have been called
verifyNever(() => gameStorage.fetchOngoingGame());
});
testWidgets(
'Game uses Variant.fromPosition and custom initial position when variant is standard',
(tester) async {
final gameStorage = MockOverTheBoardGameStorage();
when(() => gameStorage.fetchOngoingGame()).thenAnswer((_) async => null);
late WidgetRef ref;
final app = await makeTestProviderScopeApp(
tester,
home: Consumer(
builder: (context, r, _) {
ref = r;
return const OverTheBoardScreen(initialFen: _customFen);
},
),
overrides: {
overTheBoardGameStorageProvider: overTheBoardGameStorageProvider.overrideWith(
(_) => gameStorage,
),
},
);
await tester.pumpWidget(app);
await tester.pumpAndSettle();
// Variant defaults to Standard, tap Play
await tester.tap(find.text('Play'));
await tester.pumpAndSettle();
final gameState = ref.read(overTheBoardGameControllerProvider);
expect(gameState.game.meta.variant, Variant.fromPosition);
expect(gameState.game.initialFen, _customFen);
// Board should show the custom position (e4 pawn on e4, black pawn on e5)
expect(find.byKey(const ValueKey('e2-whitepawn')), findsNothing);
expect(find.byKey(const ValueKey('e4-whitepawn')), findsOneWidget);
expect(find.byKey(const ValueKey('e7-blackpawn')), findsNothing);
expect(find.byKey(const ValueKey('e5-blackpawn')), findsOneWidget);
},
);
testWidgets('Game preserves non-standard variant when initialFen is provided', (tester) async {
final gameStorage = MockOverTheBoardGameStorage();
when(() => gameStorage.fetchOngoingGame()).thenAnswer((_) async => null);
late WidgetRef ref;
final app = await makeTestProviderScopeApp(
tester,
home: Consumer(
builder: (context, r, _) {
ref = r;
return const OverTheBoardScreen(initialFen: _customFen);
},
),
overrides: {
overTheBoardGameStorageProvider: overTheBoardGameStorageProvider.overrideWith(
(_) => gameStorage,
),
},
);
await tester.pumpWidget(app);
await tester.pumpAndSettle();
// Change variant to Chess960
await tester.tap(find.textContaining('Standard'));
await tester.pumpAndSettle();
await tester.tap(find.textContaining('Atomic'));
await tester.pumpAndSettle();
await tester.tap(find.text('Play'));
await tester.pumpAndSettle();
final gameState = ref.read(overTheBoardGameControllerProvider);
// Atomic is not standard, so the variant should be preserved as-is
expect(gameState.game.meta.variant, Variant.atomic);
expect(gameState.game.lastPosition.rule, Rule.atomic);
expect(gameState.game.initialFen, _customFen);
});
testWidgets('Starting a new standard game after a fromPosition game does not crash', (
tester,
) async {
// Regression test: after playing a game from a custom FEN (which stores
// Variant.fromPosition in the game metadata), opening the configure sheet
// for a normal new game and pressing Play used to throw:
// "Invalid argument(s): This variant has no defined initial position!"
final gameStorage = MockOverTheBoardGameStorage();
when(() => gameStorage.fetchOngoingGame()).thenAnswer((_) async => null);
late WidgetRef ref;
final app = await makeTestProviderScopeApp(
tester,
home: Consumer(
builder: (context, r, _) {
ref = r;
return const OverTheBoardScreen(initialFen: _customFen);
},
),
overrides: {
overTheBoardGameStorageProvider: overTheBoardGameStorageProvider.overrideWith(
(_) => gameStorage,
),
},
);
await tester.pumpWidget(app);
await tester.pumpAndSettle();
// Start a game from the custom FEN — variant is stored as Variant.fromPosition
await tester.tap(find.text('Play'));
await tester.pumpAndSettle();
expect(ref.read(overTheBoardGameControllerProvider).game.meta.variant, Variant.fromPosition);
// Now open the configure sheet again without an initialFen (normal new game).
// The sheet must not crash and must default to Variant.standard.
await tester.tap(find.byTooltip('Menu'));
await tester.pumpAndSettle();
await tester.tap(find.text('New game'));
await tester.pumpAndSettle();
// Pressing Play must not throw even though the previous game used Variant.fromPosition
await tester.tap(find.text('Play'));
await tester.pumpAndSettle();
final gameState = ref.read(overTheBoardGameControllerProvider);
expect(gameState.game.meta.variant, Variant.standard);
expect(gameState.game.initialFen, isNull);
expect(gameState.game.steps.length, 1);
expect(gameState.game.steps.first.position, Chess.initial);
});
testWidgets('Rematch from custom position and variant restarts from same FEN and variant', (
tester,
) async {
final gameStorage = MockOverTheBoardGameStorage();
when(() => gameStorage.fetchOngoingGame()).thenAnswer((_) async => null);
when(
() => gameStorage.save(
any(),
timeIncrement: any(named: 'timeIncrement'),
whiteTimeLeft: any(named: 'whiteTimeLeft'),
blackTimeLeft: any(named: 'blackTimeLeft'),
),
).thenAnswer((_) async {});
final app = await makeTestProviderScopeApp(
tester,
home: const OverTheBoardScreen(initialVariant: Variant.atomic, initialFen: _customFen),
overrides: {
overTheBoardGameStorageProvider: overTheBoardGameStorageProvider.overrideWith(
(_) => gameStorage,
),
},
);
await tester.pumpWidget(app);
await tester.pumpAndSettle();
await tester.tap(find.text('Play'));
await tester.pumpAndSettle();
// Play a quick fool's mate from the custom position (white to move after 1.e4 e5)
await playMove(tester, 'd1', 'h5'); // Qh5
await playMove(tester, 'b8', 'c6'); // Nc6
await playMove(tester, 'f1', 'c4'); // Bc4
await playMove(tester, 'g8', 'f6'); // Nf6 (blunder)
await playMove(tester, 'h5', 'f7'); // Qxf7#
await tester.pumpAndSettle(const Duration(milliseconds: 600));
expect(find.textContaining('White is victorious'), findsOneWidget);
await tester.tap(find.text('Rematch'));
await tester.pumpAndSettle();
final container = ProviderScope.containerOf(tester.element(find.byType(Chessboard)));
final gameState = container.read(overTheBoardGameControllerProvider);
// Rematch should restart from the same custom FEN
expect(gameState.game.initialFen, _customFen);
expect(gameState.game.meta.variant, Variant.atomic);
expect(gameState.game.steps.length, 1);
expect(find.byKey(const ValueKey('e4-whitepawn')), findsOneWidget);
expect(find.byKey(const ValueKey('e5-blackpawn')), findsOneWidget);
});
});
}
Future<Rect> initOverTheBoardGame(WidgetTester tester, TimeIncrement timeIncrement) async {
final gameStorage = MockOverTheBoardGameStorage();
when(() => gameStorage.fetchOngoingGame()).thenAnswer((_) async => null);
when(
() => gameStorage.save(
any(),
timeIncrement: any(named: 'timeIncrement'),
whiteTimeLeft: any(named: 'whiteTimeLeft'),
blackTimeLeft: any(named: 'blackTimeLeft'),
),
).thenAnswer((_) async {});
final app = await makeTestProviderScopeApp(
tester,
home: const OverTheBoardScreen(),
overrides: {
overTheBoardGameStorageProvider: overTheBoardGameStorageProvider.overrideWith(
(_) => gameStorage,
),
},
);
await tester.pumpWidget(app);
// Wait for bottom sheet to show up
await tester.pumpAndSettle();
// User taps Play to start game now
await tester.tap(find.text('Play'));
// Wait for bottom sheet to disappear
await tester.pumpAndSettle();
await tester.tap(find.byIcon(CupertinoIcons.play));
final container = ProviderScope.containerOf(tester.element(find.byType(Chessboard)));
container.read(overTheBoardClockProvider.notifier).setupClock(timeIncrement);
await tester.pumpAndSettle();
return tester.getRect(find.byType(Chessboard));
}
Side? activeClock(WidgetTester tester, {Side orientation = Side.white}) {
final whiteClock = findWhiteClock(tester, orientation: orientation);
final blackClock = findBlackClock(tester, orientation: orientation);
if (whiteClock.active) {
expect(blackClock.active, false);
return Side.white;
}
if (blackClock.active) {
expect(whiteClock.active, false);
return Side.black;
}
return null;
}
Clock findWhiteClock(WidgetTester tester, {Side orientation = Side.white}) {
return tester.widget<Clock>(
find.byKey(ValueKey(orientation == Side.white ? 'bottomClock' : 'topClock')),
);
}
Clock findBlackClock(WidgetTester tester, {Side orientation = Side.white}) {
return tester.widget<Clock>(
find.byKey(ValueKey(orientation == Side.white ? 'topClock' : 'bottomClock')),
);
}